--先建一函数
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
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
行号= 2 列号= 1 错误文本= PLS-00103: 出现符号 "CREATE"在需要下列之一时: ( return compress compiled wrapped还有,请问exit when c%notfound中的notfound是一个关键字还是什么?谢谢!
用show error命令看一下具体什么错误
贴出来
--把这里面的tableB换成你自己的B表的表名c%notfound是检测游标的是否到结尾的.
执行完你的脚本
执行show error;
select id,
max(decode(role,'管理员',role),
max(decode(role,'操作者',role),
max(decode(role,'用户',role)
from B
group by id然后用A和C组合查询
这个函数在建立的时候就包错了,根本调用不了!!!