有一表tableA(l_serial_no,l_result,vc_str)
其中:
l_serial_no为主键。
l_result初始全部为0。
vc_str存的是字符串,例如'(1>0.5 and 1<0.7)'。现在需要根据vc_str的表达式的值来重置l_result为0或者1。该表数据量比较多。请问有没有比较好的方式能满足上述需求,最好能整表更新。谢谢
其中:
l_serial_no为主键。
l_result初始全部为0。
vc_str存的是字符串,例如'(1>0.5 and 1<0.7)'。现在需要根据vc_str的表达式的值来重置l_result为0或者1。该表数据量比较多。请问有没有比较好的方式能满足上述需求,最好能整表更新。谢谢
select 1 l_serial_no,0 l_result,'(1>0.5 and 1<0.7)' vc_str from dual
union all select 2,0,'1=1' from dual
union all select 3,0,'2>3' from dual
union all select 4,0,'(11=2+3 or 1<2)' from dual;create or replace function func(str in varchar2)return number
as
flag number;
begin
execute immediate 'select case when '||str||' then 1 else 0 end from dual' into flag;
return flag;
end;select l_serial_no,func(vc_str) l_result,vc_str from tablea;/*
L_SERIAL_NO L_RESULT VC_STR
1 0 (1>0.5 and 1<0.7)
2 1 1=1
3 0 2>3
4 1 (11=2+3 or 1<2)
*/
--更新
update tablea set l_result=func(vc_str);