利用sqlldr从MySQL导出一张表数据到Oracle
根据业务需求,需要从MySQL库中同步一张表tap_application到Oracle中,下面是记录的导入过程.
1. 查看MySQL表结构
desc tap_application;
+---------------------+---------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+---------------+------+-----+---------------------+----------------+
| ID | int(11) | NO | PRI | NULL | auto_increment |
| VENDORID | int(11) | NO | | NULL | |
| NAME | varchar(128) | NO | | NULL | |
| DESCRIPTION | varchar(255) | YES | | NULL | |
| CREATIONDATE | datetime | NO | | 0000-00-00 00:00:00 | |
| MODIFICATIONDATE | datetime | NO | | 0000-00-00 00:00:00 | |
| STATUS | int(11) | NO | | NULL | |
| URL | varchar(1024) | YES | | NULL | |
| APPTYPE | smallint(6) | YES | | NULL | |
| TEST_KEY | varchar(512) | YES | | NULL | |
| PRODUCTION_KEY | varchar(512) | YES | | NULL | |
| TEST_APISUSED | varchar(256) | YES | | NULL | |
| PRODUCTION_APISUSED | varchar(256) | YES | | NULL | |
+---------------------+---------------+------+-----+---------------------+----------------+
13 rows in set (0.01 sec)
2. 查看表是否有特殊字符
select * from tap_application where ID=1 or ID=55\G
*************************** 1. row ***************************
ID: 1
VENDORID: 1
NAME: app name
DESCRIPTION: NULL
CREATIONDATE: 2009-03-30 18:40:36
MODIFICATIONDATE: 2009-03-30 18:40:36
STATUS: 1
URL: NULL
APPTYPE: NULL
TEST_KEY: AQAAASBaL2Igf/////////8AAAABAAAAAQEAAAAQnPDr8PHxexN/hwVcTYQL9AEAAAAOAwAAAAEAAAABAAAAAQA=
PRODUCTION_KEY: NULL
TEST_APISUSED: NULL
PRODUCTION_APISUSED: NULL
*************************** 2. row ***************************
ID: 55
VENDORID: 52
NAME: Raj Rao's test 1 application.
DESCRIPTION: <script type='text/javascript'>
alert("I am an alert box!");
</script> CREATIONDATE: 2010-04-09 15:20:53
MODIFICATIONDATE: 2010-06-04 09:09:01
STATUS: 1
URL: http://somewhere.a.b
APPTYPE: 1
TEST_KEY: NULL
PRODUCTION_KEY: NULL
TEST_APISUSED: NULL
PRODUCTION_APISUSED: NULL
#可以看到"TEST_KEY"字段有特殊字符存在,"DESCRIPTION"字段也有换行符等特殊字符存在,因此在导出时需要特别留意,实际上通过cat -v查看数据时可以看到windows换行符"\r\n"
3. 导出MySQL表数据到文本文件中
select count(*) from tap_application;
+----------+
| count(*) |
+----------+
| 847 |
+----------+
1 row in set (0.01 sec) select
IFNULL(ID,''),
IFNULL(VENDORID,''),
IFNULL(NAME,''),
REPLACE(IFNULL(DESCRIPTION,''),'\r\n','/$'),
IFNULL(CREATIONDATE,''),
IFNULL(MODIFICATIONDATE,''),
IFNULL(STATUS,''),
IFNULL(URL,''),
IFNULL(APPTYPE,''),
IFNULL(TEST_KEY,''),
IFNULL(PRODUCTION_KEY,''),
IFNULL(TEST_APISUSED,''),
IFNULL(PRODUCTION_APISUSED,'')
into outfile '/usr/local/mysql/dba/exp/tap_application.txt' fields terminated by '||' optionally enclosed by '^' lines terminated by '\r\n' from tap_application; Query OK, 847 rows affected (0.01 sec) scp /usr/local/mysql/dba/exp/tap_application.txt oracle@10.189.102.118:/u01/app/oracle/dba/imp/
4. 在Oracle数据库创建对应表结构
CREATE TABLE tap_application (
ID INT NOT NULL PRIMARY KEY,
VENDORID INT NOT NULL,
NAME VARCHAR2(128) NOT NULL,
DESCRIPTION VARCHAR2(255),
CREATIONDATE DATE NOT NULL,
MODIFICATIONDATE DATE NOT NULL,
STATUS INT NOT NULL,
URL VARCHAR2(1024),
APPTYPE INT,
TEST_KEY VARCHAR2(512),
PRODUCTION_KEY VARCHAR2(512),
PRODUCTION_APISUSED VARCHAR2(256)
);
5. 创建sqlldr控制文件
$ cat /u01/app/oracle/dba/imp/load_tap_application.ctl
load DATA
INFILE '/u01/app/oracle/dba/imp/tap_application.txt'
BADFILE '/u01/app/oracle/dba/imp/tap_application.bad'
DISCARDFILE '/u01/app/oracle/dba/imp/tap_application.dsc'
TRUNCATE
INTO TABLE TAP_APPLICATION
fields terminated by '||' optionally enclosed by '^'
TRAILING NULLCOLS
(
ID integer external,
VENDORID integer external,
NAME char(128),
DESCRIPTION char(255) "replace(:DESCRIPTION,'/$','\r\n')",
CREATIONDATE date "YYYY-MM-DD HH24:MI:SS",
MODIFICATIONDATE date "YYYY-MM-DD HH24:MI:SS",
STATUS integer external,
URL char(1024),
APPTYPE integer external,
TEST_KEY char(512),
PRODUCTION_KEY char(512),
PRODUCTION_APISUSED char(256)
)
6. 导入数据到Oracle
$ $ORACLE_HOME/bin/sqlldr system/888888 control=/u01/app/oracle/dba/imp/load_tap_application.ctl errors=50000 log=/u01/app/oracle/dba/imp/load_tap_application.log SQL*Loader: Release 11.2.0.4.0 - Production on Fri Jul 7 08:33:39 2017 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Commit point reached - logical record count 60
Commit point reached - logical record count 120
Commit point reached - logical record count 180
Commit point reached - logical record count 240
Commit point reached - logical record count 300
Commit point reached - logical record count 360
Commit point reached - logical record count 420
Commit point reached - logical record count 480
Commit point reached - logical record count 540
Commit point reached - logical record count 600
Commit point reached - logical record count 660
Commit point reached - logical record count 720
Commit point reached - logical record count 780
Commit point reached - logical record count 840
Commit point reached - logical record count 847
7. 查看导入的log信息
$ cat /u01/app/oracle/dba/imp/load_tap_application.log SQL*Loader: Release 11.2.0.4. - Production on Fri Jul :: Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Control File: /u01/app/oracle/dba/imp/load_tap_application.ctl
Data File: /u01/app/oracle/dba/imp/tap_application.txt
Bad File: /u01/app/oracle/dba/imp/tap_application.bad
Discard File: /u01/app/oracle/dba/imp/tap_application.dsc
(Allow all discards) Number to load: ALL
Number to skip:
Errors allowed:
Bind array: rows, maximum of bytes
Continuation: none specified
Path used: Conventional Table TAP_APPLICATION, loaded from every logical record.
Insert option in effect for this table: TRUNCATE
TRAILING NULLCOLS option in effect Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
ID FIRST * O(^) CHARACTER
Terminator string : '||'
VENDORID NEXT * O(^) CHARACTER
Terminator string : '||'
NAME NEXT O(^) CHARACTER
Terminator string : '||'
DESCRIPTION NEXT O(^) CHARACTER
Terminator string : '||'
SQL string for column : "replace(:DESCRIPTION,'/$','
')"
CREATIONDATE NEXT * O(^) DATE YYYY-MM-DD HH24:MI:SS
Terminator string : '||'
MODIFICATIONDATE NEXT * O(^) DATE YYYY-MM-DD HH24:MI:SS
Terminator string : '||'
STATUS NEXT * O(^) CHARACTER
Terminator string : '||'
URL NEXT O(^) CHARACTER
Terminator string : '||'
APPTYPE NEXT * O(^) CHARACTER
Terminator string : '||'
TEST_KEY NEXT O(^) CHARACTER
Terminator string : '||'
PRODUCTION_KEY NEXT O(^) CHARACTER
Terminator string : '||'
PRODUCTION_APISUSED NEXT O(^) CHARACTER
Terminator string : '||' value used for ROWS parameter changed from to Table TAP_APPLICATION:
Rows successfully loaded.
Rows not loaded due to data errors.
Rows not loaded because all WHEN clauses were failed.
Rows not loaded because all fields were null. Space allocated for bind array: bytes( rows)
Read buffer bytes: Total logical records skipped:
Total logical records read:
Total logical records rejected:
Total logical records discarded: Run began on Fri Jul ::
Run ended on Fri Jul :: Elapsed time was: ::00.44
CPU time was: ::00.01
利用sqlldr从MySQL导出一张表数据到Oracle的更多相关文章
- Mysql导出(多张表)表结构及表数据 mysqldump用法
命令行下具体用法如下: mysqldump -u用戶名 -p密码 -d 數據库名 表名 脚本名; 1.导出數據库為dbname的表结构(其中用戶名為root,密码為dbpasswd,生成的脚 ...
- MySQL实现两张表数据的同步
有两张表A和B,要求往A里面插入一条记录的同时要向B里面也插入一条记录,向B里面插入一条记录的同时也向A插入一条记录.两张表的结构不同,需要将其中几个字段对应起来.可以用下面的触发器实现. 表A的触发 ...
- mysql导出某张表的部分数据
.使用into outfile '保存到操作系统的外部文件路径' mysql -uroot -p123456 -hhostname -P3306 select column_name_list fro ...
- mysql导出多个表数据为excel方法,substring函数查询
//查询sys_username以S.00655开头的用户 ),sys_password FROM `tbl_sa_syslogin` where sys_username like 'S.%'; / ...
- mysql查询哪张表数据最大
转载:https://blog.csdn.net/qq13650793239/article/details/81142134 mysql数据库中information_schema 数据库存储了数据 ...
- sqlplus 导出一张表数据
内网只让用sql developer 这软件搓的不行,数据加载到51行就黑了,没法法用sqlplus. 打开cmd, sqlplus user/passwd@ip:port/库名set colsep ...
- 将Mysql的一张表导出至Excel格式文件
将Mysql的一张表导出至Excel格式文件 导出语句 进入mysql数据库,输入如下sql语句: select id, name, age from tablename into outfile ' ...
- MySQL实例多库某张表数据文件损坏导致xxx库无法访问故障恢复
一.问题发现 命令行进入数据库实例手动给某张表进行alter操作,发现如下报错. mysql> use xx_xxx; No connection. Trying to reconnect... ...
- [转]mysql导出导入中文表解决方法
在开发过程中会经常用到mysql导出导入中文表,本文将详细介绍其如何使用,需要的朋友可以参考下. 在开发过程中会经常用到mysql导出导入中文表,本文将详细介绍其如何使用,需要的朋友可以参考下一.先针 ...
随机推荐
- zepto 入门
2017-03-17 文章来源:http://www.cnblogs.com/daysme zepto 简介 jq虽然有一些衍生的插件可用在移动端上,但它有点大. click 有,但有问题 onmou ...
- AmazeUI学习
http://amazeui.org/ 相比于其他国外的框架而言,Amaze UI更关注中文排版,被前端工程师称为最懂中文的前端框架. Amaze UI受欢迎的一个重要的原因是:文档非常完善,适合各阶 ...
- latex 脚注编号也成为超链接
我们用LaTeX写文章时,往往会引用tabularx和hyperref两个包,当我们想让脚注编号也成为超链接以方便阅读时,往往会发现在hyperref包的属性里设置hyperfootnotes=tru ...
- vs项目的属性页面总结
本文主要针对vs中属性页面的相关选项含义进行了总结.
- RN酷炫组件圆形加载
地址:https://js.coach/react-native/react-native-circular-progress?search=react-native 别谢我 点个赞就行 ## Use ...
- ImgNoGoodWindow
using System;using System.Collections.Generic;using System.Linq;using System.Text;using UnityEditor; ...
- hdu 5120 Intersection 两个圆的面积交
Intersection Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) P ...
- Oracle(order by)
传统数据查询只会按照设置的主键排列.如果现在对制定的列进行排序的操作,那么就必须通过 ORDER BY 子句控制. 排序语法: SELECT [DISTINCT] * | 列名称 [AS] 列别名, ...
- HDU 1715 斐波那契数列1000项
二维数组模拟大数加法就可以了,不太难,直接上代码了. #include<stdio.h> #include<string.h> #include<math.h> # ...
- x1c2017 8G版 win linux的取舍纠结记录
x1c 2017 的 i5 7200U 8G ram 的丐版.换了1T SSD.其实一般使用没啥问题. 1 外出携带的轻便性太满意(mac13寸相比之下都太重了): 2 coding时候的安静性,比原 ...