跳过将数据加载到外部 table 的列
Skipping columns which loading data into an external table
这是我创建的外部table:
CREATE TABLE emp_load
(
"ESN_NO" VARCHAR2 (200),
"MAKER" VARCHAR2 (30),
"HANDSET" VARCHAR2 (20),
"MODEL_NO" VARCHAR2 (20),
"OMH_TTSL_FLAG" VARCHAR2 (10),
"OFFER" VARCHAR2 (100),
"STATUS" VARCHAR2 (20),
"STATUS_UPDATED_DATE" DATE
) ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER DEFAULT DIRECTORY "EXT_TAB_DIR" ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE skip 1
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
missing FIELD VALUES are NULL
) LOCATION ('BAU.csv')
) ;
BAU.csv
文件的示例内容
ESN No Make Model RI_value
A10000428A5348 Lava C180 OFFER14
A10000428A5349 Lava C180 OFFER14
A10000428A534A Lava C180 OFFER14
A10000428A534B Lava C180 OFFER14
它工作正常,但数据没有出现在我需要的列中;我希望 handset
列为空,但当前文件中的 model
值被加载到 handset
列中。所以我目前得到:
ESN_NO MAKER HANDSET MODEL_NO OMH_TTSL_FLAG OFFER STATUS STATUS_UPDATED_DATE
A10000428A5348 Lava C180 OFFER14
A10000428A5349 Lava C180 OFFER14
A10000428A534A Lava C180 OFFER14
A10000428A534B Lava C180 OFFER14
我希望跳过 handset
列并在 model_no
中插入 model
;和 omh_ttsl_flag
应该被跳过,文件中的 ri_value
应该被插入到 offer
中。所以我想要结束的是:
ESN_NO MAKER HANDSET MODEL_NO OMH_TTSL_FLAG OFFER STATUS STATUS_UPDATED_DATE
A10000428A5348 Lava C180 OFFER14
A10000428A5349 Lava C180 OFFER14
A10000428A534A Lava C180 OFFER14
A10000428A534B Lava C180 OFFER14
如何在将数据加载到外部 table 时跳过这些列?
insert into emp_load (ESN_NO,MAKER,MODEL_NO,OFFER)
values ('A10000428A5348','Lava','Lava','OFFER14)
默认值为 null ,因此所有其他列都将收到 null
您可以通过将文件中的字段指定为 fields
子句的一部分,并指定未与 the column transforms
clause 一起出现的字段来实现,例如:
COLUMN TRANSFORMS ("HANDSET" FROM NULL, "OMH_TTSL_FLAG" FROM NULL)
所以你的陈述变成:
CREATE TABLE emp_load
(
"ESN_NO" VARCHAR2 (200),
"MAKER" VARCHAR2 (30),
"HANDSET" VARCHAR2 (20),
"MODEL_NO" VARCHAR2 (20),
"OMH_TTSL_FLAG" VARCHAR2 (10),
"OFFER" VARCHAR2 (100),
"STATUS" VARCHAR2 (20),
"STATUS_UPDATED_DATE" DATE
)
ORGANIZATION EXTERNAL
(
TYPE ORACLE_LOADER DEFAULT DIRECTORY "EXT_TAB_DIR" ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE skip 1
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
MISSING FIELD VALUES ARE NULL
(
"ESN_NO" CHAR (200),
"MAKER" CHAR (30),
"MODEL_NO" CHAR (20),
"OFFER" CHAR (100)
)
COLUMN TRANSFORMS
(
"HANDSET" FROM NULL,
"OMH_TTSL_FLAG" FROM NULL,
"STATUS" FROM NULL,
"STATUS_UPDATED_DATE" FROM NULL
)
)
LOCATION ('BAU.csv')
) ;
我已经包含了其他两列,这不是必需的,但有助于记录您希望看到的内容。
将您的示例数据转换为 CSV,加载为:
set sqlformat ansiconsole
column esn_no format a20
select * from emp_load;
ESN_NO MAKER HANDSET MODEL_NO OMH_TTSL_FLAG OFFER STATUS STATUS_UPDATED_DATE
A10000428A5348 Lava C180 OFFER14
A10000428A5349 Lava C180 OFFER14
A10000428A534A Lava C180 OFFER14
A10000428A534B Lava C180 OFFER14
这是我创建的外部table:
CREATE TABLE emp_load
(
"ESN_NO" VARCHAR2 (200),
"MAKER" VARCHAR2 (30),
"HANDSET" VARCHAR2 (20),
"MODEL_NO" VARCHAR2 (20),
"OMH_TTSL_FLAG" VARCHAR2 (10),
"OFFER" VARCHAR2 (100),
"STATUS" VARCHAR2 (20),
"STATUS_UPDATED_DATE" DATE
) ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER DEFAULT DIRECTORY "EXT_TAB_DIR" ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE skip 1
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
missing FIELD VALUES are NULL
) LOCATION ('BAU.csv')
) ;
BAU.csv
文件的示例内容
ESN No Make Model RI_value
A10000428A5348 Lava C180 OFFER14
A10000428A5349 Lava C180 OFFER14
A10000428A534A Lava C180 OFFER14
A10000428A534B Lava C180 OFFER14
它工作正常,但数据没有出现在我需要的列中;我希望 handset
列为空,但当前文件中的 model
值被加载到 handset
列中。所以我目前得到:
ESN_NO MAKER HANDSET MODEL_NO OMH_TTSL_FLAG OFFER STATUS STATUS_UPDATED_DATE
A10000428A5348 Lava C180 OFFER14
A10000428A5349 Lava C180 OFFER14
A10000428A534A Lava C180 OFFER14
A10000428A534B Lava C180 OFFER14
我希望跳过 handset
列并在 model_no
中插入 model
;和 omh_ttsl_flag
应该被跳过,文件中的 ri_value
应该被插入到 offer
中。所以我想要结束的是:
ESN_NO MAKER HANDSET MODEL_NO OMH_TTSL_FLAG OFFER STATUS STATUS_UPDATED_DATE
A10000428A5348 Lava C180 OFFER14
A10000428A5349 Lava C180 OFFER14
A10000428A534A Lava C180 OFFER14
A10000428A534B Lava C180 OFFER14
如何在将数据加载到外部 table 时跳过这些列?
insert into emp_load (ESN_NO,MAKER,MODEL_NO,OFFER)
values ('A10000428A5348','Lava','Lava','OFFER14)
默认值为 null ,因此所有其他列都将收到 null
您可以通过将文件中的字段指定为 fields
子句的一部分,并指定未与 the column transforms
clause 一起出现的字段来实现,例如:
COLUMN TRANSFORMS ("HANDSET" FROM NULL, "OMH_TTSL_FLAG" FROM NULL)
所以你的陈述变成:
CREATE TABLE emp_load
(
"ESN_NO" VARCHAR2 (200),
"MAKER" VARCHAR2 (30),
"HANDSET" VARCHAR2 (20),
"MODEL_NO" VARCHAR2 (20),
"OMH_TTSL_FLAG" VARCHAR2 (10),
"OFFER" VARCHAR2 (100),
"STATUS" VARCHAR2 (20),
"STATUS_UPDATED_DATE" DATE
)
ORGANIZATION EXTERNAL
(
TYPE ORACLE_LOADER DEFAULT DIRECTORY "EXT_TAB_DIR" ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE skip 1
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
MISSING FIELD VALUES ARE NULL
(
"ESN_NO" CHAR (200),
"MAKER" CHAR (30),
"MODEL_NO" CHAR (20),
"OFFER" CHAR (100)
)
COLUMN TRANSFORMS
(
"HANDSET" FROM NULL,
"OMH_TTSL_FLAG" FROM NULL,
"STATUS" FROM NULL,
"STATUS_UPDATED_DATE" FROM NULL
)
)
LOCATION ('BAU.csv')
) ;
我已经包含了其他两列,这不是必需的,但有助于记录您希望看到的内容。
将您的示例数据转换为 CSV,加载为:
set sqlformat ansiconsole
column esn_no format a20
select * from emp_load;
ESN_NO MAKER HANDSET MODEL_NO OMH_TTSL_FLAG OFFER STATUS STATUS_UPDATED_DATE
A10000428A5348 Lava C180 OFFER14
A10000428A5349 Lava C180 OFFER14
A10000428A534A Lava C180 OFFER14
A10000428A534B Lava C180 OFFER14