Oracle SQL Procedure错误

时间:2016-04-26 11:05:52

标签: sql oracle

贝娄是我的程序。

CREATE OR REPLACE PROCEDURE "CUSTOMER_INCREMENTAL" (
    ID VARCHAR2, 
    TITLE VARCHAR2, 
    SHORT_NAME VARCHAR2, 
    ACCOUNT_OFFICER VARCHAR2, 
    LEGAL_ID VARCHAR2, 
    LOCAL_REF_23 VARCHAR2, 
    LOCAL_REF_90 VARCHAR2, 
    COUNTRY VARCHAR2, 
    BIRTH_INCORP_DATE VARCHAR2, 
    LOCAL_REF_1 VARCHAR2, 
    CUSTOMER_STATUS VARCHAR2, 
    INDUSTRY VARCHAR2, 
    LEGAL_ID_2 VARCHAR2, 
    NET_MONTHLY_IN VARCHAR2, 
    GENDER VARCHAR2, 
    MARITAL_STATUS VARCHAR2, 
    OCCUPATION VARCHAR2, 
    EMPLOYERS_NAME VARCHAR2, 
    OFF_PHONE VARCHAR2, 
    EMPLOYERS_ADD VARCHAR2, 
    NO_OF_DEPENDENTS VARCHAR2, 
    INTRODUCER VARCHAR2, 
    DATE_TIME DATE, 
    LAST_KYC_REVIEW_DATE VARCHAR2, 
    JOB_TITLE VARCHAR2, 
    EMPLOYMENT_STATUS VARCHAR2, 
    LOCAL_REF_22 VARCHAR2, 
    LOCAL_REF_99 VARCHAR2, 
    LEGAL_EXP_DATE VARCHAR2, 
    DATE_OF_BIRTH VARCHAR2, 
    NATIONALITY VARCHAR2, 
    GIVEN_NAMES VARCHAR2, 
    FAMILY_NAME VARCHAR2, 
    LOCAL_REF_87 VARCHAR2, 
    NAME_2 VARCHAR2, 
    STREET VARCHAR2, 
    ADDRESS VARCHAR2, 
    TOWN_COUNTRY VARCHAR2, 
    LOCAL_REF_20 VARCHAR2, 
    LOCAL_REF_21 VARCHAR2, 
    COUNTRY_2 VARCHAR2, 
    POST_CODE VARCHAR2, 
    PHONE_1 VARCHAR2, 
    FAX_1 VARCHAR2, 
    SMS_1 VARCHAR2, 
    EMAIL_1 VARCHAR2, 
    LOCAL_REF_66 VARCHAR2, 
    LOCAL_REF_67 VARCHAR2, 
    LOCAL_REF_68 VARCHAR2, 
    LOCAL_REF_69 VARCHAR2, 
    LOCAL_REF_70 VARCHAR2, 
    LOCAL_REF_71 VARCHAR2, 
    LOCAL_REF_81 VARCHAR2, 
    LOCAL_REF_72 VARCHAR2, 
    RELATION_CODE VARCHAR2, 
    BASEL_SG VARCHAR2, 
    LEGAL_DOC_NAME VARCHAR2, 
    LEGAL_ID_3 VARCHAR2, 
    LEGAL_ISS_AUTH VARCHAR2, 
    LEGAL_EXP_DATE_2 VARCHAR2, 
    DATE_TIME_2 VARCHAR2, 
    LOCAL_REF_4 VARCHAR2, 
    MNEMONIC VARCHAR2, 
    PEP VARCHAR2, 
    RESIDENCE VARCHAR2, 
    OTHER_NATIONALITY VARCHAR2, 
    FADCA_CUS_POB VARCHAR2,
    RUN_DATE DATE,
    TABLE_NAME VARCHAR2 
    )  IS   
