orecle select function 不是group by 表达式

longdpt922 2013-12-18 11:07:52
select a.goodsid,
b.goodsname,
b.goodsspec,
b.unitname,
a.materialid,
c.goodsname as mgoodsname,
qty,
tl_recipecost(a.goodsid ,1) as cost1,
a.qty1,
tl_recipecost(a.goodsid ,2) as cost2,
a.qty2,
tl_recipecost(a.goodsid ,3) as cost3,
a.qty3,
tl_recipecost(a.goodsid ,4) as cost4
from recipe a, goods b, goods c
where a.goodsid = b.goodsid
and a.materialid = c.goodsid


create or replace function tl_recipecost
(
I_goodsid in int,
I_type in varchar2
)
return varchar2
--------------------------------------------

--------------------------------------------
as
v_caseno varchar2(64);
v_count int;
o_cost number(10,6);
begin


o_cost:=0;


if(I_type =1 )then

For R in
(
select min(a.cost) AS COST, b.materialid ,b.qty ,b.goodsid
from goodsshop a ,recipe b where a.goodsid = b.materialid and b.goodsid = i_goodsid
group by b.materialid ,b.qty ,b.goodsid
)
loop
o_cost := o_cost+ R.COST*b.qty;

end loop ;


elsif (I_type =2 )then
For R in
(
select min(a.cost) AS COST, b.materialid ,b.qty1 ,b.goodsid
from goodsshop a ,recipe b where a.goodsid = b.materialid and b.goodsid = i_goodsid
group by b.materialid ,b.qty ,b.goodsid
)
loop
o_cost := o_cost+ R.COST*b.qty1;

end loop ;
elsif (I_type =3 )then
For R in
(
select min(a.cost) AS COST, b.materialid ,b.qty2 ,b.goodsid
from goodsshop a ,recipe b where a.goodsid = b.materialid and b.goodsid = i_goodsid
group by b.materialid ,b.qty ,b.goodsid
)
loop
o_cost := o_cost+ R.COST*b.qty2;

end loop ;
elsif (I_type =4 )then
For R in
(
select min(a.cost) AS COST, b.materialid ,b.qty3 ,b.goodsid
from goodsshop a ,recipe b where a.goodsid = b.materialid and b.goodsid = i_goodsid
group by b.materialid ,b.qty ,b.goodsid
)
loop
o_cost := o_cost+ R.COST*b.qty3;

end loop ;
end if;



v_caseno:=to_char(o_cost);
return o_cost;
end ;

执行提示不是group by表达式??为啥?该怎么改?
...全文
173 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
_拙计 2013-12-23
  • 打赏
  • 举报
回复
你group by的和你select的 字段不统一 like #1
CT_LXL 2013-12-18
  • 打赏
  • 举报
回复
用了聚合函数需用GROUP BY,#1 +1
  • 打赏
  • 举报
回复
你判断I_type 是否等于2,3,4里面 select min(a.cost) AS COST, b.materialid ,b.qty1 ,b.goodsid from goodsshop a ,recipe b where a.goodsid = b.materialid and b.goodsid = i_goodsid group by b.materialid ,b.qty ,b.goodsid I_type =3和I_type =4里面类似错误

684

社区成员

发帖
与我相关
我的任务
社区描述
智能路由器通常具有独立的操作系统,包括OpenWRT、eCos、VxWorks等,可以由用户自行安装各种应用,实现网络和设备的智能化管理。
linuxpython 技术论坛(原bbs)
社区管理员
  • 智能路由器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