After reading a large number of paging stored procedures, I found that SQL Server is targeted, but oracle is not. Therefore, I want to write a stored procedure about Oracle, because the database I use is Oracle. Bytes --------------------------------------------------------------------------------------- The idea of Oracle paging stored procedures is the same as that of SQL Server, but I have made some changes here because of the differences in Oracle syntax and rules, the Oracle paging Stored Procedure looks a little different. Smile! Cursor variables are required to return record sets during Oracle storage. Oracle cannot directly return a record set as SQL Server does. Because it is assumed that complicated SQL statements are generated in. net, the problem of generating SQL statements is not considered in the stored procedure. Bytes ----------------------------------------------------------------------------------- The following is a paging stored procedure in Oracle. Create or replace package DOTNET is
Type type_cur is ref cursor; -- defines the cursor variable used to return the record set
Procedure dotnetpagination ( Pindex in number, -- paging Index Psql in varchar2, -- SQL statement that generates Dataset Psize in number, -- page size Pcount out number, -- total number of returned pages V_cur out type_cur -- returns the current page data record );
Procedure dotnetpagerecordscount ( Psqlcount in varchar2, -- generate the dataset SQL statement Prcount out number -- total number of returned records );
End dotnot; ------------------------------------------------------------------------------- Create or replace package body DOTNET is --*************************************** **************************************** ******** Procedure dotnetpagination ( Pindex in number, Psql in varchar2, Psize in number, Pcount out number, V_cur out type_cur ) As V_ SQL varchar2 (1000 ); V_count number; V_plow number; V_phei number; Begin ------------------------------------------------------------ Retrieve the total number of pages V_ SQL: = 'select count (*) from ('| Psql | ')'; Execute immediate v_ SQL into v_count; Pcount: = Ceil (v_count/psize ); -------------------------------------------------------------- Display any page content V_phei: = pindex * psize + psize; V_plow: = v_phei-psize + 1; -- Psql: = 'select rownum RN, T. * From cd_ssxl T'; -- The rownum field must be included. V_ SQL: = 'select * from ('| Psql |') Where rn between' | v_plow | 'and' | v_phei; Open v_cur for v_ SQL;
End dotnetpagination; --*************************************** **************************************** ******* Procedure dotnetpagerecordscount ( Psqlcount in varchar2, Prcount out number ) As
V_ SQL varchar2 (1000 ); V_prcount number;
Begin
V_ SQL: = 'select count (*) from ('| psqlcount | ')'; Execute immediate v_ SQL into v_prcount; Prcount: = v_prcount; -- total number of returned records
End dotnetpagerecordscount;
--*************************************** **************************************** ******* End dotnot; Bytes ------------------------------------------------------------------------------------------ The following describes how to call the Oracle paging stored procedure in. net. (VB.net) Datareader is required to call the stored procedure of the returned record set in. net. However, datareader does not support paging in the DataGrid. Therefore, you must use the DataGrid custom paging function. Protected withevents datagrid1 as system. Web. UI. webcontrols. DataGrid Dim conn as new oracleclient. oracleconnection () Dim cmd as new oracleclient. oraclecommand () Dim Dr as oracleclient. oracledatareader Private sub gridbind (byval pindex as integer, byval Psql as string, optional byval psize as integer = 10) Conn. connectionstring = "Password = gzdlgis; user id = gzdlgis; Data Source = gzgis" Cmd. Connection = Conn Cmd. commandtype = commandtype. storedprocedure Conn. open () 'Timeout '------------------------------------------------------------------------------------ Cmd. commandtext = "dotnot. dotnetpagerecordscount" 'Timeout '------------------------------------------------------------------------------------ Cmd. Parameters. Add ("psqlcount", oracletype. varchar). value = Psql Cmd. Parameters. Add ("prcount", oracletype. Number). Direction = parameterdirection. Output Cmd. executenonquery () Me. datagrid1.allowpaging = true Me. datagrid1.allowcustompaging = true Me. datagrid1.pagesize = psize Me. datagrid1.virtualitemcount = cmd. parameters ("prcount"). Value Cmd. Parameters. Clear () 'Timeout '------------------------------------------------------------------------------------ Cmd. commandtext = "dotnot. dotnetpagination" 'Timeout '------------------------------------------------------------------------------------ Cmd. Parameters. Add ("pindex", Data. oracleclient. oracletype. Number). value = pindex Cmd. Parameters. Add ("Psql", Data. oracleclient. oracletype. varchar). value = Psql '"select rownum RN, T. * From cd_ssxl t" Cmd. Parameters. Add ("psize", Data. oracleclient. oracletype. Number). value = psize Cmd. Parameters. Add ("v_cur", Data. oracleclient. oracletype. cursor). Direction = parameterdirection. Output Cmd. Parameters. Add ("pcount", Data. oracleclient. oracletype. Number). Direction = parameterdirection. Output Dr = cmd. executereader () Me. datagrid1.datasource = Dr Me. datagrid1.databind () Dr. Close () Conn. Close () Response. Write ("Total pages" & cmd. parameters ("pcount"). value) End sub Bytes ---------------------------------------------------------------------------------------- Private sub page_load (byval sender as system. Object, byval e as system. eventargs) handles mybase. Load If not page. ispostback then Dim Psql as string = "select rownum RN, T. * From cd_ssxl t" Gridbind (0, Psql, 20)
End if End sub Bytes --------------------------------------------------------------------------------------- Private sub maid (byval source as object, byval e as system. Web. UI. webcontrols. datagridpagechangedeventargs) handles maid Dim Psql as string = "select rownum RN, T. * From cd_ssxl t" Me. Maid = E. newpageindex Gridbind (E. newpageindex, Psql, 20) End sub |