oracle paging is a great sql statement

  • 2020-06-19 11:55:35
  • OfStack

CREATE OR REPLACE PROCEDURE PROC6338196642095312503719 (news content Varchar2 Varchar2 input news theme, input, input Varchar2 release time, enter the current page number Number, enter the number of rows per page Number, output the current page number OUT Number, output the number of lines of the headquarters of OUT Number, output page total pages OUT Number, whether the input on the next page Number, enter news number Varchar2,RETURN_CURSOR OUT ES21en.MYRCTYPE)
-- Function Description:
-- Author:
-- Date of Compilation:

If the result set is returned, the custom cursor Return_Cursor must be used
IS --OR AS

-- Variable definition area

v_cPageCount integer; -- The total number of rows of data to display
v_cPage integer; The current page of the data to be displayed

BEGIN

-- Stored procedure body
Enter the news number is null then
begin
-- Output total rows
select max(rownum) into
select * from xtnews where 1=1
Enter and null or (enter is not null and V_XWZT like '%'|| enter ||'%')
Enter is null or (enter is not and D_FBSJ = to_date(enter Release time,' ES89en-ES90en-ES91en '))
where is null or is not null and V_XWNR like '%'|| '%'

-- Output total pages
select ceil(output lines/input lines per page)
exception when no_data_found then
null;
end;
Calculate the total number of rows of data to be displayed when entering the current page number
Enter the current page number is not null then
- xia1 page
if enter whether next page = 1 then
-- Calculate the previous page of the acquired data
v_cPage := (enter current page + 1);
-- Last page
if v_cPage > Output total page then
v_cPage := Output total pages;
end if;
end if;
- shang1 page
if enter whether next page = 0 then
-- Calculate the previous page of the acquired data
v_cPage := (enter current page number -1);
-- Top 1 page
if v_cPage = 0 then
v_cPage := 1;
end if;
end if;
-- The total number of rows of data to display
v_cPageCount := v_cPage * Enter the number of lines per page;
end if;
end if;
-- Execute a query to get the data to display
begin
open return_cursor for
select nts.* from(
select nt.* from (
select rownum serial number,n.* from(
select * from(
select * from(
select
I_ID News number,
V_XWZT News topic,
V_XWNR News content,
D_FBSJ release time,
D_YXSJ effective time,
V_FBBM Publishing department
from xtnews
where 1=1 and enter is null or (enter es2220en not null and V '%'|| enter ||'%')
where is null or is not and '%'|| '%'
Enter where mm null or (enter is not and = to_date(enter 'ES248en-ES249en-ES250en '))
)n where is null or (Enter is not null and News number = Enter news number)
order by rownum
)nt where nt < = v_cPageCount order by Serial number desc
)nts where nts > (v_cPageCount- enter the number of lines per page)
exception when no_data_found then
null;
end;

Output the last computed current page number
Enter the news number is null and v_cPage not null then
Output current page number := v_cPage;
end if;

END;

Related articles: