0

FN_UPD正在调用CURSOR_SELECT,但我不断收到错误消息。

"Error(11,12): PLS-00201: identifier 'V_RC' must be declared"
when i try to add the DECLARE , it will throw other error.


create or replace procedure FN_UPD
( COL_A in varchar2 ,V_INPUT_TYP in varchar2)

IS
v_rc sys_refcursor;
begin
v_rc  := CURSOR_SELECT(COL_A, V_INPUT_TYP);


for f in v_rc 
loop
if (f.rownum = 1) then 
        update TB_TARGET SUMM set ENEX_ID = F.SNS_KEY, LAST__DT = F.VEH_ENT_EXT_ON
    where V_NUM = COL_A and INPUT_TYP = V_INPUT_TYP;
else
    update TB_TARGET SUMM set ENEX2_ID = f.sns_key, LAST2__DT = f.veh_ent_ext_on
     WHERE V_NUM = COL_A and INPUT_TYP = V_INPUT_TYP;
end if;
end loop;
commit;
--close C1;

EXCEPTION
WHEN OTHERS THEN

raise_application_error(-20001,'遇到错误 - '||SQLCODE||' -ERROR- '||SQLERRM); 结尾; /

遇到其他错误

"Error(10,12): PLS-00221: 'V_RC' is not a procedure or is undefined"

如果我更新到以下

create or replace procedure FN_UPD
 ( COL_A in varchar2 ,V_INPUT_TYP in varchar2) is
v_rc sys_refcursor;
begin
v_rc := CURSOR_SELECT(COL_A, V_INPUT_TYP);
4

2 回答 2

0

您需要为特定查询打开游标。

您的 v_rc 应该包含哪些记录?更具体地说,您要在什么值上运行 for 循环?

利用

create or replace procedure FN_UPD
 ( COL_A in varchar2 ,V_INPUT_TYP in varchar2) is
v_rc sys_refcursor;
begin
OPEN V_RC FOR SELECT X,Y,Z FROM YOUR_TABLE_FOR_LOOP;

for f in v_rc
.
.
.
.
.
CLOSE V_RC
于 2013-11-06T11:30:39.543 回答
0

您不需要循环,因为您不更改 where 子句:

试试这个:

CREATE OR REPLACE
PROCEDURE fn_upd(
          col_a       IN VARCHAR2 ,
          v_input_typ IN VARCHAR2)
IS
     v_rc sys_refcursor;
     l_id NUMBER;
     l_ent_on DATE;
BEGIN
     v_rc := cursor_select(col_a, v_input_typ);
     dbms_output.put_line ('Records to be processed: '||col_a);
     fetch v_rc INTO l_id, l_ent_on;
          UPDATE tb_target summ
          SET  enex_id   = l_id,
               last__dt  = l_ent_on
          WHERE v_num    = col_a
           AND input_typ = v_input_typ;

COMMIT;
exception WHEN others THEN
     raise_application_error(-20001,'An error was encountered - '||sqlcode||' -ERROR- '||sqlerrm);
END;
于 2013-11-06T04:32:00.437 回答