存储过程

create or replace procedure getrenewbooks(rids in varchar2,uid in varchar2,rtnrids out varchar2) as
rtnbookids varchar2(500); --返回更新的图书
tmprid int; --临时变量 图书
tmpchid int; --临时变量 章节
tmporder int;
chapterid int;
corder int;
sqlstr varchar2(500);
type mycursor is ref cursor;
r_words mycursor;
begin
-- sqlstr := 'select r.resource_id, max(nvl(chapter_id, 0)) as chid from mass_resource_tmp r, mass_book_chapter c where r.resource_id in ('||rids|| ') and r.resource_id = c.resource_id(+) group by r.resource_id';
sqlstr := 'select o.resource_id,c.chapter_id as chid,c.chapter_order from (select r.resource_id, max(nvl(c.chapter_order, 0)) as chorder
from mass_resource_tmp r, mass_book_chapter c where r.resource_id in ('||rids|| ') and r.resource_id = c.resource_id(+) and chapter_isdelete=0
group by r.resource_id order by chorder desc) o,mass_book_chapter c where o.resource_id = c.resource_id(+) and o.chorder=c.chapter_order'; -- and chapter_isdelete=0
open r_words for sqlstr;
loop
fetch r_words into tmprid, tmpchid,tmporder;
--判断用户是否阅读到最后章节
select count(*) into chapterid from mass_app_afterbook where resource_id=tmprid and user_id=uid and ROWNUM=1 order by cdate desc;
EXIT WHEN r_words%NOTFOUND;
if chapterid>0 then
select b.cid,b.orderid into chapterid,corder from (select a.chapter_id as cid ,c.chapter_order as orderid from mass_app_afterbook a,mass_book_chapter c where a.resource_id=tmprid and a.user_id=uid
and a.chapter_id = c.chapter_id order by a.cdate desc) b where ROWNUM=1;
--阅读记录章节和这本书最大章节比较 order
if corder1 then
rtnbookids := substr(rtnbookids,0,length(rtnbookids)-1);
end if;
rtnrids:=rtnbookids;
--DBMS_OUTPUT.PUT_LINE('在RUNBYPARMETERS过程中出错!');
end;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值