ORA-24344:编译错误成功103/9 PL / SQL:ORA-00913:值太多

时间:2015-07-29 15:48:34

标签: oracle plsql oracle11g triggers rowtype

我正在尝试创建一个触发器,它将插入带有更多数据的记录,但我的触发器创建正在抛出编译错误

[Warning] ORA-24344: success with compilation error 103/9 PL/SQL: ORA-00913: too many values 16/9 PL/SQL: SQL Statement ignored (1: 0): Warning: compiled but with compilation errors

以下是我的触发代码

CREATE OR REPLACE trigger insert_into_out_customer
before insert
on out_customer
for each row

DECLARE
v_username out_customer.created_by%TYPE;
newRow out_customer%ROWTYPE;
cId out_customer.CUSTOMER_ID%TYPE;

begin

SELECT user INTO v_username
FROM dual;

:new.created_by := v_username;
:new.updated_by := v_username;
cId := :new.CUSTOMER_ID;


    SELECT  
    SAS_FATCA_CUSTOMER.CUSTOMER_ID  ,
    CUSTOMER_TYPE   ,
    CUSTOMER_SUB_TYPE   ,
    FIRST_NAME  ,
    MIDDLE_NAME ,
    LAST_NAME   ,
    DOB ,
    PASSPORT_NUMBER ,
    GREEN_CARD_HOLDER   ,
    GREEN_CARD_NUMBER   ,
    TIN ,
    PRIMARY_ADDR_LINE_1 ,
    PRIMARY_ADDR_LINE_2 ,
    PRIMARY_ADDR_CITY   ,
    PRIMARY_ADDR_STATE  ,
    PRIMARY_ADDR_POSTAL_CODE    ,
    PRIMARY_ADDR_COUNTRY    ,
    PRIMARY_ADDR_PHONE_COUNTRY_CD   ,
    PRIMARY_ADDR_PHONE_NUMBER   ,
    PRIMARY_EMAIL   ,
    SECONDARY_ADDR_LINE_1   ,
    SECONDARY_ADDR_LINE_2   ,
    SECONDARY_ADDR_CITY ,
    SECONDARY_ADDR_STATE    ,
    SECONDARY_ADDR_POSTAL_CODE  ,
    SECONDARY_ADDR_COUNTRY  ,
    SECONDARY_ADDR_PHONE_CNTRY_CD   ,
    SECONDARY_ADDR_PHONE_NUMBER ,
    SECONDARY_EMAIL ,
    CITIZENSHIP ,
    COUNTRY_OF_ORIGIN   ,
    NATIONALITY_1   ,
    NATIONALITY_2   ,
    BANK_STAFF_ID   ,
    SELF_CERTIFICATION_RESPONSE ,
    SELF_CERTIFICATION_REASON   ,
    SELF_CERTIFICATION_TIMESTAMP    ,
    'EDIT_FLAG' ,
    POA_EXISTS  ,
    POA_FIRST_NAME  ,
    POA_LAST_NAME   ,
    POA_DOB ,
    POA_ADDR_LINE_1 ,
    POA_ADDR_LINE_2 ,
    POA_CITY    ,
    POA_STATE   ,
    POA_POSTAL_CODE ,
    POA_COUNTRY ,
    POA_COUNTRY_OF_ORIGIN   ,
    POA_PHONE_COUNTRY_CODE  ,
    POA_PHONE_NUMBER    ,
    BENEFICIARY_BANK_ADDRESS_LINE1  ,
    BENEFICIARY_BANK_ADDRESS_LINE2  ,
    BENEFICIARY_BANK_CITY   ,
    BENEFICIARY_BANK_POSTAL_CODE    ,
    BENEFICIARY_BANK_COUNTRY    ,
    BENEFICIARY_BANK_IFSC_CODE  ,
    'ACCOUNT_NUMBER'    ,
    'ACCOUNT_NAME'    ,
    'ACCOUNT_OPEN_DATE'    ,
    'BASE_CURRENCY '   ,
   ' ACCOUNT_BALANCE_BASE_CURRENCY'    ,
   ' ACCOUNT_BALANCE_US_CURRENCY'    ,
    'GROSS_WITHDRAWALS'    ,
   ' GROSS_PROCEEDS'    ,
    'GROSS_DIVIDENDS'    ,
    'GROSS_INTERESTS'   ,
    'OTHER_INCOME'    ,
    sysdate
    POA_ID  ,
    STANDING_INSTRUCTION_ID ,
    BENEFICIARY_ACCOUNT_ID  ,
    BENEFICIARY_ACCOUNT_NUMBER  ,
    BENEFICIARY_ACCOUNT_NAME    ,
    BENEFICIARY_BANK_NAME   ,
    STANDING_INSTRUCTION_START_DT   ,
    STANDING_INSTRUCTION_END_DATE   ,
    STANDING_INS_AMOUNT ,
    STANDING_INSTRC_FREQUENCY   ,
    :new.FATCA_REASON   ,
    :new.fatca_flag ,
    SAS_FATCA_CUSTOMER.CREATED_BY   ,
    SAS_FATCA_CUSTOMER.CREATED_DT   ,
    SAS_FATCA_CUSTOMER.UPDATED_BY   ,
    SAS_FATCA_CUSTOMER.UPDATED_DT   
    into newRow
    FROM SAS_FATCA_CUSTOMER
    LEFT JOIN SAS_FATCA_ATTORNEY  ON SAS_FATCA_CUSTOMER.CUSTOMER_ID = SAS_FATCA_ATTORNEY.CUSTOMER_ID
    LEFT JOIN SAS_FATCA_STANDING_INSTRUCTION ON SAS_FATCA_CUSTOMER.CUSTOMER_ID = SAS_FATCA_STANDING_INSTRUCTION.CUSTOMER_ID
    where SAS_FATCA_CUSTOMER.CUSTOMER_ID= cId and rownum<2;


    :new.CUSTOMER_TYPE :=    newRow.CUSTOMER_TYPE ;
    :new.CUSTOMER_SUB_TYPE :=    newRow.CUSTOMER_SUB_TYPE ;
    :new.FIRST_NAME :=    newRow.FIRST_NAME ;
    :new.MIDDLE_NAME :=    newRow.MIDDLE_NAME ;
    :new.LAST_NAME :=    newRow.LAST_NAME ;
    :new.DOB :=    newRow.DOB ;
    :new.PASSPORT_NUMBER :=    newRow.PASSPORT_NUMBER ;
    :new.GREEN_CARD_HOLDER :=    newRow.GREEN_CARD_HOLDER ;
    :new.GREEN_CARD_NUMBER :=    newRow.GREEN_CARD_NUMBER ;
    :new.TIN :=    newRow.TIN ;
    :new.PRIMARY_ADDR_LINE_1 :=    newRow.PRIMARY_ADDR_LINE_1 ;
    :new.PRIMARY_ADDR_LINE_2 :=    newRow.PRIMARY_ADDR_LINE_2 ;
    :new.PRIMARY_ADDR_CITY :=    newRow.PRIMARY_ADDR_CITY ;
    :new.PRIMARY_ADDR_STATE :=    newRow.PRIMARY_ADDR_STATE ;
    :new.PRIMARY_ADDR_POSTAL_CODE :=    newRow.PRIMARY_ADDR_POSTAL_CODE ;
    :new.PRIMARY_ADDR_COUNTRY :=    newRow.PRIMARY_ADDR_COUNTRY ;
    :new.PRIMARY_ADDR_PHONE_COUNTRY_CD :=    newRow.PRIMARY_ADDR_PHONE_COUNTRY_CD ;
    :new.PRIMARY_ADDR_PHONE_NUMBER :=    newRow.PRIMARY_ADDR_PHONE_NUMBER ;
    :new.PRIMARY_EMAIL :=    newRow.PRIMARY_EMAIL ;
    :new.SECONDARY_ADDR_LINE_1 :=    newRow.SECONDARY_ADDR_LINE_1 ;
    :new.SECONDARY_ADDR_LINE_2 :=    newRow.SECONDARY_ADDR_LINE_2 ;
    :new.SECONDARY_ADDR_CITY :=    newRow.SECONDARY_ADDR_CITY ;
    :new.SECONDARY_ADDR_STATE :=    newRow.SECONDARY_ADDR_STATE ;
    :new.SECONDARY_ADDR_POSTAL_CODE :=    newRow.SECONDARY_ADDR_POSTAL_CODE ;
    :new.SECONDARY_ADDR_COUNTRY :=    newRow.SECONDARY_ADDR_COUNTRY ;
    :new.SECONDARY_ADDR_PHONE_CNTRY_CD :=    newRow.SECONDARY_ADDR_PHONE_CNTRY_CD ;
    :new.SECONDARY_ADDR_PHONE_NUMBER :=    newRow.SECONDARY_ADDR_PHONE_NUMBER ;
    :new.SECONDARY_EMAIL :=    newRow.SECONDARY_EMAIL ;
    :new.CITIZENSHIP :=    newRow.CITIZENSHIP ;
    :new.COUNTRY_OF_ORIGIN :=    newRow.COUNTRY_OF_ORIGIN ;
    :new.NATIONALITY_1 :=    newRow.NATIONALITY_1 ;
    :new.NATIONALITY_2 :=    newRow.NATIONALITY_2 ;
    :new.BANK_STAFF_ID :=    newRow.BANK_STAFF_ID ;
    :new.SELF_CERTIFICATION_RESPONSE :=    newRow.SELF_CERTIFICATION_RESPONSE ;
    :new.SELF_CERTIFICATION_REASON :=    newRow.SELF_CERTIFICATION_REASON ;
    :new.SELF_CERTIFICATION_TIMESTAMP :=    newRow.SELF_CERTIFICATION_TIMESTAMP ;
    :new.POA_EXISTS :=    newRow.POA_EXISTS ;
    :new.POA_FIRST_NAME :=    newRow.POA_FIRST_NAME ;
    :new.POA_LAST_NAME :=    newRow.POA_LAST_NAME ;
    :new.POA_DOB :=    newRow.POA_DOB ;
    :new.POA_ADDR_LINE_1 :=    newRow.POA_ADDR_LINE_1 ;
    :new.POA_ADDR_LINE_2 :=    newRow.POA_ADDR_LINE_2 ;
    :new.POA_CITY :=    newRow.POA_CITY ;
    :new.POA_STATE :=    newRow.POA_STATE ;
    :new.POA_POSTAL_CODE :=    newRow.POA_POSTAL_CODE ;
    :new.POA_COUNTRY :=    newRow.POA_COUNTRY ;
    :new.POA_COUNTRY_OF_ORIGIN :=    newRow.POA_COUNTRY_OF_ORIGIN ;
    :new.POA_PHONE_COUNTRY_CODE :=    newRow.POA_PHONE_COUNTRY_CODE ;
    :new.POA_PHONE_NUMBER :=    newRow.POA_PHONE_NUMBER ;
    :new.BENEFICIARY_BANK_ADDRESS_LINE1 :=    newRow.BENEFICIARY_BANK_ADDRESS_LINE1 ;
    :new.BENEFICIARY_BANK_ADDRESS_LINE2 :=    newRow.BENEFICIARY_BANK_ADDRESS_LINE2 ;
    :new.BENEFICIARY_BANK_CITY :=    newRow.BENEFICIARY_BANK_CITY ;
    :new.BENEFICIARY_BANK_POSTAL_CODE :=    newRow.BENEFICIARY_BANK_POSTAL_CODE ;
    :new.BENEFICIARY_BANK_COUNTRY :=    newRow.BENEFICIARY_BANK_COUNTRY ;
    :new.BENEFICIARY_BANK_IFSC_CODE    :=    newRow.BENEFICIARY_BANK_IFSC_CODE;

    commit;

