sqlldr中使用條件裝載及作為外部表訪問
目的:sqlldr中使用條件裝載及作為外部表訪問。
1,sqlldr中使用條件裝載:
[oracle@bocnet95 mh]$ cat netval.sql
create table netval
(
fncode VARCHAR2(6) not null,
fndate date,
netval NUMBER(7,4),
enddate date,
addupbns NUMBER(7,4),
addupnav NUMBER(7,4),
fundincomeunit NUMBER(7,4),
fundincomeratio NUMBER(7,4),
dayincomeratio NUMBER(7,4)
)
;
[oracle@bocnet95 mh]$ cat netval.dat
|000012|20110930|10.911|20110930|0|0|0|0|0|
|000031|20110930|1.134|20110930|0|0|0|0|0|
|000021|20110930|1.599|20110930|0|0|0|0|0|
|000001|20110930|1.003|20110930|0|0|0|0|0|
|000011|20110930|10.911|20110930|0|0|0|0|0|
|002021|20110930|1.042|20110930|0|0|0|0|0|
|002011|20110930|1.635|20110930|0|0|0|0|0|
|002031|20110930|2.252|20110930|0|0|0|0|0|
|002002|20110930|1.219|20110930|0|0|0|0|0|
|000061|20110930|.764|20110930|0|0|0|0|0|
[oracle@bocnet95 mh]$ cat netval.ctl
LOAD DATA
INFILE 'netval.dat'
REPLACE
INTO TABLE netval
WHEN FNCODE= '000021'
FIELDS TERMINATED BY '|'
(
col filler,
FNCODE,
FNDATE date "YYYYMMDD",
NETVAL,
ENDDATE date "YYYYMMDD",
ADDUPBNS,
ADDUPNAV,
FUNDINCOMEUNIT,
FUNDINCOMERATIO,
DAYINCOMERATIO
)
[oracle@bocnet95 mh]$ sqlldr mh/mh control=netval.ctl
裝載後可以查詢到符合條件的一條記錄。
2,sqlldr中作為外部表訪問。
2.1使用sqlldr生成建立外部表的sql:
[oracle@bocnet95 mh]$ sqlldr mh/mh control=netval.ctl external_table=generate_only
SQL*Loader: Release 10.2.0.1.0 - Production on Thu May 3 10:56:21 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
[oracle@bocnet95 mh]$ ls
netval.dat
netval.sql
netval.ctl
netval.log
[oracle@bocnet95 mh]$ cat netval.log
SQL*Loader: Release 10.2.0.1.0 - Production on Thu May 3 10:56:21 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Control File: netval.ctl
Data File: netval.dat
Bad File: netval.bad
Discard File: none specified
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Continuation: none specified
Path used: External Table
Table NETVAL, loaded when FNCODE = 0X303030303231(character '000021')
Insert option in effect for this table: REPLACE
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
COL FIRST * | CHARACTER
(FILLER FIELD)
FNCODE NEXT * | CHARACTER
FNDATE NEXT * | DATE YYYYMMDD
NETVAL NEXT * | CHARACTER
ENDDATE NEXT * | DATE YYYYMMDD
ADDUPBNS NEXT * | CHARACTER
ADDUPNAV NEXT * | CHARACTER
FUNDINCOMEUNIT NEXT * | CHARACTER
FUNDINCOMERATIO NEXT * | CHARACTER
DAYINCOMERATIO NEXT * | CHARACTER
CREATE DIRECTORY statements needed for files
------------------------------------------------------------------------
CREATE DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000 AS '/home/oracle/mh'
CREATE TABLE statement for external table:
------------------------------------------------------------------------
CREATE TABLE "SYS_SQLLDR_X_EXT_NETVAL"
(
"FNCODE" VARCHAR2(6),
"FNDATE" DATE,
"NETVAL" NUMBER(7,4),
"ENDDATE" DATE,
"ADDUPBNS" NUMBER(7,4),
"ADDUPNAV" NUMBER(7,4),
"FUNDINCOMEUNIT" NUMBER(7,4),
"FUNDINCOMERATIO" NUMBER(7,4),
"DAYINCOMERATIO" NUMBER(7,4)
)
ORGANIZATION external
(
TYPE oracle_loader
DEFAULT DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE CHARACTERSET AL32UTF8
LOAD WHEN ("FNCODE" = "000021")
BADFILE 'SYS_SQLLDR_XT_TMPDIR_00000':'netval.bad'
LOGFILE 'netval.log_xt'
READSIZE 1048576
FIELDS TERMINATED BY "|" LDRTRIM
REJECT ROWS WITH ALL NULL FIELDS
(
"COL" CHAR(255)
TERMINATED BY "|",
"FNCODE" CHAR(255)
TERMINATED BY "|",
"FNDATE" CHAR(255)
TERMINATED BY "|"
DATE_FORMAT DATE MASK "YYYYMMDD",
"NETVAL" CHAR(255)
TERMINATED BY "|",
"ENDDATE" CHAR(255)
TERMINATED BY "|"
DATE_FORMAT DATE MASK "YYYYMMDD",
"ADDUPBNS" CHAR(255)
TERMINATED BY "|",
"ADDUPNAV" CHAR(255)
TERMINATED BY "|",
"FUNDINCOMEUNIT" CHAR(255)
TERMINATED BY "|",
"FUNDINCOMERATIO" CHAR(255)
TERMINATED BY "|",
"DAYINCOMERATIO" CHAR(255)
TERMINATED BY "|"
)
)
location
(
'netval.dat'
)
)REJECT LIMIT UNLIMITED
INSERT statements used to load internal tables:
------------------------------------------------------------------------
INSERT /*+ append */ INTO NETVAL
(
FNCODE,
FNDATE,
NETVAL,
ENDDATE,
ADDUPBNS,
ADDUPNAV,
FUNDINCOMEUNIT,
FUNDINCOMERATIO,
DAYINCOMERATIO
)
SELECT
"FNCODE",
"FNDATE",
"NETVAL",
"ENDDATE",
"ADDUPBNS",
"ADDUPNAV",
"FUNDINCOMEUNIT",
"FUNDINCOMERATIO",
"DAYINCOMERATIO"
FROM "SYS_SQLLDR_X_EXT_NETVAL"
statements to cleanup objects created by previous statements:
------------------------------------------------------------------------
DROP TABLE "SYS_SQLLDR_X_EXT_NETVAL"
DROP DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000
Run began on Thu May 03 10:56:21 2012
Run ended on Thu May 03 10:56:21 2012
Elapsed time was: 00:00:00.07
CPU time was: 00:00:00.02
2.2 建立外部表、驗證:
[oracle@bocnet95 mh]$ sqlplus mh/mh
SQL*Plus: Release 10.2.0.1.0 - Production on Thu May 3 10:59:11 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> CREATE DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000 AS '/home/oracle/mh'
2 ;
Directory created.
SQL> CREATE TABLE "SYS_SQLLDR_X_EXT_NETVAL"
2 (
3 "FNCODE" VARCHAR2(6),
4 "FNDATE" DATE,
5 "NETVAL" NUMBER(7,4),
6 "ENDDATE" DATE,
7 "ADDUPBNS" NUMBER(7,4),
8 "ADDUPNAV" NUMBER(7,4),
9 "FUNDINCOMEUNIT" NUMBER(7,4),
10 "FUNDINCOMERATIO" NUMBER(7,4),
11 "DAYINCOMERATIO" NUMBER(7,4)
12 )
13 ORGANIZATION external
14 (
15 TYPE oracle_loader
16 DEFAULT DIRECTORY SYS_SQLLDR_XT_TMPDIR_00000
17 ACCESS PARAMETERS
18 (
19 RECORDS DELIMITED BY NEWLINE CHARACTERSET AL32UTF8
20 LOAD WHEN ("FNCODE" = "000021")
21 BADFILE 'SYS_SQLLDR_XT_TMPDIR_00000':'netval.bad'
22 LOGFILE 'netval.log_xt'
23 READSIZE 1048576
24 FIELDS TERMINATED BY "|" LDRTRIM
25 REJECT ROWS WITH ALL NULL FIELDS
26 (
27 "COL" CHAR(255)
28 TERMINATED BY "|",
29 "FNCODE" CHAR(255)
30 TERMINATED BY "|",
31 "FNDATE" CHAR(255)
32 TERMINATED BY "|"
33 DATE_FORMAT DATE MASK "YYYYMMDD",
34 "NETVAL" CHAR(255)
35 TERMINATED BY "|",
36 "ENDDATE" CHAR(255)
37 TERMINATED BY "|"
38 DATE_FORMAT DATE MASK "YYYYMMDD",
39 "ADDUPBNS" CHAR(255)
40 TERMINATED BY "|",
41 "ADDUPNAV" CHAR(255)
42 TERMINATED BY "|",
43 "FUNDINCOMEUNIT" CHAR(255)
44 TERMINATED BY "|",
45 "FUNDINCOMERATIO" CHAR(255)
46 TERMINATED BY "|",
47 "DAYINCOMERATIO" CHAR(255)
48 TERMINATED BY "|"
49 )
50 )
51 location
52 (
53 'netval.dat'
54 )
55 )REJECT LIMIT UNLIMITED;
Table created.
SQL> SELECT
2 "FNCODE",
3 "FNDATE",
4 "NETVAL",
5 "ENDDATE",
6 "ADDUPBNS",
7 "ADDUPNAV",
8 "FUNDINCOMEUNIT",
9 "FUNDINCOMERATIO",
10 "DAYINCOMERATIO"
11 FROM "SYS_SQLLDR_X_EXT_NETVAL"
12 ;
FNCODE FNDATE NETVAL ENDDATE ADDUPBNS ADDUPNAV
------ ------------------ ---------- ------------------ ---------- ----------
FUNDINCOMEUNIT FUNDINCOMERATIO DAYINCOMERATIO
-------------- --------------- --------------
000021 30-SEP-11 1.599 30-SEP-11 0 0
0 0 0
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/18922393/viewspace-722607/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle sqlldr 與 外部表OracleSQL
- 使用sqlldr載入外部檔案中的資料到Oracle中(轉)SQLOracle
- 使用外部表訪問監聽日誌
- 使用外部表訪問警告日誌檔案
- 測試TOM=SQLLDR生成外部表SQL
- 檔案作為塊裝置訪問
- 查詢正常作為條件報錯的問題
- 【SQLLDR】使用SQL*Loader輔助生成外部表建立語句SQL
- 查詢作為條件的SQLSQL
- sqlldr 裝載換行符(使用str屬性)SQL
- 資料型別為date作為查詢條件資料型別
- Vector用陣列下標訪問的條件陣列
- postgres_fdw 無法通過域名 訪問外部表問題
- 【SQL】SQL中if條件的使用SQL
- ABAP訪問外部SQL (轉)SQL
- Oracle中left join中右表的限制條件Oracle
- 使用 FOR ALL ENTRIES 將 ABAP 內表內容作為資料庫表的讀取條件之一試讀版資料庫
- 使用條件型別實現TypeScript中的函式過載型別TypeScript函式
- excel圖表中的條件格式化Excel
- 生產環境sqlldr載入效能問題及分析之一SQL
- 生產環境sqlldr載入效能問題及分析之二SQL
- outerDocument訪問外部屬性方法
- sqlldr載入效能問題的排查SQL
- php中條件語句的使用整理PHP
- 如何從 Vim 中訪問 shell 或者執行外部命令
- 【Azure微服務 Service Fabric 】Service Fabric中應用開啟外部訪問埠及微服務之間通過反向代理埠訪問問題微服務
- 報表查詢條件的 N 種使用方式
- java中使用URLClassLoader訪問外部jar包的java類JavaJAR
- Oracle外部表學習及Ora-01846問題Oracle
- 外部表載入資料(ExternalTables)
- CentOS 6.4 i386 版本安裝 FastDFS、使用Nginx作為檔案訪問WEB伺服器CentOSASTNginxWeb伺服器
- 用sqlloader(sqlldr)裝載LOB資料SQL
- 如何在ORACLE中修改表的約束條件啊Oracle
- Stream中filter過濾條件問題記錄Filter
- SQL中on條件與where條件的區別[轉]SQL
- ApacheActiveMQ安裝必要條件ApacheMQ
- knockoutjs如何動態載入外部的file作為component中的template資料來源JS
- 文字檔案的資料裝載工具sqlldrSQL