--獲取資訊列表
procedure pro_get_article_list
(sidpara in cms_category.cat_sid%type,--欄目編號
usernamepara in varchar2,--當前使用者
currpagepara in number,--當前第幾頁
pagesizepara in number,--頁面大小
startindexpara in number,--獲取當前頁的記錄的開始下標,第一條為1
endindexpara in number,--獲取當前頁的記錄的結束下標
timescopepara in number,--獲取什麼時間以後的資料
userlevelpara in number,--使用者級別
artcountpara out number,--資訊總數量
pagecountpara out number, --總頁數
artlistpara out refcur)is
--定義當前頁展示資訊開始的索引值
vstartindex number(10,0);
vendindex number(10,0);
--定義資訊總數
vartcount number(10,0);
--定義是否按照最大許可權設定
vexists number(8);
vprivilege varchar2(5);
begin
--驗證使用者是否擁有所有資訊的瀏覽許可權
select count(*) into vexists
from cms_v_user_group
where username=usernamepara
and group_sid = leader_sid;
if vexists = 0 then
vprivilege := 'false';
else
vprivilege := 'true';
end if;
--驗證startindexpara引數與pagesizepara的關係
if pagesizepara < startindexpara then
vstartindex := 0;
else
vstartindex := startindexpara - 1;--vstartindex的正確初始值為0
end if;
--驗證endindexpara引數與pagesizepara的關係
if pagesizepara < endindexpara then
vendindex := pagesizepara;
else
vendindex := endindexpara;
end if;
--計算出當前頁展示資訊開始的索引值
vstartindex := (currpagepara-1) * pagesizepara + vstartindex;
--計算出當前頁展示資訊結束的索引值
vendindex := (currpagepara-1) * pagesizepara + vendindex;
--獲取資訊總數
if vprivilege = 'false' then
select
count(*) into vartcount
from cms_article t
where
exists(
select art_id from cms_art_scope t1,cms_v_user_group t2
where t2.group_sid like t1.art_role||'%'
and t.art_id = t1.art_id
and t2.username=usernamepara
)and t.art_deleted='false'
and t.art_audited='true'
and t.art_reader_level>=userlevelpara
and t.art_st_datesysdate
and t.cat_sid like sidpara||'%'
and t.art_updated > sysdate-timescopepara;
else
select
count(*) into vartcount
from cms_article t
where
t.art_deleted='false'
and t.art_audited='true'
and t.art_st_datesysdate
and t.cat_sid like sidpara||'%'
and t.art_updated > sysdate-timescopepara;
end if;
if vartcount = 0 then
artcountpara := 0;
pagecountpara := 0;
open artlistpara for
select * from cms_article
where art_id<0;
return;
end if;
artcountpara := vartcount;
--計算總頁數
if mod(vartcount,pagesizepara) = 0 then
pagecountpara := trunc(vartcount / pagesizepara);
else
pagecountpara := trunc(vartcount / pagesizepara) + 1;
end if;
if vprivilege = 'false' then
open artlistpara for
select
*from
(select
art_id,cat_sid,art_title,art_title_style,company,department,art_title_sign,to_char(art_st_date,'yyyy-mm-dd') as art_updated,art_url,rownum as r
from--獲取按順序的值
(select
art_id,cat_sid,art_title,art_title_style,company,department,art_title_sign, art_st_date,skin.skin_path||'showarticle.aspx?art_id='||art_id as art_url
from cms_article t,new_cms_skin skin
where
exists(
select art_id from cms_art_scope t1,cms_v_user_group t2
where t2.group_sid like t1.art_role||'%'
and t.art_id = t1.art_id
and t2.username=usernamepara
)and t.cat_sid like sidpara||'%'
and t.art_skin_id = skin.skin_id
and t.art_deleted='false'
and t.art_audited='true'
and t.art_reader_level>=userlevelpara
and t.art_st_datesysdate
and t.art_updated>sysdate-timescopepara
order by
art_topped desc,art_st_date desc,art_id desc))
where r>vstartindex and r < vendindex +1;
else
open artlistpara for
select
*from
(select
art_id,cat_sid,art_title,art_title_style,company,department,art_title_sign,to_char(art_st_date,'yyyy-mm-dd') as art_updated,art_url,rownum as r
from--獲取按順序的值
(select
art_id,cat_sid,art_title,art_title_style,company,department,art_title_sign, art_st_date,skin.skin_path||'showarticle.aspx?art_id='||art_id as art_url
from cms_article t,new_cms_skin skin
where
t.cat_sid like sidpara||'%'
and t.art_skin_id = skin.skin_id
and t.art_deleted='false'
and t.art_audited='true'
and t.art_st_datesysdate
and t.art_updated>sysdate-timescopepara
order by
art_topped desc,art_st_date desc,art_id desc))
where r>vstartindex and r < vendindex +1;
end if;
end pro_get_article_list;
Oracle中的分頁儲存過程
create or replace procedure proc selectall tablename in varchar2,要查詢的表名 pageno in number,當前頁數 pagesizes in number,沒有條數 pagecount out number 總頁數 listsi...
Oracle中的儲存過程(二)
一 儲存過程的引數 過程引數的三種模式 in預設的引數模式用於接受呼叫程式的值 out用於向呼叫程式返回值 in out 用於接受呼叫程式的值,並向呼叫程式返回更新的值 create or replace procedure findemp eno in number,ename out varch...
ORACLE中建儲存過程
建立測試表 create table xiaoyan id number primary key,username varchar2 24 age varchar2 3 address varchar2 1024 other varchar2 1024 comment on table xiaoya...