Oracle通过其实际存储过程中返回相关数据集

以下的文章主要介绍的是Oracle通过存储过程中返回相关数据集的实际操作方案,我们首先要了解的是如何正确的使用存储过程来返回数据集,我们大家都知道Oracle数据库中的存储过程返回数据集是Oracle通过ref cursor类型数据的参数返回的。

而返回数据的参数应该是out或in out类型的,由于在定义存储过程时无法直接指定参数的数据类型为:ref cursor,而是首先Oracle通过以下方法将ref cursor进行了重定义:

 

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

 

还可以定义其他内容

 

 
 
 
  1. end FuxjPackage; 

再定义存储过程:

 

 
 
 
  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;  

 

 

 
 
 
  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;  

 

在Delphi中调用返回数据集的存储过程

可以通过TstoredProc或TQuery控件来调用执行返回数据集的存储,数据集Oracle通过TstoredProc或TQuery控件的参数返回,注意参数的DataType类型为ftCursor,而参数的ParamType类型为ptInputOutput。

使用TstoredProc执行UpdatefuxjExample的相关设置为:

 

 
 
 
  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   

上述的相关内容就是对Oracle通过存储过程中返回数据集的描述,希望会给你带来一些帮助在此方面。

【编辑推荐】

  1. Oracle rownum用法的归纳
  2. Oracle存储过程定时执行2种方法
  3. Oracle 10g中的hints调整机制详解
  4. 提高Oracle SQL的执行效率的3个方案
  5. Oracle数据库的性能完全保护的4个项目
THE END