How Does Oracle return a dataset through a stored procedure?

Source: Internet
Author: User

This article mainly teaches you how to correctly use the Oracle stored procedure so that it can return the actual operation steps of the relevant dataset, we all know that the returned data sets in the stored procedures in Oracle mainly serve to be returned through the actual application parameters of the ref cursor data, the returned data parameters should be of the out or in out type.

When defining an Oracle stored procedure, you cannot directly specify the parameter's data type as ref cursor. Instead, you must first redefine the ref cursor using the following method:

 
 
  1. create or replace package FuxjPackage is  
  2. type FuxjResultSet is ref cursor;  

You can also define other content

 
 
  1. end FuxjPackage; 

Then define the Oracle stored procedure:

 
 
  1. create or replace procedure UpdatefuxjExample 
    (sDM in char,sMC in char, pRecCur in out FuxjPackage.FuxjResultSet)  
  2. as  
  3. begin  
  4. update fuxjExample set mc=sMC where dm=sDM;  
  5. if SQL%ROWCOUNT=0 then  
  6. rollback;  
  7. open pRecCur for  
  8. select '0' res from dual;  
  9. else  
  10. commit;  
  11. open pRecCur for  
  12. select '1' res from dual;  
  13. end if;  
  14. end;  

And

 
 
  1. create or replace procedure InsertfuxjExample 
    (sDM in char,sMC in char, pRecCur in out FuxjPackage.FuxjResultSet)  
  2. as  
  3. begin  
  4. insert into FuxjExample (dm,mc) values (sDM,sMC);  
  5. commit;  
  6. open pRecCur for  
  7. select * from FuxjExample;  
  8. end;  

2. Calling the Oracle Stored Procedure for the returned dataset in Delphi

You can use the TstoredProc or TQuery control to call and store the returned dataset. The dataset is returned through the parameters of the TstoredProc or TQuery control. Note that the DataType type of the parameter is ftCursor, And the ParamType type of the parameter is ptInputOutput.

Use TstoredProc to execute UpdatefuxjExample and set it:

 
 
  1. object StoredProc1: TStoredProc  
  2. DatabaseName = 'UseProc' 
  3. StoredProcName = 'UPDATEFUXJEXAMPLE' 
  4. ParamData = < 
  5. item 
  6. DataType = ftString 
  7. Name = 'sDM' 
  8. ParamType = ptInput 
  9. end  
  10. item  
  11. DataType = ftString 
  12. Name = 'sMC' 
  13. ParamType = ptInput 
  14. end  
  15. item  
  16. DataType = ftCursor 
  17. Name = 'pRecCur' 
  18. ParamType = ptInputOutput 
  19. Value = Null 
  20. end> 
  21. end   

The above content is an introduction to the returned data sets in the Oracle stored procedure. I hope you will find some gains.

Related Article

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.