1818IP-服务器技术教程,云服务器评测推荐,服务器系统排错处理,环境搭建,攻击防护等

当前位置:首页 - 数据库 - 正文

君子好学,自强不息!

文章主要教会你如何正确的使用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 

本文来源:1818IP

本文地址:https://www.1818ip.com/post/10985.html

免责声明:本文由用户上传,如有侵权请联系删除!

发表评论

必填

选填

选填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。