各位大神,请教个oracle中functions 的问题。在线等。。。。。。。。。。。。。
SELECT b.REP_BUS,sum(a.SL) AS SL,sum(a.HSCB) AS HSCB,sum(a.XSJE) AS XSJE FROM XS_SELGDS a,BA_WHBASE b
WHERE a.SOUR='E' AND substr(a.TJLB,1,2)='01' AND a.RQ>'20130725' AND a.RQ<='20130825' AND a.BZ1=b.REP_BM
and b.visible in('N','Y')
GROUP BY b.REP_BUS;
这个语句执行没问题,然后我就想写个函数返回('N','Y') 这段话,如下:
create or replace function f_get return varchar2 is
Result varchar2(100);
begin
result := '(N,Y)';
return(Result);
end f_get;
减了这个函数。在执行语句
SELECT b.REP_BUS,sum(a.SL) AS SL,sum(a.HSCB) AS HSCB,sum(a.XSJE) AS XSJE FROM XS_SELGDS a,BA_WHBASE b
WHERE a.SOUR='E' AND substr(a.TJLB,1,2)='01' AND a.RQ>'20130725' AND a.RQ<='20130825' AND a.BZ1=b.REP_BM
and b.visible in f_get
GROUP BY b.REP_BUS;
这句话能执行,但无结果集。
请大神们看看问题出在哪?
------解决方案--------------------首先你的函数里面的括号是全角中文的!
另外select查询语句里面 and b.visible in('N','Y')
中的 ('N','Y') 不可以简单的当做字符串处理;
如果必须有这样需求的话,得考虑使用 动态sql,那是另外一套pl/sql的技巧了!
------解决方案--------------------补充一下,如果不用in条件,而是=条件的话,你的思路是木有问题的,举例如下:
SELECT 。。。from
WHERE 。。。
and b.visible = 'N'
GROUP BY b.REP_BUS;
create or replace function f_get return varchar2 is
Result varchar2(100);
begin
result := 'N';
return(Result);
end f_get;
/
SELECT 。。。from
WHERE 。。。
and b.visible = f_get
GROUP BY b.REP_BUS;
------解决方案--------------------