点击上方“IT那活儿”公众号,关注后了解更多内容,不管IT什么活儿,干就完了!!!
前期准备
[oracle@host01]$ zcat ceshi.dat.gz
A,AA,1,11,AAA
B,BB,2,22,BBB
C,CC,3,33,CCC
D,DD,4,44,DDD
E,EE,5,55,EEE
F,FF,6,66,FFF
G,GG,7,77,ggg
[oracle@host01]$ cat uncompress.sh
/bin/gunzip -c $1
编辑sqlldr控制文件
create table sh.ceshi(sname varchar2(2000),cname varchar2(2000),sno varchar2(2000),cno varchar2(2000));
[oracle@host01]$ cat ceshi.ctl
LOAD DATA
INFILE /home/oracle/scripts/ceshi.dat.gz
BADFILE /home/oracle/scripts/ceshi.bad
DISCARDFILE /home/oracle/scripts/ceshi.dsc
APPEND
INTO TABLE sh.prod_master
FIELDS TERMINATED BY , OPTIONALLY ENCLOSED BY "
TRAILING NULLCOLS
(sname, cname, sno, cno)
生成外部表语句
[oracle@host01 Skillset3]$ sqlldr sh/sh control=ceshi.ctl log=external.log external_table=generate_only
SQL*Loader: Release 12.1.0.2.0 - Production on Mon Sep 19 22:38:58 2022
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
Path used: External Table
[oracle@host01 Skillset3]$ cat external.log
SQL*Loader: Release 12.1.0.2.0 - Production on Mon Sep 19 22:38:58 2022
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
Control File: ceshi.ctl
Data File: /home/oracle/scripts/ceshi.dat.gz
Bad File: /home/oracle/scripts/ceshi.bad
Discard File: /home/oracle/scripts/ceshi.dsc
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Continuation: none specified
Path used: External Table
Table SH.CESHI, loaded from every logical record.
Insert option in effect for this table: APPEND
TRAILING NULLCOLS option in effect
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
SNAME FIRST * , O(") CHARACTER
CNAME NEXT * , O(") CHARACTER
SNO NEXT * , O(") CHARACTER
CNO NEXT * , O(") CHARACTER
CREATE DIRECTORY statements needed for files
------------------------------------------------------------------------
CREATE DIRECTORY SYS_SQLLDR_XT_TMPDIR_00002 AS /home/oracle/scripts/
CREATE DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000 AS /home/oracle/scripts/
CREATE TABLE statement for external table:
------------------------------------------------------------------------
CREATE TABLE "SYS_SQLLDR_X_EXT_CESHI"
(
"SNAME" VARCHAR2(2000),
"CNAME" VARCHAR2(2000),
"SNO" VARCHAR2(2000),
"CNO" VARCHAR2(2000)
)
ORGANIZATION external
(
TYPE oracle_loader
DEFAULT DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII
BADFILE SYS_SQLLDR_XT_TMPDIR_00000:ceshi.bad
DISCARDFILE SYS_SQLLDR_XT_TMPDIR_00000:ceshi.dsc
LOGFILE SYS_SQLLDR_XT_TMPDIR_00002:external.log_xt
READSIZE 1048576
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY " LDRTRIM
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
(
"SNAME" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY ",
"CNAME" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY ",
"SNO" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY ",
"CNO" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY "
)
)
location
(
ceshi.dat.gz
)
)REJECT LIMIT UNLIMITED
INSERT statements used to load internal tables:
------------------------------------------------------------------------
INSERT /*+ append */ INTO SH.CESHI
(
SNAME,
CNAME,
SNO,
CNO
)
SELECT
"SNAME",
"CNAME",
"SNO",
"CNO"
FROM "SYS_SQLLDR_X_EXT_CESHI"
statements to cleanup objects created by previous statements:
------------------------------------------------------------------------
DROP TABLE "SYS_SQLLDR_X_EXT_CESHI"
DROP DIRECTORY SYS_SQLLDR_XT_TMPDIR_00002
DROP DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000
Run began on Mon Sep 19 22:38:58 2022
Run ended on Mon Sep 19 22:38:58 2022
Elapsed time was: 00:00:00.16
CPU time was: 00:00:00.00
[oracle@host01 Skillset3]$ cat external.log
CREATE TABLE sh.ceshi
(
"SNAME" VARCHAR2(2000),
"CNAME" VARCHAR2(2000),
"SNO" VARCHAR2(2000),
"CNO" VARCHAR2(2000)
)
ORGANIZATION external
(
TYPE oracle_loader
DEFAULT DIRECTORY SYS_SQLLDR_XT_TMPDIR_00002
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE CHARACTERSET AL32UTF8
PREPROCESSOR SYS_SQLLDR_XT_TMPDIR_00002:uncompress.sh
BADFILE SYS_SQLLDR_XT_TMPDIR_00002:ceshi.bad
DISCARDFILE SYS_SQLLDR_XT_TMPDIR_00002:ceshi.dsc
LOGFILE SYS_SQLLDR_XT_TMPDIR_00002:external.log_xt
READSIZE 1048576
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY " LDRTRIM
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
(
"SNAME" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY ",
"CNAME" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY ",
"SNO" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY ",
"CNO" CHAR(255)
TERMINATED BY "," OPTIONALLY ENCLOSED BY "
)
)
location
(
ceshi.dat.gz
)
)REJECT LIMIT UNLIMITED;
建表
CREATE DIRECTORY SYS_SQLLDR_XT_TMPDIR_00002 AS /home/oracle/scripts/;
grant read,write,execute on directory SYS_SQLLDR_XT_TMPDIR_00002 to public;
SH@PROD4 >drop table sh.ceshi;
Table dropped.
SH@PROD4 >@external.log
Table created.
验证
SH@PROD4 >set pages 200
SH@PROD4 >col sname for a20
SH@PROD4 >col cname for a20
SH@PROD4 >col sno for a20
SH@PROD4 >col cno for a20
SH@PROD4 >select * from ceshi;
SNAME CNAME SNO CNO
-------------------- -------------------- -------------------- --------------------
A AA 1 11
B BB 2 22
C CC 3 33
D DD 4 44
E EE 5 55
F FF 6 66
G GG 7 77
7 rows selected.
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/129166.html
摘要:为了避免这种情况,可以针对表短期内被两个以上的语句所加载执行一个大的数据压缩。通常,对一张大表执行数据压缩会花费大量的时间几分钟到几小时不等。 本文介绍了如何将数据从现有的RDBMS迁移到Trafodion数据库。从其它的RDBMS或外部数据源向Trafodion集群中导入大量的重要数据,可以通过下面两步完美实现: 在Trafodion集群中,将数据从源头导入Hive表。使用下列方...
摘要:移动易后台实现外部数据库连接要实现外置数据库,即上层开发人员不关心下层数据库的实现,在项目中需要针对不同数据库修改文件以及在项目中添加依赖包。本文主要介绍移动易后台如何实现同不同数据源的连接,数据源包括,。 1、移动易后台实现外部数据库连接 要实现外置数据库,即上层开发人员不关心下层数据库的实现,在Spring boot项目 中需要针对不同数据库修改application.proper...
摘要:数据排序使用的列数,取最前面几列,不能超过总的列数。示例创建一个动态分区表。创建外部表创建外部表在创建外部表的目的是可以通过访问外部数据库。创建表时,关于和的数量和数据量的建议。 建表(Create Table)创建表语法:CREATE TABLE [IF NOT EXISTS] [database.]table ( column_definition_list, [inde...
摘要:摘要第九届中国数据库技术大会,阿里云数据库产品专家萧少聪带来以阿里云如何打破迁移上云的壁垒为题的演讲。于是,阿里云给出了上面的解决方案。 摘要: 2018第九届中国数据库技术大会,阿里云数据库产品专家萧少聪带来以阿里云如何打破Oracle迁移上云的壁垒为题的演讲。Oracle是指数据库管理系统,面对Oracle迁移上云的壁垒,阿里云如何能够打破它呢?本文提出了Oracle 到云数据库P...
阅读 1356·2023-01-11 13:20
阅读 1706·2023-01-11 13:20
阅读 1215·2023-01-11 13:20
阅读 1906·2023-01-11 13:20
阅读 4165·2023-01-11 13:20
阅读 2755·2023-01-11 13:20
阅读 1400·2023-01-11 13:20
阅读 3670·2023-01-11 13:20