--先建一函数
create or replace function test(p_id number) return varchar2 as
    v_temp varchar2(300);
    v_out varchar2(300);
    cursor c is select b.role from tableB b where b.id=p_id;
begin
    open c;    
    loop
         fetch c into v_temp;
         exit when c%notfound;
         v_out:=v_out||' '||v_temp ;
    end loop;
    close c;
    return v_out;
    exception 
        when others then 
            return '处理出错';    
end;
--查询
select a.id id,a.name name,test(a.id) role from tablea a

解决方案 »

  1.   

    创建函数的时候报错牙!!!
    行号= 2 列号= 1 错误文本= PLS-00103: 出现符号 "CREATE"在需要下列之一时:  ( return compress    compiled wrapped还有,请问exit when c%notfound中的notfound是一个关键字还是什么?谢谢!
      

  2.   

    函数看上去没什么问题
    用show error命令看一下具体什么错误
    贴出来
      

  3.   

    不好意思,我不止到怎么用show error命令,在哪里用!?
      

  4.   

    cursor c is select b.role from tableB b where b.id=p_id;
    --把这里面的tableB换成你自己的B表的表名c%notfound是检测游标的是否到结尾的.
      

  5.   

    在sql*plus里面
    执行完你的脚本
    执行show error;
      

  6.   

    建立视图C
    select id, 
           max(decode(role,'管理员',role),
           max(decode(role,'操作者',role),
           max(decode(role,'用户',role)
      from B
    group by id然后用A和C组合查询  
      

  7.   

    to bzszp(www.bzszp.533.net):
    这个函数在建立的时候就包错了,根本调用不了!!!