麻烦问一下各位 就是我写了一个存储过程
create or replace procedure pro_test(id_   in varchar2, 
                                     name_  out varchar2, 
                                     age_  out varchar2, 
                                     email_   out varchar2, 
                                     ) is
begin
      select a.name,a.age,a.email into name_,age_,email_ from AA a where id=id_;
      union
      select b.name,b.age,b.email into name_,age_,email_ from BB b where id=id_;      
      union
      select c.name,c.age,c.email into name_,age_,email_ from CC c where id=id_;
  end;
exception
  when others then
    rollback;
end pro_test;
就是有AA,BB,CC三张表 一个学生的id  有可能AA表有 也有可能BB表才有  我不知道这个学生的id 在哪张表里面 所以要放在三张表里面查  现在我执行这个存储过程的时候  报into有错  我想是不是不能重复的赋值给name_,age_,email_  麻烦问一下  这个要怎么写  才能把最后查出来的name,age,email赋值给name_,age_,email_   谢谢了

解决方案 »

  1.   

    过程中 不能 select 表的  只有插入 或者跟新之类的  不能查询 
      

  2.   

    可以select啊  只是select出来的值 into到参数里面  好像不对  是应该不能重复的赋值
    我写的那个付3次值了   不知道这个应该怎么写了
      

  3.   

    --用游标吧         create or replace procedure pro_test(id_ in varchar2,  
      name_ out varchar2,  
      age_ out varchar2,  
      email_ out varchar2,  
      ) is
    begin
      for cur in (
      select a.name,a.age,a.email  from AA a where id=id_;
      union
      select b.name,b.age,b.email  from BB b where id=id_;   
      union
      select c.name,c.age,c.email  from CC c where id=id_)   loop
      .......
      .......
      end loop;
      
      
      end;
    exception
      when others then
      rollback;
    end pro_test;
      

  4.   

    Oracle返回多条记录,还不如直接在程序里面做,将查询出来的结果集保存到数组中,再循环数组取数据
      

  5.   

     for cur in (
      select a.name,a.age,a.email from AA a where id=id_;
      union
      select b.name,b.age,b.email from BB b where id=id_;   
      union
      select c.name,c.age,c.email from CC c where id=id_) loop
      name_ := cur.name;
      age_  := cur.age;
      email_:= cur.email;    end loop;
      

  6.   

    但是你这个 我怎么保证cur.name去到的值呢?AA表里面 不叫那么name  叫mc比如  要是我 
      select a.mc,a.nl,a.dzyj from AA a where id=id_;
      union
      select b.name,b.age,b.email from BB b where id=id_;   
      union
      select c.name,c.age,c.email from CC c where id=id_;这种的话   name_ := cur.name;
      age_ := cur.age;
      email_:= cur.email; 这个好像就不对吧
      

  7.   

    主要是 我几张表 虽然都是去的这几个值  但是在几张表里面 名字不一样
    不如 有一张表叫name  有一张表的name是mc (名称)
    也就是说  AA表 列    mc(名称), nl(年龄),dzyj(电子邮件)
              BB表 列    name(名称),age(年龄),email(电子邮件)
              CC表 列    mc(名称), age(年龄),email(电子邮件)
    这种的话 实际我的查询写的是  select a.mc,a.nl,a.dzyj from AA a where id=id_;
      union
      select b.name,b.age,b.email from BB b where id=id_;   
      union
      select c.mc,c.age,c.email from CC c where id=id_;这种的话  name_ := cur.name;
      age_ := cur.age;
      email_:= cur.email; 这个好像就不对吧
      

  8.   

    而且我试了一下 没取到值 for cur in (
      select a.name,a.age,a.email from AA a where id=id_;
      union
      select b.name,b.age,b.email from BB b where id=id_;   
      union
      select c.name,c.age,c.email from CC c where id=id_) loop
      name_ := cur.name;
      age_ := cur.age;
      email_:= cur.email;     end loop;