我在function里建立了:
create or replace function GetUserName(Myuser_account varchar2) return varchar2 is
Result varchar2(50);
begin
declare cursor MyCursor is select distinct user_name from tbs_user where user_account =Myuser_account ;
begin
open MyCursor;
fetch MyCursor into Result;
close MyCursor;
end;
return(Result);
end GetUserName;
然后再试图里面调用
create or replace view view_tbp_failureupgrade as
select
t1.SQDWBM,t1.SQRQ,t1.XTBM,t1.LLDBH,t1.GDBH,t1.KF_GZXX,t1.KF_DJRBM,t1.WH1_CLNR,t1.WH1_RYBM,t1.WH1_RYBZBM,t1.WH2_CLNR,t1.WH2_RYBM,t1.WH2_RYBZBM,t1.WH3_CLNR,t1.WH3_RYBM,····
GetUserName(KF_DJRbm) as KF_DJRMC,
GetUserName(WH1_RYbm) as WH1_RYMC,
GetUserName(WH2_RYbm) as WH2_RYMC,
GetUserName(WH3_RYbm) as WH3_RYMC,
GetUserName(KF_HFRbm) as KF_HFRMC,
GetUserName(WH1_JG_DJRYbm) as WH1_JG_DJRYMC,
From TBP_FAILUREUPGRADE t1
他返回放的结果又很多行啊 ,怎么让他就返回table里面对应的一行?
为什么他会有那么多重复的行???
------解决方案--------------------
你的函数返回结果只能是一行数据,不能是多行数据,否则就报错
可以用rownum =1, 将你的函数只返回一行数据
------解决方案--------------------
函数返回一个值没问题
创建视图的语句可以使用rownum或distinct来限制返回行数