ORA-01722:无效编号ORA-06512:位于“BWSTAGE.LOAD_CONTACT_PROCEDURE”,第8行ORA-06512:第2行

时间:2017-11-22 07:22:18

标签: oracle stored-procedures plsql

CREATE OR REPLACE PROCEDURE LOAD_CONTACT_PROCEDURE AS

CURSOR C1 IS SELECT FIRST_NAME, MIDDLE_INITIAL, LAST_NAME, TITLE, DATE_OF_BIRTH, PHONE_MOBILE, PREFERRED_PHONE, EMAIL_ADDRESS, PREFERRED_EMAIL, DECEASED, 
preferred_name, student_id, last_website_login, north_america_email, international_email, afloat_email, lifelong_quarterly, fundraising_email, id_first_name, 
id_middle_name, id_last_name, id_number, passport_first_name, passport_middle_name, passport_last_nm, passport_number, passport_issuing_auth, passport_date_issued, 
passport_expiration_dt, state_of_birth, special_needs_descr, whitelist_descr FROM STAGE_CONTACT;

BEGIN

FOR i IN C1 LOOP

INSERT INTO LOAD_CONTACT(FIRSTNAME, MIDDLENAME, LASTNAME, TITLE, BIRTHDATE, PHONE, NPE01__PREFERREDPHONE__C, NPE01__HOMEEMAIL__C, NPE01__PREFERRED_EMAIL__C,
NPSP__DECEASED__C, PREFERRED_NAME__C, STUDENT_ID__C, LAST_WEBSITE_LOGIN__C, NORTH_AMERICA_EMAIL__C, INTERNATIONAL_EMAIL__C, AFLOAT_EMAIL__C, LIFELONG_QUARTERLY__C,
FUNDRAISING_EMAIL__C, ID_FIRST_NAME__C, ID_MIDDLE_NAME__C, ID_LAST_NAME__C, ID_NUMBER__C, PASSPORT_FIRST_NAME__C, PASSPORT_MIDDLE_NAME__C, PASSPORT_LAST_NAME__C, 
PASSPORT_NUMBER__C, PASSPORT_ISSUING_AUTHORITY__C, PASSPORT_DATE_ISSUED__C, PASSPORT_EXPIRATION_DATE__C, STATE_OF_BIRTH__C, SPECIAL_NEEDS_DESCRIPTION__C, 
WHITELIST_DESCRIPTION__C) 

VALUES 

(i.FIRST_NAME, i.MIDDLE_INITIAL, i.LAST_NAME, i.TITLE, i.DATE_OF_BIRTH, i.PHONE_MOBILE, 'Home', i.EMAIL_ADDRESS, 'Personal',
DECODE (i.DECEASED, 'Y', '1', 'N', '0'), i.preferred_name, i.student_id, i.last_website_login, DECODE (i.north_america_email, 'Y', '1', 'N', '0'), 
DECODE (i.international_email, 'Y', '1', 'N', '0'), DECODE (i.afloat_email, 'Y', '1', 'N', '0'), DECODE (i.lifelong_quarterly, 'Y', '1', 'N', '0'),
DECODE (i.fundraising_email, 'Y', '1', 'N', '0'), i.id_first_name, i.id_middle_name, i.id_last_name, i.id_number, i.passport_first_name, i.passport_middle_name, 
i.passport_last_nm, i.passport_number, i.passport_issuing_auth, i.passport_date_issued, i.passport_expiration_dt, i.state_of_birth, i.special_needs_descr,
i.whitelist_descr);

END LOOP;

COMMIT;

END LOAD_CONTACT_PROCEDURE;

我正在编写此程序,我收到以下错误:

  

ORA-01722:无效的数字ORA-06512:at   “BWSTAGE.LOAD_CONTACT_PROCEDURE”,第8行ORA-06512:第2行

我试图解决它很久以来但我无法找到解决方案。请帮忙。

1 个答案:

答案 0 :(得分:-1)

ORA-01722: invalid number表示您正在尝试将非数字值放入数字列中。因此,您需要检查在INSERT投影中引用的LOAD_CONTACT中的所有列,并将它们与VALUES子句中的列进行比较。

有两种可能性:

  1. 两个投影不同步,你需要重新订购一个以匹配另一个。
  2. STAGE_CONTACT使用字符串列作为数字属性。这对于临时表来说并不罕见。但它确实使staging表包含无法转换为数字的字符串。这很难捕捉到。
  3. 但你可以加入一些粗略的错误处理:

    FOR i IN C1 LOOP
       begin
         INSERT INTO LOAD_CONTACT(FIRSTNAME, MIDDLENAME, LASTNAME, TITLE, BIRTHDATE, PHONE, NPE01__PREFERREDPHONE__C, NPE01__HOMEEMAIL__C, NPE01__PREFERRED_EMAIL__C,
    NPSP__DECEASED__C, PREFERRED_NAME__C, STUDENT_ID__C, LAST_WEBSITE_LOGIN__C, NORTH_AMERICA_EMAIL__C, INTERNATIONAL_EMAIL__C, AFLOAT_EMAIL__C, LIFELONG_QUARTERLY__C,
    FUNDRAISING_EMAIL__C, ID_FIRST_NAME__C, ID_MIDDLE_NAME__C, ID_LAST_NAME__C, ID_NUMBER__C, PASSPORT_FIRST_NAME__C, PASSPORT_MIDDLE_NAME__C, PASSPORT_LAST_NAME__C, 
    PASSPORT_NUMBER__C, PASSPORT_ISSUING_AUTHORITY__C, PASSPORT_DATE_ISSUED__C, PASSPORT_EXPIRATION_DATE__C, STATE_OF_BIRTH__C, SPECIAL_NEEDS_DESCRIPTION__C, 
    WHITELIST_DESCRIPTION__C) 
    
        VALUES 
    
        (i.FIRST_NAME, i.MIDDLE_INITIAL, i.LAST_NAME, i.TITLE, i.DATE_OF_BIRTH, i.PHONE_MOBILE, 'Home', i.EMAIL_ADDRESS, 'Personal',
    DECODE (i.DECEASED, 'Y', '1', 'N', '0'), i.preferred_name, i.student_id, i.last_website_login, DECODE (i.north_america_email, 'Y', '1', 'N', '0'), 
    DECODE (i.international_email, 'Y', '1', 'N', '0'), DECODE (i.afloat_email, 'Y', '1', 'N', '0'), DECODE (i.lifelong_quarterly, 'Y', '1', 'N', '0'),
    DECODE (i.fundraising_email, 'Y', '1', 'N', '0'), i.id_first_name, i.id_middle_name, i.id_last_name, i.id_number, i.passport_first_name, i.passport_middle_name, 
    i.passport_last_nm, i.passport_number, i.passport_issuing_auth, i.passport_date_issued, i.passport_expiration_dt, i.state_of_birth, i.special_needs_descr,
    i.whitelist_descr);
    
     exception
        when invalid_number then
            raise_application_error(-20000, 
                 'record for ' ||i.FIRST_NAME||' '||i.MIDDLE_INITIAL||' '||i.LAST_NAME 
           || ' contains invalid number',
                true);
      end;
    END LOOP;
    

    这将为您提供一些信息,您可以使用这些信息查询STAGE_CONTACT并查找恶意值。

    如果您为真实系统(而不是家庭作业)执行此操作,则应调查Oracle的批量DML错误日志记录。 Find out more