end;

编辑1:以下查询工作正常,这意味着out_customer拥有所有列

SELECT  CUSTOMER_ID    ,
CUSTOMER_TYPE    ,
CUSTOMER_SUB_TYPE    ,
FIRST_NAME    ,
MIDDLE_NAME    ,
LAST_NAME    ,
DOB    ,
PASSPORT_NUMBER    ,
GREEN_CARD_HOLDER    ,
GREEN_CARD_NUMBER    ,
TIN    ,
PRIMARY_ADDR_LINE_1    ,
PRIMARY_ADDR_LINE_2    ,
PRIMARY_ADDR_CITY    ,
PRIMARY_ADDR_STATE    ,
PRIMARY_ADDR_POSTAL_CODE    ,
PRIMARY_ADDR_COUNTRY    , 
PRIMARY_ADDR_PHONE_COUNTRY_CD    ,
PRIMARY_ADDR_PHONE_NUMBER    ,
PRIMARY_EMAIL    ,
SECONDARY_ADDR_LINE_1    ,
SECONDARY_ADDR_LINE_2    ,
SECONDARY_ADDR_CITY    ,
SECONDARY_ADDR_STATE    ,
SECONDARY_ADDR_POSTAL_CODE    ,
SECONDARY_ADDR_COUNTRY    ,
SECONDARY_ADDR_PHONE_CNTRY_CD    ,
SECONDARY_ADDR_PHONE_NUMBER    ,
SECONDARY_EMAIL    ,
CITIZENSHIP    ,
COUNTRY_OF_ORIGIN    ,
NATIONALITY_1    ,
NATIONALITY_2    ,
BANK_STAFF_ID    ,
SELF_CERTIFICATION_RESPONSE    ,
SELF_CERTIFICATION_REASON    ,
SELF_CERTIFICATION_TIMESTAMP    ,
EDIT_FLAG    ,
POA_EXISTS    ,
POA_FIRST_NAME    ,
POA_LAST_NAME    ,
POA_DOB    ,
POA_ADDR_LINE_1    ,
POA_ADDR_LINE_2    ,
POA_CITY    ,
POA_STATE    ,
POA_POSTAL_CODE    ,
POA_COUNTRY    ,
POA_COUNTRY_OF_ORIGIN    ,
POA_PHONE_COUNTRY_CODE    ,
POA_PHONE_NUMBER    ,
BENEFICIARY_BANK_ADDRESS_LINE1    ,
BENEFICIARY_BANK_ADDRESS_LINE2    ,
BENEFICIARY_BANK_CITY    ,
BENEFICIARY_BANK_POSTAL_CODE    ,
BENEFICIARY_BANK_COUNTRY    ,
BENEFICIARY_BANK_IFSC_CODE    ,
ACCOUNT_NUMBER    ,
ACCOUNT_NAME    ,
ACCOUNT_OPEN_DATE    ,
BASE_CURRENCY    ,
ACCOUNT_BALANCE_BASE_CURRENCY    ,
ACCOUNT_BALANCE_US_CURRENCY    ,
GROSS_WITHDRAWALS    ,
GROSS_PROCEEDS    ,
GROSS_DIVIDENDS    ,
GROSS_INTERESTS    ,
OTHER_INCOME    ,
BALANCE_DATE    ,
POA_ID    ,
STANDING_INSTRUCTION_ID    ,
BENEFICIARY_ACCOUNT_ID    ,
BENEFICIARY_ACCOUNT_NUMBER    ,
BENEFICIARY_ACCOUNT_NAME    ,
BENEFICIARY_BANK_NAME    ,
STANDING_INSTRUCTION_START_DT    ,
STANDING_INSTRUCTION_END_DATE    ,
STANDING_INS_AMOUNT    ,
STANDING_INSTRC_FREQUENCY    ,
FATCA_REASON    ,
FATCA_FLAG    ,
CREATED_BY    ,
CREATED_DT    ,
UPDATED_BY    ,
UPDATED_DT    
from out_customer

