我正在尝试从外部表中插入数据。
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),
发布于 2020-08-10 20:02:30
外部表名为construct_ext
CREATE TABLE construct_ext
( 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)
)
ORGANIZATION EXTERNAL
(
TYPE ORACLE_LOADER
DEFAULT DIRECTORY data_to_input
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII
TERRITORY AMERICA
SKIP 1
BADFILE bad_files:'badflie_insert_into_construct_from_construct.bad'
LOGFILE bad_files:'logflie_insert_into_construct_from_construct.log'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
MISSING FIELD VALUES ARE NULL
)
LOCATION ('CONSTRUCT.CSV')
) REJECT LIMIT UNLIMITED;
INSERT /*+ ignore_row_on_dupkey_index ( consruct ( construct_id ) ) */
INTO construct
(construct_id,
n_term,
enz_name,
c_term,
cpp,
mutations,
mw_kda)
SELECT
construct_id,
n_term ,
enz_name,
c_term ,
cpp ,
mutations ,
mw_kda
FROM
construct_ext 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
);
编辑:-根据@a_horse_with_no_name,您可以访问外部表,而无需为数据库版本18c及以上创建内联外部表
当您尝试插入目标表而不创建外部表(希望有人能说明这一点)时,问题就出现了:创建暂存表,然后插入目标表。
CREATE TABLE construct_stg
AS
-- select part works without creating external table
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_import
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII
TERRITORY AMERICA
SKIP 1
BADFILE bad_files:'badflie_insert_into_construct_from_construct.bad'
--LOGFILE bad_files:'logflie_insert_into_construct_from_construct.log'--create different directory for log file or skip this line
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
MISSING FIELD VALUES ARE NULL
(
construct_id,
n_term ,
enz_name,
c_term ,
cpp ,
mutations ,
mw_kda
)
)
LOCATION ('CONSTRUCT.CSV')
REJECT LIMIT UNLIMITED)ext_tab;
CREATE INDEX idx_construct_id ON construct_stg(construct_id);
ALTER TABLE construct_stg ADD CONSTRAINT pk_construct_id_stg PRIMARY KEY (construct_id) USING INDEX; -- to enforce unique or skip this
INSERT /*+ ignore_row_on_dupkey_index ( consruct,idx_construct_id) */
INTO construct
(construct_id,
n_term,
enz_name,
c_term,
cpp,
mutations,
mw_kda)
SELECT
construct_id,
n_term ,
enz_name,
c_term ,
cpp ,
mutations ,
mw_kda
FROM
construct_stg 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
);
https://dba.stackexchange.com/questions/273483
复制相似问题