背景
在 Oracle 数据库中,有时候需要将表里的记录进行复制或迁移。会用以下几种方法:
- A 表的记录导出为一条条分号隔开的 insert 语句,然后执行插入到 B 表中
- 建立数据库间的 dblink,然后用 insert into B select * from A@dblink where …
- exp A 表,再 imp 到 B 表,exp 时可加查询条件
- 程序实现 select from A …,然后 insert into B …,也要分批提交
- 再就是使用 Sql Loader(sqlldr) 来导入数据,效果比起逐条 insert 来很明显
操作过程
第一步
先运行cmd,然后输入 sqlldr,执行后看是否有输出结果,结果大概如下:
SQL*Loader: Release 12.2.0.1.0 - Production on ...
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
Usage: SQLLDR keyword=value [,keyword=value,...]
Valid Keywords:
userid -- ORACLE username/password
control -- control file name
log -- log file name
bad -- bad file name
data -- data file name
discard -- discard file name
discardmax -- number of discards to allow (Default all)
skip -- number of logical records to skip (Default 0)
load -- number of logical records to load (Default all)
errors -- number of errors to allow (Default 50)
rows -- number of rows in conventional path bind array or between direct path data saves