我有一个需要加载到表中的CSV文件。使用"外部表"概念将数据插入表中,对于从CSV文件中拒绝的记录,我们可以得到行号。来自LOG文件的字段名称,但对于接受的行,即插入到表中的行,我们如何获取行号(CSV文件中的哪一行插入到表中);
CREATE TABLE emp_external
(
EMPNO NUMBER(4),
ENAME VARCHAR2(10),
JOB VARCHAR2(9),
MGR NUMBER(4),
SAL NUMBER(7,2),
COMM NUMBER(7,2),
DEPTNO NUMBER(2)
)
ORGANIZATION EXTERNAL
(TYPE ORACLE_LOADER
DEFAULT DIRECTORY my_data
ACCESS PARAMETERS
(RECORDS DELIMITED BY NEWLINE
LOGFILE my_data:'data.log'
BADFILE my_data:'data.bad'
DISCARDFILE my_data:'data.disc'
fields terminated by ','
MISSING FIELD VALUES ARE NULL
)
LOCATION (my_data:'emp.csv')
);
答案 0 :(得分:2)
你可以在最后(在DEPTNO之后)添加一个额外的字段(比如Line_Number)并在访问参数部分中将该字段填充为RECNUM 例如:
CREATE TABLE emp_external
(
....
....
DEPTNO NUMBER(2),
Line_Number VARCHAR2(10)
)
ORGANIZATION EXTERNAL
(TYPE ORACLE_LOADER
DEFAULT DIRECTORY my_data
ACCESS PARAMETERS
(RECORDS DELIMITED BY NEWLINE
LOGFILE my_data:'data.log'
BADFILE my_data:'data.bad'
DISCARDFILE my_data:'data.disc'
fields terminated by ','
MISSING FIELD VALUES ARE NULL
(
....
....
Line_Number RECNUM
)
)
LOCATION (my_data:'emp.csv')
);