oracle228
数据转载
数据的装载:
•SQL*LOADER
•外部表
•导入/导出
SQL*LOADER:
SQL*LOADER是一个ORACLE工具,能够将数据从外部数据文件装载到数据库中。
运行SQL*LOADER的命令是sqlldr。
Sqlldr的两种使用方式:
1. 只使用一个控制文件,在这个控制文件中包含数据
2. 使用一个控制文件(作为模板) 和一个数据文件
一般采用第二种方式,数据文件可以是 CSV 文件、txt文件或者以其他分割符分隔的。
说明:操作类型 可用以下中的一值:
1) insert --为缺省方式,在数据装载开始时要求表为空
2) append --在表中追加新记录
3) replace --删除旧记录(用 delete from table 语句),替换成新装载的记录
4) truncate --删除旧记录(用 truncate table 语句),替换成新装载的记录
通过spool来制作数据文件:--可以查询帮助文档的示例代码
SQL> spool /u01/app/oracle/test_data_loader/student.txt--开启spool导出数据文件
SQL> select id ||',' || name ||',' || age ||',' || inner_date from student;--导出数据
ID||','||NAME||','||AGE||','||INNER_DATE
--------------------------------------------------------------------------------
1,zhangsan,21,23-JAN-15
2,lisi,22,23-JAN-15
3,wangwu,23,23-JAN-15
SQL> spool off;--关闭
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@localhost test_data_loader]$ cat student.txt--可以查看到导出的数据记录
SQL> select id ||',' || name ||',' || age ||',' || inner_date from student;
ID||','||NAME||','||AGE||','||INNER_DATE
--------------------------------------------------------------------------------
1,zhangsan,21,23-JAN-15
2,lisi,22,23-JAN-15
3,wangwu,23,23-JAN-15
SQL> spool off;
写配置文件:
[oracle@localhost test_data_loader]$ vi student.ctl
[oracle@localhost test_data_loader]$ cat student.ctl
options(skip=4)--表示前面的四行
load data--导入数据
infile 'student.txt'--通过该文件导入数据
into table student--导入的表
insert--执行的是插入操作
fields terminated by ','--记录中的分割符
(
id char,--注意虽然表中是number类型,但是要写char类型
name char,
age char,
inner_date date nullif (inner_date = "null"))
[oracle@localhost test_data_loader]$
既然是insert操作所以:
SQL> truncate table student;--清空表,由于执行的是插入操作
Table truncated.
SQL> select * from student;
no rows selected
执行sqlldr操作:
[oracle@localhost test_data_loader]$ sqlldr hr/hr control= student.ctl log = student.log
SQL*Loader: Release 11.2.0.1.0 - Production on Fri Jan 23 23:11:08 2015
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 4
[oracle@localhost test_data_loader]$ cat student.log
SQL*Loader: Release 11.2.0.1.0 - Production on Fri Jan 23 23:11:08 2015
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Control File: student.ctl
Data File: student.txt
Bad File: student.bad
Discard File: none specified
(Allow all discards)
Number to load: ALL
Number to skip: 4
Errors allowed: 50
Bind array: 64 rows, maximum of 256000 bytes
Continuation: none specified
Path used: Conventional
Table STUDENT, loaded from every logical record.
Insert option in effect for this table: INSERT
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
ID FIRST * , CHARACTER
NAME NEXT * , CHARACTER
AGE NEXT * , CHARACTER
INNER_DATE NEXT * , DATE DD-MON-RR
NULL if INNER_DATE = 0X6e756c6c(character 'null')
Record 4: Rejected - Error on table STUDENT, column ID.
Column not found before end of logical record (use TRAILING NULLCOLS)
Table STUDENT:
3 Rows successfully loaded.
1 Row not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
Space allocated for bind array: 66048 bytes(64 rows)
Read buffer bytes: 1048576
Total logical records skipped: 4
Total logical records read: 4
Total logical records rejected: 1
Total logical records discarded: 0
Run began on Fri Jan 23 23:11:08 2015
Run ended on Fri Jan 23 23:11:08 2015
Elapsed time was: 00:00:00.10
CPU time was: 00:00:00.01
[oracle@localhost test_data_loader]$ sqlplus hr/hr
SQL*Plus: Release 11.2.0.1.0 Production on Fri Jan 23 23:13:14 2015
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select * from student;
ID NAME AGE INNER_DATE
---------- -------------------- ---------- ------------
1 zhangsan 21 23-JAN-15
2 lisi 22 23-JAN-15
3 wangwu 23 23-JAN-15
SQL> exit |
外部表:
外部表中的数据不装入数据库中,数据库中只存储外部表的定义信息,实际的数据位于操作系统的平面文件中,
但是,可以在数据库中,像访问正常表那样,通过select语句来访问操作系统中的平面文件中所含有的数据。
外部表是只读的。
可以使用SQL,PL/SQL和JAVA访问外部表。
外表表分为2种:使用数据泵引擎生成的外部表、
SQL>create table student_re(re_id,re_name,re_age,re_inner_date)
organization external
(
type oracle_datapump--外部表生成方式是数据泵
default directory test_impdp_expdp--默认的路径
location('student.dmp')--通过路径和文件名生成外部表在操作系统的平面数据文件
)
parallel--并行 as
select * from student; 2 3 4 5 6 7 8 9 10
Table created.
SQL> !ls
student.dmp STUENT_17109.log
SQL> select * from stuent;
RE_ID RE_NAME RE_AGE RE_INNER_DAT
---------- -------------------- ---------- ------------
1 zhangsan 21 23-JAN-15
2 lisi 22 23-JAN-15
3 wangwu 23 23-JAN-15
SQL> |
根据文本文件创建的外部表。
SQL> spool student.txt
ID||','||NAME||','||AGE||','||INNER_DATE
--------------------------------------------------------------------------------
1,zhangsan,21,23-JAN-15
2,lisi,22,23-JAN-15
3,wangwu,23,23-JAN-15
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@localhost test_impdp_expdp]$ vi student.txt
[oracle@localhost test_impdp_expdp]$ sqlplus hr/hr
SQL*Plus: Release 11.2.0.1.0 Production on Sat Jan 24 00:05:18 2015
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create table student_re_2--该外部表的名称下面列是外部表的建表语句,而上面通过数据泵的表是通过as select from tab来建立的。
2 (id number,name varchar2(20),age number(10),inner_date date)
3 organization external
4 ( type oracle_loader--外部文件方式
5 default directory test_impdp_expdp--默认的目录
6 access parameters--访问外部文件所遵守的格式
7 (
records delimited by newline--记录分隔符
fields terminated by ','--字段分隔符
8 ) location ('student.txt')--位置
); 9 10 11
Table created.
SQL> select * from student_re_2;
ID NAME AGE INNER_DATE
---------- -------------------- ---------- ------------
1 zhangsan 21 23-JAN-15
2 lisi 22 23-JAN-15
3 wangwu 23 23-JAN-15
SQL> |
分享到:
相关推荐
轻松导入数据 转载 非原创 大家共勉 版权共享
Oracle数据文件迁移(转载
【RPA之家转载】2UiPath数据表会话.mp4
PI NETWORK区块链一键备份UUID(原创,拒绝转载,谢谢)
数据来源:和鲸社区,转载请注明来源! 原作者:Ustinian 数据集连接:https://www.kesci.com/home/dataset/5eb69b4d366f4d002d77d63c/comment 原背景描述: 网易云音乐是一款专注于发现与分享的音乐产品,依托专业...
最近研究元数据管理,收集到的网上关于元数据管理的一些概念和相关说明
spring MVC数据绑定 含例子 转载自疯芒毕露的专栏 刚开始用spring mvc 做web开发时 经常会不知道如何合适绑定页面数据 用惯struts2的朋友更认为spring mvc 绑定数据不如struts2方便 本人最开始也是这么认为 经过一段...
WPF数据绑定 很详细,包含源代码:WPF 数据绑定[1]WPF 数据绑定[2]WPF 数据绑定[3]WPF 数据绑定[4]WPF 数据绑定[5]WPF 数据绑定[6]WPF 数据绑定[7]WPF 数据绑定[8]WPF 数据绑定[9]WPF 数据绑定[10]
提供推特内容、标签、转载数等源数据,相互学习,共同进步!
北京交通大学-数据结构925-13年-18年考研真题(转载)-附带答案
RSOD是一个开放的目标检测...版权声明:本文为CSDN博主「陨星落云」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/qq_28368377/article/details/121464756
对数据结构的各个部分,在C语言和c++语言数据结构的基础上,用C#语言进行了详细编写,内容参考性强,便于对数据结构的理解
oracle 导出数据字典的小工具 能导成word形式的带表格的数据字典,非常好用从网上转载的,不会的可以留言啊
RPA之家全套视频教程,想系统学习RPA的,可以下载该资源学习。在学习的过程中,如果碰到任何问题,也可以在评论区里面交流。
JavaScript中如何检测数据类型?有四种检测的方式: typeof:检测数据类型的运算符 instanceof : 检测某个实例是否属于这个类(什么是类) ...商业转载请联系作者获得授权,非商业转载请注明出处。
利用进程通信,获取手机内所有应用的缓存 及 应用数据转载请注明出处 利用进程通信,获取手机内所有应用的缓存 及 应用数据转载请注明出处 利用进程通信,获取手机内所有应用的缓存 及 应用数据转载请注明出处
描述多种数据分析方法
【原创整理,严禁任何团队和个人转载获利,转载必究!】 税调企业专利相关研究是近年来研究的热点方向之一,在各类顶级刊物中频繁出现。为附件 内为由本人及所在课题组独家整理、权威匹配、多重校验的2007-2016...
NULL 博文链接:https://gzuimis.iteye.com/blog/1912414