Oracle通过存储过程如何正确返回数据集?
?
摘要:以下的文章Oracle通过存储过程中返回数据集的实际应用,我前两天在相关网站看见的资
料,觉得挺好,就拿出来供大家分享。
?
标签:Oracle通过存储过程
?
文章主要教会你如何正确的使用Oracle存储过程使其返回相关的数据集的实际操作步骤,我们大家都知道在Oracle中存储过程的返回相关的数据集主要作用是通过相关ref cursor类型数据的实际应用参数返回的,而返回数据的参数应该是out或in out类型的。
由于在定义Oracle存储过程时无法直接指定参数的数据类型为:ref cursor,而是首先通过以下方法将ref cursor进行了重定义:
1. create or replace package FuxjPackage is 2. type FuxjResultSet is ref cursor;
还可以定义其他内容
1. end FuxjPackage;
再定义Oracle存储过程:
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中调用返回数据集的Oracle存储过程
可以通过TstoredProc或TQuery控件来调用执行返回数据集的存储,数据集通过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存储过程中返回数据集的介绍,望你能有所收获。
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库Oracle通过存储过程如何正确返回数据集在线全文阅读。
相关推荐: