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);
答案 0 :(得分: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;
答案 1 :(得分: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