Oracle APEX应用程序MERGE语句 - ORA-06550子程序或游标超出范围

时间:2014-09-23 13:19:16

标签: sql oracle oracle-apex

我正在尝试为Oracle APEX应用程序编写MERGE语句。用户填写表单,如果唯一列STVSBGI_CODE不存在,则应插入该表单,如果STVSBGI_CODE存在则更新。这是我写的MERGE:

MERGE INTO UA_SATURN.SWBSBGI U
USING (SELECT :P5_STVSBGI_CODE, :P5_STATE_CODE, :P5_NCES_SCHOOL_ID, :P5_NCES_DISTRICT_ID, :APP_USER FROM DUAL) V
ON (U.STVSBGI_CODE = V.STVSBGI_CODE)
WHEN MATCHED THEN UPDATE SET
    U.STATE_CODE = :P5_STATE_CODE,
    U.NCES_SCHOOL_ID = :P5_NCES_SCHOOL_ID,
    U.NCES_DISTRICT_ID = :P5_NCES_DISTRICT_ID,
    U.ACTIVITY_DATE = SYSDATE,
    U.USER_ID = :APP_USER,
    U.ACTIVE_IND = 'Y'
WHEN NOT MATCHED THEN INSERT
(
    U.STVSBGI_CODE,
    U.STATE_CODE,
    U.NCES_SCHOOL_ID,
    U.NCES_DISTRICT_ID,
    U.ACTIVITY_DATE,
    U.USER_ID,
    U.ACTIVE_IND
)
VALUES
(
    :P5_STVSBGI_CODE,
    :P5_STATE_CODE,
    :P5_NCES_SCHOOL_ID,
    :P5_NCES_DISTRICT_ID,
    SYSDATE,
    :APP_USER,
    'Y'
);

这是我得到的错误:

1 error has occurred
ORA-06550: line 4, column 22: PLS-00225: subprogram or cursor 'V' reference is out of
scope ORA-06550: line 4, column 22: PLS-00306: wrong number or types of arguments in
call to 'STVSBGI_CODE' ORA-06550: line 4, column 22: PL/SQL: ORA-00904:
"V"."STVSBGI_CODE": invalid identifier ORA-06550: line 2, column 1: PL/SQL: SQL
Statement ignored

1 个答案:

答案 0 :(得分:2)

您需要在SELECT语句中对列进行别名,以便可以在JOIN中使用它,例如

SELECT :P5_STVSBGI_CODE AS STVSBGI_CODE, ...

谢谢!