文章主要教会你如何正确的使用Oracle存储过程使其返回相关的数据集的实际操作步骤,我们大家都知道在Oracle中存储过程的返回相关的数据集主要作用是通过相关ref cursor类型数据的实际应用参数返回的,而返回数据的参数应该是out或in out类型的。
由于在定义Oracle存储过程时无法直接指定参数的数据类型为:ref cursor,而是首先通过以下方法将ref cursor进行了重定义:
createorreplacepackageFuxjPackageis typeFuxjResultSetisrefcursor;
还可以定义其他内容
endFuxjPackage;
再定义Oracle存储过程:
createorreplaceprocedureUpdatefuxjExample (sDMinchar,sMCinchar,pRecCurinoutFuxjPackage.FuxjResultSet) as begin updatefuxjExamplesetmc=sMCwheredm=sDM; ifSQL%ROWCOUNT=0then rollback; openpRecCurfor select'0'resfromdual; else commit; openpRecCurfor select'1'resfromdual; endif; end;
和
createorreplaceprocedureInsertfuxjExample (sDMinchar,sMCinchar,pRecCurinoutFuxjPackage.FuxjResultSet) as begin insertintoFuxjExample(dm,mc)values(sDM,sMC); commit; openpRecCurfor select*fromFuxjExample; end;
二、在Delphi中调用返回数据集的Oracle存储过程
可以通过TstoredProc或TQuery控件来调用执行返回数据集的存储,数据集通过TstoredProc或TQuery控件的参数返回,注意参数的DataType类型为ftCursor,而参数的ParamType类型为ptInputOutput。
使用TstoredProc执行UpdatefuxjExample的相关设置为:
objectStoredProc1: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
相关文章
标签:Oracle