Oracle

當我從外部表載入時嘗試記錄錯誤時,為什麼會出現“缺少右括號”錯誤?

  • August 7, 2020

我已成功創建錯誤記錄表

BEGIN
   DBMS_ERRLOG.create_error_log(
   dml_table_name  => 'enzyme',
   skip_unsupported => TRUE);
END;
/

desc ERR$_ENZYME;
Name            Null? Type           
--------------- ----- -------------- 
ORA_ERR_NUMBER$       NUMBER         
ORA_ERR_MESG$         VARCHAR2(2000) 
ORA_ERR_ROWID$        UROWID         
ORA_ERR_OPTYP$        VARCHAR2(2)    
ORA_ERR_TAG$          VARCHAR2(2000) 
ENZ_NAME              VARCHAR2(4000) 

但是當我嘗試執行此查詢時出現錯誤:

insert /*+ ignore_row_on_dupkey_index ( enzyme ( enz_name ) ) */
into enzyme
SELECT enz_name FROM EXTERNAL ((
 construct_id NUMBER(10),
 n_term VARCHAR2 (50),
 enz_name VARCHAR2 (3),
 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
       FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
       MISSING FIELD VALUES ARE NULL 
       ) 
   LOCATION ('CONSTRUCT.CSV')
   LOG ERRORS INTO ERR$_ENZYME ('INSERT') REJECT LIMIT UNLIMITED) ext
   where not exists (
       select * from enzyme e
       where e.enz_name = ext.enz_name
   );
Error at Command Line : 79 Column : 5
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"
*Cause:    
*Action:

第 79 行是 LOG ERRORS INTO 行。

如果我刪除該LOG ERRORS INTO ERR$_ENZYME ('INSERT')部分,此命令將完美執行。

因為 DML 錯誤記錄 ( LOG ERRORS INTO ...) 部分屬於外部插入,而不是內聯外部表。將其從內部移出。

外部表具有不同類型的錯誤日誌記錄,可以使用BADFILE記錄有錯誤行的子句指定另一個文件。

更新:

像這樣的東西:

insert /*+ ignore_row_on_dupkey_index ( enzyme ( enz_name ) ) */
into enzyme
SELECT enz_name FROM EXTERNAL ((
 construct_id NUMBER(10),
 n_term VARCHAR2 (50),
 enz_name VARCHAR2 (3),
 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
       FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
       MISSING FIELD VALUES ARE NULL 
       ) 
   LOCATION ('CONSTRUCT.CSV')
   ) ext
   where not exists (
       select * from enzyme e
       where e.enz_name = ext.enz_name
   )
LOG ERRORS INTO ERR$_ENZYME ('INSERT') REJECT LIMIT UNLIMITED;

引用自:https://dba.stackexchange.com/questions/273416