我在将for循环变量传递给显式声明的游标时遇到问题。这是PL / SQL代码:
DECLARE
count_total number := 0;
i number :=0;
ch varchar(10) := 'abc';
ch2 varchar(10) := 'xyz';
CURSOR cursor_sim_b IS **--identifying if value is garbage--**
select a1,a2, a3, a4, a5, a6,
trim(translate(a1,'0123456789',' ')),
trim(translate(a2,'0123456789',' ')),
trim(translate(a3,'0123456789',' ')),
trim(translate(a4,'0123456789',' ')),
trim(translate(a5,'0123456789',' ')),
trim(translate(a6,'0123456789',' '))
from temp_clean;
sim_b_rec cursor_sim_b%rowtype;
BEGIN
dbms_output.put_line('OUTSIDE the CURSOR ');
FOR sim_b_rec IN cursor_sim_b
LOOP
dbms_output.put_line('OUTSIDE the FOR LOOP ');
FOR i IN 1..6
LOOP
ch := 'a' ||i;
if sim_b_rec.ch is not null **--ERROR--**
then
BEGIN
execute immediate 'update temp_clean
set sim_b_rec.%ch = NULL';
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
END;
DBMS_OUTPUT.PUT_LINE('a'||i||'<' || ch || '>');
end if;
END LOOP;
END LOOP;
END;
/
获得以下错误: PLS-00302:组件&#39; CH&#39;必须声明
有没有办法将变量传递给光标?
答案 0 :(得分:0)
怎么样:
update temp_clean
set a1=case when trim(translate(a1,'0123456789',' ')) is not null then null else a1 end,
a2=case when trim(translate(a2,'0123456789',' ')) is not null then null else a1 end,
a3=case when trim(translate(a3,'0123456789',' ')) is not null then null else a1 end,
a4=case when trim(translate(a4,'0123456789',' ')) is not null then null else a1 end,
a5=case when trim(translate(a5,'0123456789',' ')) is not null then null else a1 end,
a6=case when trim(translate(a6,'0123456789',' ')) is not null then null else a1 end