公式样例:
A059.G05919 := G007.G00703 + G008.G00704 +100.43
像A059 和G007 G008这是数据库的表名。
而表名后面是字段名。
现在需要写一个从出过程来实现这个公式。把右面执行的结果更新到左边的字段中。
因为初学存储过程,觉得很难。不知道大哥哥大姐姐们谁能帮帮忙。
A059.G05919 := G007.G00703 + G008.G00704 +100.43
像A059 和G007 G008这是数据库的表名。
而表名后面是字段名。
现在需要写一个从出过程来实现这个公式。把右面执行的结果更新到左边的字段中。
因为初学存储过程,觉得很难。不知道大哥哥大姐姐们谁能帮帮忙。
update A059 set A059.G05919 = G007.G00703 + G008.G00704 +100.43
where exists (
select * from G007,G008
where A059.id=G007.id and G007.id=G008.id
)
i int;
begin
execute immediate 'select 1+1 from dual'
into i;
dbms_output.put_line(i);
end;可以输出2
G007.G00703 + G008.G00704 +100.43
from G007,G008 where G007.g00700 =G008.g00800 and A059.a05900 = G007.g00700)[/code]动态sql语句就是象5楼代码那样用execute immediate来动态执行一条sql字符串
set G05919 = (select G00703 from G007 where A059.a05900 = G007.g00700) +
(select G00704 from G008 where A059.a05900 = G008.g00800) +
100.43
where exists (select G00703 from G007 where A059.a05900 = G007.g00700)
and exists
(select G00704 from G008 where A059.a05900 = G008.g00800)
你到底想实现什么样的需求呢,我觉得没必要用动态SQL,除非你的字段统计是不确定的.
set G05919 = (select G00703 + G00704 + 100.43
from G007
where A059.a05900 = G007.g00700
and A059.a05900 = G008.g00800) where exists (select 1
from G007
where A059.a05900 = G007.g00700
and A059.a05900 = G008.g00800)
as
strsql varchar2(4000);begin
strsql:='update A059
set G05919 = (select '||gongshi||' from G007,G008
where A059.a05900 = G007.g00700
and A059.a05900 = G008.g00800)
where exists (select 1
from G007,G008
where A059.a05900 = G007.g00700
and A059.a05900 = G008.g00800)';
execute immediate strsql;
commit;
end;
这个过程只针对A059的G05919 字段和G007及G0082个表。
调用 SQL code
call test100('G007.G00703 + G008.G00704 +100.43' )
但是还是建议你把表之间的关联关系先搞清楚,这样才能用公式算出正确的需要要的结果;
给一个简单的例子:
--创建一个函数
CREATE OR REPLACE FUNCTION F_test(V_a IN NUMBER,
V_b IN NUMBER
) RETURN VARCHAR2 IS
V_c NUMBER(9, 5);BEGIN
V_c:=V_a+V_b_xxx;
RETURN(V_c);
END F_test;--调用这个函数
insert into table_a
select F_test(table_b.col1,table_c.col2)
from table_b ,table_c
where table_b.colx=table_c.colx;
commit;