點擊上方“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.
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/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...
閱讀 1346·2023-01-11 13:20
閱讀 1684·2023-01-11 13:20
閱讀 1132·2023-01-11 13:20
閱讀 1858·2023-01-11 13:20
閱讀 4100·2023-01-11 13:20
閱讀 2704·2023-01-11 13:20
閱讀 1385·2023-01-11 13:20
閱讀 3597·2023-01-11 13:20