declare
t_zl varchar2(100);
t_ts varchar2(100);
t_l number;
hh varchar2(100);
xx varchar2(100);
type TIArray is table of varchar2(100);
type TCArray is table of varchar2(100);
A TIArray;
B TCArray;
cursor c is select zl,tstybm from fc_h_qsdc2;
begin
A:=TIArray('四十七','四十六','四十五','四十四','四十三','四十二','四十一','三十九','三十八','三十七',
'三十六','三十五','三十四','三十三','三十二','三十一','二十九','二十八','二十七','二十六','二十五','二十四','二十三',
'二十二','二十一','四十','三十','二十','十九','十八','十七','十六','十五','十四','十三','十二','十一','十','九','八','七','六','五','四','三','二','一');
B:=TCArray('47','46','45','44','43','42','41','39','38','37','36','35','34','33','32','31','29','28','27','26','25','24','23','22','21','40','30','20','19','18','17','16','15','14','13','12','11','10','9'
,'8','7','6','5','4','3','2','1');
open c;
loop
fetch c into t_zl,t_ts;
exit when c%notfound;
for i in 1..47 loop
select instr(t_zl,A(i)) into xx from dual;
if (xx>0 and length(A(i))=3) then
hh:=substr(t_zl,1,xx-1)||B(i)||substr(t_zl,xx+3);
elsif(xx>0 and length(A(i))=2) then
hh:=substr(t_zl,1,xx-1)||B(i)||substr(t_zl,xx+2);
elsif(xx>0 and length(A(i))=1) then
hh:=substr(t_zl,1,xx-1)||B(i)||substr(t_zl,xx+1);
else
hh:=t_zl;
end if;
t_zl:=hh;
end loop;
update fc_h_qsdc2 set zl=t_zl where tstybm=t_ts;
end loop;
close c;
end;