公式样例:
A059.G05919 := G007.G00703 + G008.G00704 +100.43
像A059 和G007 G008这是数据库的表名。
而表名后面是字段名。
现在需要写一个从出过程来实现这个公式。把右面执行的结果更新到左边的字段中。
因为初学存储过程,觉得很难。不知道大哥哥大姐姐们谁能帮帮忙。
A059.G05919 := G007.G00703 + G008.G00704 +100.43
像A059 和G007 G008这是数据库的表名。
而表名后面是字段名。
现在需要写一个从出过程来实现这个公式。把右面执行的结果更新到左边的字段中。
因为初学存储过程,觉得很难。不知道大哥哥大姐姐们谁能帮帮忙。
你这三个表A059 和G007 G008按什么字段去关联?
把简单的数据帖出来,应该用一条SQL就可以解决了.
i int;
begin
execute immediate 'select 1+1 from dual'
into i;
dbms_output.put_line(i);
end;可以输出2
如果不太难的话,不一定要用存储过程
用SQL直接解决!
G007.G00703 + G008.G00704 +100.43
from G007,G008 where G007.g00700 =G008.g00800 and A059.a05900 = G007.g00700)
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)
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)
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)
需要在oracle中把表达式进行分解。
create or replace procedure test100(gongshi in varchar2)
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个表。
调用call test100('G007.G00703 + G008.G00704 +100.43' )
http://topic.csdn.net/u/20081217/14/3d894130-a4ed-4bb4-aef3-dcac7db4a4bd.htmlselect REGEXP_SUBSTR(f,'[A-Z][0-9]+')as f1,REGEXP_SUBSTR(f,'[^.][A-Z][0-9]+') as f2,f from(
select 'A059.G05919 := G007.G00703 ' as f from dual) /*
F1 F2 F
A059 G007 A059.G05919 := G007.G00703
*/
A059.G05937 := A059.G05937 +(A059.G05902 + A059.A05903+A059.G05936) * 0.4 / 21.75 * A059.G05925 ENDIF
假如遇到这样的公式呢!
你不觉得这样设计的系统很难使用么。是不是让用户去写if else?
as
strsql varchar2(4000);begin
strsql:='update A059
set G05919 = (select '||gongshi||' from G007,G008,A059
where A059.a05900 = G007.g00700
and A059.a05900 = G008.g00800)
where exists (select 1
from G007,G008,A059
where A059.a05900 = G007.g00700
and A059.a05900 = G008.g00800)';
execute immediate strsql;
commit;
end;
调用的方式,即传入的参数变一下call test100(case when A058.E05805 / 7 < 2 AND A058.G05812 = 0
then A059.G05937 +(A059.G05902 + A059.A05903+A059.G05936) * 0.4 / 21.75 * A059.G05925 else A059.G05919 END ')
as
strsql varchar2(4000);begin
strsql:='update '||tablename||
' set '||fieldname||' = (select '||gongshi||' from G007,G008,A059
where A059.a05900 = G007.g00700
and A059.a05900 = G008.g00800)
where exists (select 1
from G007,G008,A059
where A059.a05900 = G007.g00700
and A059.a05900 = G008.g00800)';
execute immediate strsql;
commit;
end;
CREATE OR REPLACE FUNCTION F_test(V_a IN NUMBER,
V_b IN NUMBER
) RETURN VARCHAR2 IS
V_c NUMBER(9, 5);BEGIN
--这里面写上你的公式,如果需要逻辑判断的话,就加上if else或者case when 等判断结构
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;
return A059.G05937 := A059.G05937 +(A059.G05902 + A059.A05903+A059.G05936) * 0.4 / 21.75 * A059.G05925
来返回值