我不确定这个错误是因为我使用%ROWTYPE变量来存储查询结果。请帮我。而且,如果这是因为%ROWTYPE,那么我可以用什么代替%ROWTYPE

1 个答案:

答案 0 :(得分:0)

在这种情况下令人困惑的错误是因为你的选择投影列太少,而不是太多:

create table t42 (col1 number, col2 number);

declare
  x t42%rowtype;
begin
  select 1 into x from dual;
end;
/

Error report -
ORA-06550: line 4, column 19:
PL/SQL: ORA-00913: too many values

如果你的选择中有太多列,那么你会得到ORA-00947: not enough values。据推测,这是基于rowtype变量,与select相比,列数太多,而不是像你期望的那样反过来。

在你的情况下,你错过了一个逗号。目前POA_IDsysdate的别名,而不是单独的列。所以这个:

    'OTHER_INCOME'    ,
    sysdate
    POA_ID  ,

应该是:

    'OTHER_INCOME'    ,
    sysdate,
    POA_ID  ,

顺便提一下,这两步选择包括你已经知道的值的所有内容到一个rowtype变量,然后将其中的一些值单独复制到:new pseudorow列中,似乎不必要地复杂化,如果表结构发生变化,可能会中断或者列不完全符合您的预期。 (这可能发生在环境之间移动;虽然这可能是一个迹象,你做错了)。

为什么不直接设置固定值:

:new.created_by := user;
:new.updated_by := user;
:new.some_column := sysdate;
:new.some_column := 'EDIT FLAG';
...

然后只选择你真正必须从其他表中直接得到的值:新变量列表?

你也无法在触发器内提交。