我正在尝试从外部表中插入数据。
INSERT /*+ ignore_row_on_dupkey_index ( consruct ( construct_id ) ) */
INTO construct
(construct_id,
n_term ,
enz_name,
c_term,
cpp,
mutations,
mw_kda)
SELECT *
FROM EXTERNAL ((
construct_id NUMBER(10),
n_term VARCHAR2 (50),
enz_name VARCHAR2 (50),
c_term VARCHAR2 (50),
cpp VARCHAR2 (50),
mutations VARCHAR2 (50),
mw_kda NUMBER (7,3))
TYPE ORACLE_LOADER
DEFAULT DIRECTORY data_to_input
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE
SKIP 1
BADFILE bad_files:'badflie_insert_into_construct_from_construct.bad'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
MISSING FIELD VALUES ARE NULL
)
LOCATION ('CONSTRUCT.CSV')
REJECT LIMIT UNLIMITED) ext
WHERE NOT EXISTS (
SELECT * FROM construct c
WHERE c.n_term = ext.n_term
AND c.enz_name = ext.enz_name
AND c.c_term = ext.c_term
AND c.cpp = ext.cpp
AND c.mutations = ext.mutations
);
但现在我得到这个错误:
Error at Command Line : 171 Column : 7
Error report -
SQL Error: ORA-00957: duplicate column name
00957. 00000 - "duplicate column name"
第 171 行是这部分的最后一行
INSERT /*+ ignore_row_on_dupkey_index ( consruct ( construct_id ) ) */
INTO construct
(construct_id,
n_term ,
enz_name,
c_term,
cpp,
mutations,
mw_kda)
这显然不是重复的列。
如果我做:
INSERT /*+ ignore_row_on_dupkey_index ( consruct ( construct_id ) ) */
INTO construct
(construct_id,
n_term,
enz_name,
c_term,
cpp,
mutations,
mw_kda)
SELECT *
FROM EXTERNAL ((
ext.construct_id NUMBER (10),
ext.n_term VARCHAR2 (50),
ext.enz_name VARCHAR2 (50),
ext.c_term VARCHAR2 (50),
ext.cpp VARCHAR2 (50),
ext.mutations VARCHAR2 (50),
ext.mw_kda NUMBER (7,3))
TYPE ORACLE_LOADER
DEFAULT DIRECTORY data_to_input
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE
SKIP 1
BADFILE bad_files:'badflie_insert_into_construct_from_construct.bad'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
MISSING FIELD VALUES ARE NULL
)
LOCATION ('CONSTRUCT.CSV')
REJECT LIMIT UNLIMITED) ext
WHERE NOT EXISTS (
SELECT * FROM construct c
WHERE c.n_term = ext.n_term
AND c.enz_name = ext.enz_name
AND c.c_term = ext.c_term
AND c.cpp = ext.cpp
AND c.mutations = ext.mutations
);
我明白了
Error at Command Line : 174 Column : 10
Error report -
SQL Error: ORA-00902: invalid datatype
00902. 00000 - "invalid datatype"
第 171 行是ext.construct_id NUMBER (10),
外部表名是
construct_ext
编辑:-创建外部表后验证您是否能够查询该表
编辑:-根据@a_horse_with_no_name,您可以访问外部表,而无需为数据库版本 18c 及更高版本创建使用内联外部表
当您尝试在不创建外部表的情况下插入目标表时出现问题(希望有人能对此有所了解)解决方法是创建临时表然后插入目标表