Comparison of stored procedures for returned datasets ..........

Source: Internet
Author: User

In SQL Server2000, if a stored procedure has a separate SQL statement, use C # To Call The Stored Procedure and use the adapter fill dataset (Dataset) the number of tables in the dataset exactly corresponds to the number of SQL statements that run separately in the stored procedure.
Create procedure jisentest
@ Qwtgw varchar (16 ),
@ AAA int,
@ ABC varchar (16) Out
As

Delete distest where [name] = @ qwtgw;
Set @ abc = '20140901 ';
Select * From distest;
Select * From distest;
Select * From distest;
Return 1;
Go
C # after this stored procedure is called, there will be 3 datatable data sets in the dataset
In Oracle, it is not that simple to return a dataset. After finding the data, it seems that only the cursor can be used to return the dataset. (currently, I do not know how to output multiple cursors in a stored procedure .)
Create a package declaration first. In the package declaration
Create or replace package jisen. Test
Is
Type cur_type is ref cursor;
Procedure pageprocedure (
Sqltext in varchar2,
Pagecount in number,
Pagenumber in number,
Sqlcondition in varchar2,
Icount out number,
MYCS out cur_type );
End;
Next, create a package subject that includes the declared Implementation of the stored procedure
Create or replace package body jisen. Test
Is
Procedure pageprocedure
(Sqltext in varchar2,
Pagecount in number,
Pagenumber in number,
Sqlcondition in varchar2,
Icount out number,
MYCS out cur_type
)
As
Tempsql varchar2 (2000 );
Bbegin number (10 );
Bend number (10 );
Find_rs_cur cur_type;
Begin

If sqlcondition is null then
Begin
Tempsql: = 'select count (*) from ('| sqltext | ')';
End;
Elsif length (sqlcondition)> 0 then
Begin
Tempsql: = 'select count (*) from ('| sqltext |') Where '| sqlcondition;
End;
Else
Begin
Tempsql: = 'select count (*) from ('| sqltext | ')';
End;
End if;
Execute immediate tempsql into icount;

Bbegin: = pagecount * pagenumber;
Bend: = (pagenumber + 1) * pagecount;
 
Tempsql: = 'select * from (
Select rownum as Tempa, T. * from ('
| Sqltext | ') t where rownum <' | bend | ')
Where Tempa> = '| bbegin;
Open find_rs_cur for tempsql;
MYCS: = find_rs_cur;
-- Execute immediate tempsql; the query results cannot be obtained from C # using this statement.
End pageprocedure;
End pk_wt;
In this stored procedure, rownum is used for paging.
I wonder if the experts have a simple stored procedure for returning a dataset? Don't forget to give me some advice!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.