我的表格如下:
id jancuk pijut
-------------------------------
1 20 * 4
2 2 + 4
3 3 - 1 + 2
4 20 / 5
我想使用pijut
列的结果更新列jancuk
。这是否可以在oracle中使用查询?
因此,如果表已更新,那么表应如下所示:
id jancuk pijut
-------------------------------
1 20 * 4 80
2 2 + 4 6
3 3 - 1 + 2 4
4 20 / 5 4
请帮帮我。感谢。
答案 0 :(得分:2)
您可以使用带动态SQL的函数来执行此操作 -
create or replace function calc_value(str in varchar2) return number is
val_ number;
begin
if str is null then
return null;
end if;
execute immediate 'begin :val_ := '||str||'; end;' using out val_;
return val_;
end;
/
,结果选择将是 -
with t as
(
select 1 as id, ' 20 * 4 ' as jancuk from dual union all
select 2 as id, ' 2 + 4 ' as jancuk from dual union all
select 3 as id, ' 3 - 1 + 2 ' as jancuk from dual union all
select 4 as id, ' 20 / 5 ' as jancuk from dual
)
select id, jancuk, calc_value(jancuk) as pijut
from t
答案 1 :(得分:2)
尝试:
update tbl
set "pijut" = xmlquery(replace( "jancuk", '/', ' div ' ) returning content ).getNumberVal();
了解更多信息link