上傳個例子,好久不寫代碼,基本文法忘記得差不多了:這裡要注意,一個begin ....end 之間,exception放在end之前,要不然錯誤千奇百怪
set serveroutput on;
declare
v_cons_flg varchar2(1);
v_version varchar2(10);
v_name varchar2(20);
v_name2 varchar2(50);
v_value varchar2(100);
cursor tmp_cur is
select version, name,name2,value
from changemanagementddl ;
begin
v_cons_flg:='0';
open tmp_cur;
fetch tmp_cur into v_version, v_name, v_name2,v_value ;
while tmp_cur%found
loop
if instr(upper(v_value),'PRIMARY')<>0 then
v_cons_flg:='1';
else
v_cons_flg:='0';
end if ;
dbms_output.put_line('table:'||v_name||' '||'cons_flg:'||v_cons_flg) ;
update changemanagementddl
set cons_flg=v_cons_flg
where version=v_version and name=v_name and name2=v_name2;
commit;
fetch tmp_cur into v_version, v_name, v_name2,v_value ;
end loop;
close tmp_cur;
exception
when others then
update changemanagementddl
set cons_flg='2'
where version=v_version and name=v_name and name2=v_name2;
commit;
end ;