公式样例:
A059.G05919 := G007.G00703 + G008.G00704 +100.43
像A059 和G007 G008这是数据库的表名。
而表名后面是字段名。
现在需要写一个从出过程来实现这个公式。把右面执行的结果更新到左边的字段中。
因为初学存储过程,觉得很难。不知道大哥哥大姐姐们谁能帮帮忙。

解决方案 »

  1.   

    不用存储过程,一条语句就可以搞定
    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

      

  2.   

    declare
      i   int;
     begin
      execute immediate 'select 1+1 from dual'
        into i;
      dbms_output.put_line(i);
     end;可以输出2
      

  3.   

    我估计lz是把"A059.G05919 := G007.G00703 + G008.G00704 +100.43 "字符串保存在什么地方,然后需要解释这个公式来计算。对于解释型脚本语言,只要用动态执行就可以了。
      

  4.   

    是啊。。什么是动态sql语句呢!!
      

  5.   

    [code=SQL]update A059 set G05919=(select 
    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字符串
      

  6.   

    try itupdate A059
       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)
      

  7.   


    你到底想实现什么样的需求呢,我觉得没必要用动态SQL,除非你的字段统计是不确定的.
      

  8.   

    update A059
       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)
      

  9.   

    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个表。 
    调用 SQL code
    call test100('G007.G00703 + G008.G00704 +100.43' )
      

  10.   

    可以用一个函数实现,把你公式写好,如果有很多重复的可以重用;
    但是还是建议你把表之间的关联关系先搞清楚,这样才能用公式算出正确的需要要的结果;
    给一个简单的例子:
    --创建一个函数
    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;