在oracle中 生成大规模数据 500万条 (使用导入数据方式 sqlldr 导入命令 *.ctl文件)

来源:互联网 发布:文言文翻译器软件 编辑:程序博客网 时间:2024/04/29 23:35

 

在Oracle中导入数据

 

Oracle中导入数据时,使用的文件后缀是*.ctl

 

命令是 sqlldr

 

sqlldr username/password control = 'TBL_EMP,ctl'

 

从postgre中导出部分数据

psql saison -c 'select user_id, user_name from user order by 1,2'  user_list.txt -A -F, -t

 

生成的文件 user_list.txt

100001,xiaoming

100002,xiaowang

 

ctl 文件

load data

infile user_list.txt

APPEND into table TBL_EMP

FILDS TERMINATED BY ","

trailing nullcols

(

  user_unique_key SEQUENCE(MAX),

  user_id,

  user_name,

  user_pin_id ":user_id",

  user_berthday "20120202",

  pay_month 10000,

  user_flag "1"

)

 

 

说明:①

程序有两个DB,其中一个DB是postgre另外一个是oracle

在postgre中生成数据后,导出两个数据库相关联的部分 user_id  user_name

 

postgre 中的数据库表是 user

Oracle  中的数据库表是 TBL_EMP

 

---------------------------

说明:②

关于  SEQUENCE(MAX)  的作用

这里没有使用序列,这里的作用是使这个字段自增

 

比如这个字段是一个char 10

 

那么生成的字段为

1000000000

1000000001

1000000002

。。

。。

。。

 

注意:①

在linux下执行这个命令时

要设置ORACLE_HOME这个环境变量

export ORACLE_HOME=/u01/app/oracle//product/10.2/db_1

 

否则会报错

 

Message 2100 not found; No message file for product=RDBMS, facility=ULMessage 2100 not found; No message file for product=RDBMS, facility=UL

 

注意:②

ORACLE_SID 也需要配置

 

 

注意③

在ctl文件所在目录下执行这个命令