急求存储过程是否需要使用游标请各位大大自己定夺

Neo_whl 2018-05-20 05:26:55
场景:
一张表里大体可以认为为客户评价反馈表:
现在需要


select t.rating_wid,t.created_on_dt,t.feedback,t.replyer,t.reason,t.responsible,t.solution from
(
select
nf.rating_wid, --每个客户评价都会对应一个rating_wid,但有可能评价多次就可能出现多条记录,每条记录的rating_wid相同
nf.feedback_dt, -- 反馈时间
nf.feedback, --客户的反馈详细描述
nf.replyer, --跟进人
nf.reason, --差评原因
nf.responsible, --责任归属
nf.solution from Nx_Order_Rating_Feedback_f nf --责任归属
group by nf.rating_wid,nf.created_on_dt,nf.feedback,nf.replyer,nf.reason,nf.responsible,nf.solution
order by nf.created_on_dt desc)t


--现在需求是根据rating_wid分组取每组里feedback_dt字段时间记录值最近的一条,感觉sqlserver写起来不难,对oracel存储过程和语法不太熟悉,所以求教各位大神,不吝赐教!
...全文
1565 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuyu1980 2018-05-22
  • 打赏
  • 举报
回复
如果要最新的order by那应该加上 desc
yuyu1980 2018-05-22
  • 打赏
  • 举报
回复
select * from (select t.rating_wid,t.created_on_dt,t.feedback,t.replyer,t.reason,t.responsible,t.solutionrow_number() over(partition by t.rating_wid order by t.feedback) rn from  (……)) where rn=1 看一下是不是你想要的,partition (分区)可能写的不对,自己查一下。
卖水果的net 2018-05-21
  • 打赏
  • 举报
回复
s out sys_refcursor 是一个输出参数 open s for select ,这 这里写上你的 select 语句就可以了。
Neo_whl 2018-05-20
  • 打赏
  • 举报
回复
引用
-- 大概就是这个样子。 create procedure sp1(s out sys_refcursor) as begin open s for select * from t where ....; end;
s out sys_refcursor? 是定义一个输出参数游标还是啥? open s for 是打开游标后面select是作为数源么?

   CREATE OR REPLACE PROCEDURE 存储过程名字
IS
BEGIN
select t.rating_wid,t.created_on_dt,t.feedback,t.replyer,t.reason,t.responsible,t.solution from 
(
select nf.rating_wid,nf.created_on_dt,nf.feedback,nf.replyer,nf.reason,nf.responsible,nf.solution,
ROW_NUMBER() OVER(PARTITION BY nf.rating_wid  ORDER BYnf.created_on_dt desc) AS code_id
 from Nx_Order_Rating_Feedback_f nf)t
 where t.code_id=1
 EXCEPTION
--异常处理语句段
WHEN NO_DATA_FOUND THEN dbms_output.put_line('NO_DATA_FOUND');
 END 存储过程名字
--电脑没有oracle开发环境,楼主帮 我看看能调试下没有语法错误不,拜谢
卖水果的net 2018-05-20
  • 打赏
  • 举报
回复
-- 大概就是这个样子。 create procedure sp1(s out sys_refcursor) as begin open s for select * from t where ....; end;

17,140

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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