我有写一个存储过程,要求传的参数是两张输入表的名字,一个输出表的名字,
两张输入表的字段,输出表的字段,根据输入表内的字段进行处理,将内容输出到输出表中,这样的需求,能存储过程写吗?

A表 
 a  b 
 1  10
 2  20
 3  30
B表
 a  b 
 1  10
 2  20
 3  30
C表
 a  b 
 1  20
 2  40
 3  60这里A B 为输入表,C为输出表,这些都要做为参数传入,这个加法的动作,也要通过参数传入。请大家指点.

解决方案 »

  1.   

    insert into c select t1.a,t1.b+t2.b from a t1,b t2 where t1.a=t2.a;
      

  2.   

    create or replace procedure p(a in varchar2,b varchar2,c in varchar2)
    as
    begin
         execute immediate 'insert into '||c||' select t1.a,t1.b+t2.b b from '||a||' t1,'||b||' t2 where t1.a=t2.a'; 
    end;
      

  3.   

    SQL> ed
    已写入 file afiedt.buf  1  create or replace procedure insertPro(tab1 in varchar2,tab2 in varchar2,opera in varchar2)
      2  as
      3  strsql varchar2(100);
      4  begin
      5  execute immediate 'truncate table c';
      6  strsql:='insert into c select t1.a,t1.b'||opera||'t2.b from ';
      7  strsql:=strsql||tab1||' t1,'||tab2||' t2 where t1.a=t2.a';
      8  execute immediate strsql;
      9* end;
    SQL> /过程已创建。SQL> exec insertPro('a','b','+');PL/SQL 过程已成功完成。SQL> select * from c;         A          B
    ---------- ----------
             1         20
             2         40
             3         60SQL> exec insertPro('a','b','-');PL/SQL 过程已成功完成。SQL> select * from c;         A          B
    ---------- ----------
             1          0
             2          0
             3          0SQL> exec insertPro('a','b','*');PL/SQL 过程已成功完成。SQL> select * from c;         A          B
    ---------- ----------
             1        100
             2        400
             3        900
      

  4.   

    --要是三表的字段类型一样的还好
    --insert into tb3 select t.a,t.b &oprea k.b from tb1 t,tb2 k where t.a=k.aSQL> create table tb1 as with tb as(select 1 a,10 b from dual union all
      2  select 2,20 from dual union all
      3  select 3,30 from dual) select * from tb
      4  /表已创建。
    SQL> create table tb2 as with tb as(select 1 a,10 b from dual union all
      2  select 2,20 from dual union all
      3  select 3,30 from dual) select * from tb
      4  /表已创建。SQL> create table tb3 as select * from tb1 where 1<>1
      2  /表已创建。SQL> create or replace procedure p_tb3_sum(v_tb1 varchar2,v_tb2 varchar2,v_tb3 varchar2,oprea varchar2)
      2  as
      3  begin
      4  execute immediate 'insert into '||v_tb3||'  select k.a,k.b'||oprea||'t.b from  '||v_tb1||' k,'||v_tb2||' t '||' where k.a=t.a';
      5  commit;
      6  end;
      7  /过程已创建。SQL> exec p_tb3_sum('tb1','tb2','tb3','+')PL/SQL 过程已成功完成。SQL> select * from tb3
      2  /         A          B
    ---------- ----------
             1         20
             2         40
             3         60
      

  5.   

    楼上都很正确,但是这个只是完成了一个简单的需求,我现在的问题是,通过A,B表,生成C表数据的各字段都不确定,要通过参数传递,
    这时就有麻烦了,如果能将用户填写的字段集传入处理,如果有类似数组类型的
    参数就行了。。