BEGIN
  INSERT INTO NDB_AML_CUSTOMER 
    (ID, TITLE, SHORT_NAME, ACCOUNT_OFFICER, LEGAL_ID, LOCAL_REF_23, 
     LOCAL_REF_90, COUNTRY, BIRTH_INCORP_DATE,LOCAL_REF_1, CUSTOMER_STATUS, 
     INDUSTRY, LEGAL_ID_2, NET_MONTHLY_IN, GENDER, MARITAL_STATUS, 
     OCCUPATION, EMPLOYERS_NAME, OFF_PHONE, EMPLOYERS_ADD, NO_OF_DEPENDENTS, 
     INTRODUCER, DATE_TIME, LAST_KYC_REVIEW_DATE, JOB_TITLE, 
     EMPLOYMENT_STATUS, LOCAL_REF_22, LOCAL_REF_99, LEGAL_EXP_DATE, 
     DATE_OF_BIRTH, NATIONALITY, GIVEN_NAMES, FAMILY_NAME, LOCAL_REF_87, 
     NAME_2, STREET, ADDRESS, TOWN_COUNTRY, LOCAL_REF_20, LOCAL_REF_21, 
     COUNTRY_2, POST_CODE, PHONE_1, FAX_1, SMS_1, EMAIL_1, LOCAL_REF_66, 
     LOCAL_REF_67, LOCAL_REF_68, LOCAL_REF_69, LOCAL_REF_70, 
     LOCAL_REF_71, LOCAL_REF_81, LOCAL_REF_72, RELATION_CODE, BASEL_SG, 
     LEGAL_DOC_NAME, LEGAL_ID_3, LEGAL_ISS_AUTH, LEGAL_EXP_DATE_2, 
     DATE_TIME_2, LOCAL_REF_4, MNEMONIC, PEP, RESIDENCE, OTHER_NATIONALITY, 
     FADCA_CUS_POB)
  SELECT ID, TITLE, SHORT_NAME, ACCOUNT_OFFICER, LEGAL_ID, LOCAL_REF_23,  
         LOCAL_REF_90, COUNTRY, BIRTH_INCORP_DATE, LOCAL_REF_1, 
         CUSTOMER_STATUS, INDUSTRY, LEGAL_ID_2, NET_MONTHLY_IN, GENDER, 
         MARITAL_STATUS, OCCUPATION, EMPLOYERS_NAME, OFF_PHONE, 
         EMPLOYERS_ADD, NO_OF_DEPENDENTS, INTRODUCER, DATE_TIME, 
         LAST_KYC_REVIEW_DATE, JOB_TITLE, EMPLOYMENT_STATUS, LOCAL_REF_22,
         LOCAL_REF_99, LEGAL_EXP_DATE, DATE_OF_BIRTH, NATIONALITY, 
         GIVEN_NAMES, FAMILY_NAME, LOCAL_REF_87, NAME_2, STREET, ADDRESS, 
         TOWN_COUNTRY, LOCAL_REF_20, LOCAL_REF_21, COUNTRY_2, POST_CODE, 
         PHONE_1, FAX_1, SMS_1, EMAIL_1, LOCAL_REF_66, LOCAL_REF_67, 
         LOCAL_REF_68, LOCAL_REF_69, LOCAL_REF_70, LOCAL_REF_71, 
         LOCAL_REF_81, LOCAL_REF_72, RELATION_CODE, BASEL_SG, 
         LEGAL_DOC_NAME, LEGAL_ID_3, LEGAL_ISS_AUTH, LEGAL_EXP_DATE_2, 
         DATE_TIME_2, LOCAL_REF_4, MNEMONIC, PEP, RESIDENCE, 
         OTHER_NATIONALITY, FADCA_CUS_POB
    FROM NDB_CUSTOMER_NEW
    WHERE DATE_TIME > (SELECT RUN_DATE
                         FROM CHECK_POINT
                         WHERE TABLE_NAME = (SELECT TABLE_NAME
                                               FROM ALL_TABLES
                                               WHERE TABLE_NAME='NDB_CUSTOMER_NEW'));

  UPDATE CHECK_POINT
    SET RUN_DATE = SYSDATE;

  COMMIT;
END;
/   

当我执行时我正在

  

参数的数量或类型错误

1 个答案:

答案 0 :(得分:2)

您已经为您的程序声明了很多formal parameters,但您从未使用它们。您插入NDB_AML_CUSTOMER的所有值都来自NDB_CUSTOMER_NEW

所以你的程序声明只需要:

CREATE OR REPLACE PROCEDURE "CUSTOMER_INCREMENTAL"
IS
BEGIN
  INSERT INTO ...
  UPDATE ...
  COMMIT;
END;

不需要针对ALL_TABLES的子查询;所有它真正能做的就是检查表是否存在,但如果没有,则解析器在执行该子查询之前会抛出错误。获取RUN_DATE的子查询可能只是:

SELECT RUN_DATE FROM CHECK_POINT WHERE TABLE_NAME = 'NDB_CUSTOMER_NEW'

但假设这意味着您有多个记录,每个目标表的运行日期不同,您的更新只需要触摸相同的单个记录:

UPDATE CHECK_POINT SET RUN_DATE = SYSDATE WHERE TABLE_NAME = 'NDB_CUSTOMER_NEW';

您也可能遇到一些与您正在进行的跟踪有关的问题。首先,会话可以同时执行此操作并看到相同的RUN_DATE值,可能导致数据重复或约束违规。其次,在您运行插入的时间与更新RUN_DATE时记录的时间之间存在(小)差距;如果记录在NDB_CUSTOMER_NEW中添加到DATE_TIME,则该记录将永远不会被处理。您可能希望了解for updatecurrent of以便更安全地管理它。