Oracle returns related datasets through its actual stored procedures

Source: Internet
Author: User

The following articles mainly introduce the actual operating scheme for Oracle to return the relevant dataset through the stored procedure. The first thing we need to know is how to correctly use the stored procedure to return the dataset, we all know that the data set returned by the stored procedure in the Oracle database is returned by the parameters of Oracle Data of the ref cursor type.

The returned data parameters should be of the out or in out type, because the data type of the parameter cannot be directly specified when the stored procedure is defined: ref cursor, instead, Oracle redefines 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 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;  

Call the stored procedure of the returned dataset in Delphi

You can use the TstoredProc or TQuery control to call the storage of the returned dataset. The Oracle dataset is returned through the parameters of the TstoredProc or TQuery control. Note that the DataType type of the parameter is ftCursor, 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 the description of the data set returned by Oracle through the stored procedure. I hope it will help you in this regard.

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.