如何使用oracle中的控制文件更新列?

时间:2017-06-01 13:38:22

标签: oracle sql-loader

如果满足条件,我想更新表中的列。使用sqlldr将数据加载到表中时会发生这种情况。下面是我为此编写的控制文件。我在通过sqlldr执行此操作时遇到了一些问题。

options (SKIP=1,bindsize=1048576, rows=500, errors=100)
LOAD DATA
INFILE '/home/x069291/appln/ncisdr/inbound/ExternalUserMasterNCI.TXT'
APPEND
INTO TABLE OMS_DP_EXTERNAL_USERS
FIELDS TERMINATED BY ";"
trailing nullcols
(STATUS,
USER_NAME,
FIRST_NAME,
MIDDLE_NAME,
LAST_NAME,
CMPNY_NM,
EMAIL,
MAILING_ADDRESS,
CITY,
STATE_PROVINCE,
ZIP_POSTALCODE,
COUNTRY,
PRIMARY_PHONE_NUMBER,
FAX_NUMBER,
BH_AFFILIATE,
USER_TYPE "CASE when USER_TYPE='NCIF' THEN 'G' ELSE USER_TYPE END'",
DPRTMT_NM,
TITLE,
CREATED_DATE "to_timestamp(:created_date,'YYYY-MM-DD HH24:MI:SS.FF')",
MODIFIED_DATE "to_timestamp(:modified_date,'YYYY-MM-DD HH24:MI:SS.FF')"
)

以下是文件中的数据

STATUS;USER_ID;FIRST_NAME;MIDDLE_NAME;LAST_NAME;COMPANY;EMAIL;MAILING_ADDRESS;CITY;STATE_PROVINCE;ZIP_POSTALCODE;COUNTRY;PHONE;FAX;AFFLIATE;USER_TYPE;Code;Fleet_Account_Type;CREATED_DT;UPDATED_DT
Active;XD429895;DPTesttt;M;Fleet;Hertz;;1 Nissan way;Franklin;TN ;37067;CA;231-231-2312;;NCI;NCIF;R01_FTP02;E01010101;24-APR-17 03.27.52.542000 PM;24-APR-17 03.27.52.542000 PM 
Active;XD961792;DPTesttttt;M;NCIfleet;Enterprise;;1 Nissan way;Franklin;TN ;37067;CA;123-123-1231;;NCI;NCIF;E01_12102;R01010101;24-APR-17 03.28.58.337000 PM;24-APR-17 03.28.58.337000 PM 


Below is the table structure i am using for this. 
Name                       Null Type               
Name                       Null Type               
-------------------------- ---- ------------------ 
STATUS                          VARCHAR2(10 CHAR)  
USER_NAME                       VARCHAR2(60 CHAR)  
FIRST_NAME                      VARCHAR2(60 CHAR)  
MIDDLE_NAME                     VARCHAR2(60 CHAR)  
LAST_NAME                       VARCHAR2(60 CHAR)  
POSITION                        CHAR(3 CHAR)       
TITLE                           VARCHAR2(60 CHAR)  
DEALER_EMPLOYEE_NUMBER          VARCHAR2(60 CHAR)  
HIRE_DATE                       DATE               
DATE_OF_BIRTH                   DATE               
LMS_PERSON_ID                   VARCHAR2(60 CHAR)  
EID                             VARCHAR2(60 CHAR)  
LANGUAGE                        VARCHAR2(50 CHAR)  
DOCUMENT_SENSITIVITY_LEVEL      VARCHAR2(50 CHAR)  
EMAIL                           VARCHAR2(120 CHAR) 
EMAIL2                          VARCHAR2(120 CHAR) 
EMAIL3                          VARCHAR2(120 CHAR) 
PRIMARY_PHONE_NUMBER            VARCHAR2(50 CHAR)  
ALTERNATE_PHONE_NUMBER          VARCHAR2(50 CHAR)  
FAX_NUMBER                      VARCHAR2(50 CHAR)  
MAILING_ADDRESS                 VARCHAR2(100 CHAR) 
CITY                            VARCHAR2(50 CHAR)  
STATE_PROVINCE                  VARCHAR2(15 CHAR)  
ZIP_POSTALCODE                  CHAR(20 CHAR)      
COUNTRY                         VARCHAR2(50 CHAR)  
APPLICATION_ROLE                VARCHAR2(120 CHAR) 
FUNCTIONAL_ROLE                 VARCHAR2(50 CHAR)  
PARTSNET_REGISTRATION           VARCHAR2(50 CHAR)  
DEALER_NUMBER                   VARCHAR2(20 CHAR)  
DEALER_NAME                     VARCHAR2(50 CHAR)  
BH_AFFILIATE                    VARCHAR2(50 CHAR)  
BH_CHANNEL_CODE                 VARCHAR2(25 CHAR)  
BH_DIVISION_NAME                VARCHAR2(50 CHAR)  
SALES_REGION_CODE               CHAR(3 CHAR)       
SALES_REGION_NAME               VARCHAR2(50 CHAR)  
SALES_DISTRICT_CODE             CHAR(3 CHAR)       
SALES_DISTRICT_NAME             VARCHAR2(50 CHAR)  
USER_TYPE                       CHAR(3 CHAR)       
CREATED_DATE                    TIMESTAMP(6)       
MODIFIED_DATE                   TIMESTAMP(6)       
CMPNY_NM                        VARCHAR2(50 CHAR)  
DPRTMT_NM                       VARCHAR2(50 CHAR)   

and i am previously facing the error ORA-00984: column not allowed here
After including Boeinst changes i got the error
SQL*Loader-350: Syntax error at line 23.
Expecting "," or ")", found "USER_TYPE".
USER_TYPE USER_TYPE "DECODE(:user_type, 'NCIF', 'G', :user_type)",

1 个答案:

答案 0 :(得分:0)

在END之后你有一个额外的单引号,也没有使用绑定变量:

USER_TYPE "CASE when USER_TYPE='NCIF' THEN 'G' ELSE USER_TYPE END'",

更改为:

USER_TYPE "CASE when :USER_TYPE='NCIF' THEN 'G' ELSE :USER_TYPE END",