|
最初由 冷月宫主 发布
[B]create or replace procedure P_QUERY_RESULT_BY_PAGE3(p_PageSize int, --每页记录数
p_PageNo int, --当前页码,从 1 开始
p_SqlSelect varchar2, --查询语句,含排序部分
p_OutCursor out sys_refcursor)
as
v_sql varchar2(3000);
--v_count int;
v_heiRownum int;
v_lowRownum int;
begin
/*
----取记录总数
v_sql := 'select count(*) from (' || p_SqlSelect || ')';
execute immediate v_sql into v_count;
p_OutRecordCount := v_count;
*/
----执行分页查询
v_heiRownum := p_PageNo * p_PageSize;
v_lowRownum := v_heiRownum - p_PageSize + 1;
v_sql := 'SELECT *
FROM (
SELECT A.*, rownum rn
FROM ('|| p_SqlSelect ||') A
WHERE rownum <= '|| to_char(v_heiRownum) || '
) B
WHERE rn >= ' || to_char(v_lowRownum) ;
--注意对rownum别名的使用,第一次直接用rownum,第二次一定要用别名rn
OPEN p_OutCursor FOR v_sql;
end P_QUERY_RESULT_BY_PAGE3; [/B]
要注意绑定变量的使用!
create or replace package pkg_rome_online_times as
--************************************************
-- ** Get connect time information of site.
-- ** In parameters: S_RQ
-- ** In parameters: E_RQ
-- ** In parameters: RDC_ID
-- ** In parameters: BRANCH_ID
-- ** In parameters: SITE_NO
-- ** In parameters: PAGE_NO
-- ** Returns:Ref Cursor
-- ** p_online_times_site:Ref Cursor(rq,weight)
-- ** p_online_times_branch:Ref Cursor(site_no,weight)
-- ** p_online_times_rdc:Ref Cursor(site_no,weight)
-- ************************************************
type t_ref is ref cursor;
procedure p_online_times_site(s_rq in date,e_rq in date,rdcid in varchar2,siteno in varchar2,page_no in number,num out number,cur_ref out t_ref);
procedure p_online_times_branch(s_rq in date,e_rq in date,rdcid in varchar2,branchid in varchar2,page_no in number,num out number,weight out varchar2,cur_ref out t_ref);
procedure p_online_times_rdc(s_rq in date,e_rq in date,rdcid in varchar2,page_no in number,weight out varchar2,cur_ref out t_ref);
end pkg_rome_online_times;
/
create or replace package body pkg_rome_online_times as
procedure p_online_times_site(s_rq in date,e_rq in date,rdcid in varchar2,siteno in varchar2,page_no in number,num out number,cur_ref out t_ref) is
begin
if page_no is null or page_no<0 then
return;
end if;
select count(*) into num from site_connect_summary
where rq >= s_rq
and rq <= e_rq
and rdc_id = rdcid
and site_no = siteno;
if page_no = 0 then
open cur_ref for 'select to_char(rq,''yyyy-mm-dd'') rq,trunc(weight/60)||''小时''||lpad(mod(weight,60),2,''0'')||''分'' weight
from site_connect_summary
where rq >= :s_rq
and rq <= :e_rq
and rdc_id = :rdcid
and site_no = :siteno
order by rq' using s_rq,e_rq,rdcid,siteno;
else
open cur_ref for 'select /*+ FIRST_ROWS */ to_char(rq,''yyyy-mm-dd'') rq,trunc(weight/60)||''小时''||lpad(mod(weight,60),2,''0'')||''分'' weight
from (select rownum rn,rq,weight from (select rq,weight from site_connect_summary
where rq >= :s_rq
and rq <= :e_rq
and rdc_id = :rdc_id
and site_no = :site_no
order by rq)
where rownum <= :row_e)
where rn >= :row_s'
using s_rq,e_rq,rdcid,siteno,page_no*fn_get_system_config('ROWS_PER_PAGE'),(page_no - 1)*fn_get_system_config('ROWS_PER_PAGE')+1;
end if;
exception when others then
null;
end p_online_times_site;
procedure p_online_times_branch(s_rq in date,e_rq in date,rdcid in varchar2,branchid in varchar2,page_no in number,num out number,weight out varchar2,cur_ref out t_ref) is
begin
if page_no is null or page_no<0 then
return;
end if;
select count(distinct a.site_no),trunc(sum(a.weight)/60)||'小时'||lpad(mod(sum(a.weight),60),2,'0')||'分' into num,weight
from site_connect_summary a,site b
where a.rq >= s_rq
and a.rq <= e_rq
and a.rdc_id = rdcid
and a.rdc_id = b.rdc_id
and a.site_no = b.site_no
and b.branch_id = branchid;
if page_no = 0 then
open cur_ref for 'select a.site_no site_no,trunc(sum(a.weight)/60)||''小时''||lpad(mod(sum(a.weight),60),2,''0'')||''分'' weight
from site_connect_summary a,site b
where a.rq >= :s_rq
and a.rq <= :e_rq
and a.rdc_id = :rdcid
and a.rdc_id = b.rdc_id
and a.site_no = b.site_no
and b.branch_id = :branchid
group by a.site_no
order by a.site_no' using s_rq,e_rq,rdcid,branchid;
else
open cur_ref for 'select /*+ FIRST_ROWS */ site_no,trunc(weight/60)||''小时''||lpad(mod(weight,60),2,''0'')||''分'' weight
from(select rownum rn,site_no,weight from(select a.site_no,sum(a.weight) weight from site_connect_summary a,site b
where a.rq >= :s_rq
and a.rq <= :e_rq
and a.rdc_id = :rdcid
and a.rdc_id = b.rdc_id
and a.site_no = b.site_no
and b.branch_id = :branchid
group by a.site_no
order by a.site_no)
where rownum <= :row_e)
where rn >= :row_s'
using s_rq,e_rq,rdcid,branchid,page_no*fn_get_system_config('ROWS_PER_PAGE'),(page_no - 1)*fn_get_system_config('ROWS_PER_PAGE')+1;
end if;
exception when others then
null;
end p_online_times_branch;
procedure p_online_times_rdc(s_rq in date,e_rq in date,rdcid in varchar2,page_no in number,weight out varchar2,cur_ref out t_ref) is
begin
select trunc(sum(weight)/60)||'小时'||lpad(mod(sum(weight),60),2,'0')||'分' into weight
from site_connect_summary a,site b,branch c
where a.rq >= s_rq
and a.rq <= e_rq
and a.rdc_id = rdcid
and a.rdc_id = b.rdc_id
and a.site_no = b.site_no
and b.branch_id = c.branch_id;
open cur_ref for 'select b.branch_id,c.branch_no,c.branch_name,trunc(sum(weight)/60)||''小时''||lpad(mod(sum(weight),60),2,''0'')||''分'' weight
from site_connect_summary a,site b,branch c
where a.rq >= :s_rq
and a.rq <= :e_rq
and a.rdc_id = :rdcid
and a.rdc_id = b.rdc_id
and a.site_no = b.site_no
and b.branch_id = c.branch_id
group by b.branch_id,c.branch_no,c.branch_name
order by c.branch_no' using s_rq,e_rq,rdcid;
--if page_no = 0 then
-- open cur_ref for 'select site_no,trunc(sum(weight)/60)||''小时''||lpad(mod(sum(weight),60),2,''0'')||''分'' weight
-- from site_connect_summary
-- where rq >= :s_rq
-- and rq <= :e_rq
-- and rdc_id = :rdc_id
-- group by site_no
-- order by site_no' using s_rq,e_rq,rdc_id;
--else
-- open cur_ref for 'select /*+ FIRST_ROWS */ site_no,trunc(weight/60)||''小时''||lpad(mod(weight,60),2,''0'')||''分'' weight
-- from(select rownum rn,site_no,weight from(select site_no,sum(weight) weight from site_connect_summary
-- where rq >= :s_rq
-- and rq <= :e_rq
-- and rdc_id = :rdc_id
-- group by site_no
-- order by site_no)
-- where rownum <= :row_e)
-- where rn >= :row_s'
-- using s_rq,e_rq,rdc_id,page_no*fn_get_system_config('ROWS_PER_PAGE'),(page_no - 1)*fn_get_system_config('ROWS_PER_PAGE')+1;
--end if;
exception when others then
null;
end p_online_times_rdc;
end pkg_rome_online_times;
/ |
|