从 csv 文件导入到 oracle table 时出现问题,列消息重复,但没有列重复

Issue with importing to oracle table from csv file, duplicate column message, but no column duplication

以下生成 ORA-00957 重复列名,但列名不重复。我使用的是 Oracle Express Edition,版本 18C

Create Or Replace Procedure XE_IMP_Census_Employer_000001_LOAD
As

Begin
  INSERT INTO XE_IMP_Census_Employer_000001(
      SSN                              ,
      SSN_Old                          ,
      Employee_ID                      ,
      Employee_ID_Old                  ,
      First_Name                       ,
      Middle_Name                                            ,
      Last_Name                        ,
      Street_1                         ,
      Street_2                         ,
      City                             ,
      State                            ,
      Zip                              ,
      DOB                              ,
      DOD                              ,
      Employee_EMail                   ,
      Phone_Cell                       ,
      Orig_Hire_Date                   ,
      ReHire_Date                      ,
      Pay_Freq                         ,
      Pay_Type                         ,
      Annual_Salary                    ,
      FT_PT                            ,
      Job_Title                        ,
      Gender_MF                        ,
      Life_Insur_Coverage              ,
      EPR                            ,
      OPTOUT_401K                    ,
      OPTIN_401K                                             
      )
    SELECT 
      SSN,                             
      SSN_Old,                         
      Employee_ID,                     
      Employee_ID_Old,                 
      First_Name,                      
      Middle_Name,                      
      Last_Name,                       
      Street_1,                        
      Street_2,                        
      City,                            
      State,                           
      Zip,                             
      DOB,                             
      DOD,                             
      Employee_Email,                  
      Phone_Cell,                      
      Orig_Hire_Date,                  
      ReHire_Date,                     
      Pay_Freq,                        
      Pay_Type,                        
      Annual_Salary,                   
      FT_PT,                           
      Job_Title,                       
      Gender_MF,                       
      Life_Insur_Coverage,             
      EPR,                              
      OPTOUT_401K,                      
      OPTIN_401K                       
    
    FROM   EXTERNAL (   
    (
      SSN                                   Varchar2(11)     ,  
      SSN_Old                               Varchar2(11)     ,  
      Employee_ID                           Varchar2(20)    ,   
      Employee_ID_Old                       Varchar2(20)    ,   
      First_Name                            Varchar2(30)    ,   
      Middle_Name                                         Varchar2(30)    ,   
      Last_Name                             Varchar2(30)    ,   
      Street_1                              Varchar2(40)    ,   
      Street_2                              Varchar2(40)    ,   
      City                                  Varchar2(64)    ,   
      State                                 Varchar2(64)    ,   
      Zip                                   Varchar2(15)    ,   
      DOB                                   Date            ,   
      DOD                                   Date            ,   
      Employee_EMail                        Varchar2(254)   ,   
      Phone_Cell                            Varchar2(15)    ,   
      Orig_Hire_Date                        Date            ,   
      ReHire_Date                           Date            ,   
      Pay_Freq                              Varchar2(50)    ,   
      Pay_Type                              Varchar2(50)    ,   
      Annual_Salary                         Number(20,2)    ,   
      FT_PT                                 Varchar2(5)     ,   
      Job_Title                             Varchar2(50)    ,   
      Gender_MF                             Varchar2(4)     ,   
      Life_Insur_Coverage                   Number(20,2)    ,   
      EPR                                                           Varchar2(50)    ,   
      OPTOUT_401K                                               Date                        ,   
      OPTIN_401K                            Date                            
    )     
    TYPE ORACLE_LOADER     
    DEFAULT DIRECTORY DATA_PUMP_DIR
    ACCESS PARAMETERS (
      RECORDS DELIMITED BY NEWLINE
      FIELDS TERMINATED BY ',')     
   LOCATION ('PersonCensus.csv') REJECT LIMIT UNLIMITED);
   

End XE_IMP_Census_Employer_000001_LOAD;
/

您使用的语法允许动态定义外部 table,我认为这可能是问题的根本原因(我可以通过重命名来消除 ORA-00957 错误来自外部 table 的所有列,但在此之后我在 line/column 0/0 上收到关于一些意外括号的语法错误。

如果您不能使用这种语法来使用最简单的语句,我建议 使用经典语法创建外部 table:

SQL> create table ET
  2  (
  3        SSN                   Varchar2(11)     ,
  4        SSN_Old               Varchar2(11)     ,
  5        Employee_ID               Varchar2(20)    ,
  6        Employee_ID_Old           Varchar2(20)    ,
  7        First_Name                Varchar2(30)    ,
  8        Middle_Name               Varchar2(30)    ,
  9        Last_Name                 Varchar2(30)    ,
 10        Street_1              Varchar2(40)    ,
 11        Street_2              Varchar2(40)    ,
 12        City                  Varchar2(64)    ,
 13        State                 Varchar2(64)    ,
 14        Zip                   Varchar2(15)    ,
 15        DOB                   Date        ,
 16        DOD                   Date        ,
 17        Employee_EMail            Varchar2(254)   ,
 18        Phone_Cell                Varchar2(15)    ,
 19        Orig_Hire_Date            Date        ,
 20        ReHire_Date               Date        ,
 21        Pay_Freq              Varchar2(50)    ,
 22        Pay_Type              Varchar2(50)    ,
 23        Annual_Salary             Number(20,2)    ,
 24        FT_PT                 Varchar2(5)     ,
 25        Job_Title                 Varchar2(50)    ,
 26        Gender_MF                 Varchar2(4)     ,
 27        Life_Insur_Coverage           Number(20,2)    ,
 28        EPR                   Varchar2(50)    ,
 29        OPTOUT_401K               Date,
 30        OPTIN_401K                Date
 31  )
 32  ORGANIZATION EXTERNAL
 33  (
 34    TYPE ORACLE_LOADER
 35    DEFAULT DIRECTORY DATA_PUMP_DIR
 36    ACCESS PARAMETERS (
 37    RECORDS DELIMITED BY NEWLINE
 38    FIELDS TERMINATED BY ',')
 39    LOCATION ('PersonCensus.csv')
 40  ) REJECT LIMIT UNLIMITED;

Table created.

并且 运行 一个简单的 INSERT ... SELECT ... 来自这个外部 table 应该可以工作:

insert into xe_imp_census_employer_000001
select * from et;