Oracle通過其實際存儲過程中返回相關(guān)數(shù)據(jù)集
以下的文章主要介紹的是Oracle通過存儲過程中返回相關(guān)數(shù)據(jù)集的實際操作方案,我們首先要了解的是如何正確的使用存儲過程來返回數(shù)據(jù)集,我們大家都知道Oracle數(shù)據(jù)庫中的存儲過程返回數(shù)據(jù)集是Oracle通過ref cursor類型數(shù)據(jù)的參數(shù)返回的。
而返回數(shù)據(jù)的參數(shù)應(yīng)該是out或in out類型的,由于在定義存儲過程時無法直接指定參數(shù)的數(shù)據(jù)類型為:ref cursor,而是首先Oracle通過以下方法將ref cursor進(jìn)行了重定義:
- create or replace package FuxjPackage is
- type FuxjResultSet is ref cursor;
還可以定義其他內(nèi)容
- end FuxjPackage;
再定義存儲過程:
- create or replace procedure UpdatefuxjExample (sDM in char,sMC in char, pRecCur in out FuxjPackage.FuxjResultSet)
- as
- begin
- update fuxjExample set mc=sMC where dm=sDM;
- if SQL%ROWCOUNT=0 then
- rollback;
- open pRecCur for
- select '0' res from dual;
- else
- commit;
- open pRecCur for
- select '1' res from dual;
- end if;
- end;
和
- create or replace procedure InsertfuxjExample
(sDM in char,sMC in char, pRecCur in out FuxjPackage.FuxjResultSet)- as
- begin
- insert into FuxjExample (dm,mc) values (sDM,sMC);
- commit;
- open pRecCur for
- select * from FuxjExample;
- end;
在Delphi中調(diào)用返回數(shù)據(jù)集的存儲過程
可以通過TstoredProc或TQuery控件來調(diào)用執(zhí)行返回數(shù)據(jù)集的存儲,數(shù)據(jù)集Oracle通過TstoredProc或TQuery控件的參數(shù)返回,注意參數(shù)的DataType類型為ftCursor,而參數(shù)的ParamType類型為ptInputOutput。
使用TstoredProc執(zhí)行UpdatefuxjExample的相關(guān)設(shè)置為:
- object StoredProc1: TStoredProc
- DatabaseName = 'UseProc'
- StoredProcName = 'UPDATEFUXJEXAMPLE'
- ParamData = <
- item
- DataType = ftString
- Name = 'sDM'
- ParamType = ptInput
- end
- item
- DataType = ftString
- Name = 'sMC'
- ParamType = ptInput
- end
- item
- DataType = ftCursor
- Name = 'pRecCur'
- ParamType = ptInputOutput
- Value = Null
- end>
- end
上述的相關(guān)內(nèi)容就是對Oracle通過存儲過程中返回數(shù)據(jù)集的描述,希望會給你帶來一些幫助在此方面。
【編輯推薦】