请教:关于调用存储过程返回数据集的问题(200分)

  • 主题发起人 主题发起人 xda
  • 开始时间 开始时间
X

xda

Unregistered / Unconfirmed
GUEST, unregistred user!
我在Oracle中建立了一个包,包内有一个游标用于返回数据,一个存储过程用于查询并生成数据,在Oracle中编译这个包没有错误。在Delphi中我使用了TSQLStoredProc来执行存储过程。TSQLConnection1的设置没有错误(其它控件连接数据库数据均正常)。测试的代码如下:<br>&nbsp; SQLStoredProc1.Close;<br>&nbsp; SQLStoredProc1.PackageName:='TestPKG';<br>&nbsp; SQLStoredProc1.StoredProcName:='TestProc';<br>&nbsp; SQLStoredProc1.Params.Clear;<br>&nbsp; SQLStoredProc1.Params.CreateParam(ftBCD,'CS1',ptInput);<br>&nbsp; SQLStoredProc1.Params.CreateParam(ftBCD,'CS2',ptInput); &nbsp;<br>&nbsp; SQLStoredProc1.Params.CreateParam(ftCursor,'CS3',ptOutput);<br>&nbsp; SQLStoredProc1.ParamByName('CS1').Value:=1;<br>&nbsp; SQLStoredProc1.ParamByName('CS2').Value:=2;<br>&nbsp; SQLStoredProc1.Open;<br>执行后提示错误“Accessiolation at address 022C1A09 in module 'dbexpora.dll',write of address 00000000”。请各位高手指教这是怎么回事?
 
路过,顶一下
 
我将包内的存储过程放到包外,修改后的包如下:<br>Create Or Replace Package ChargePKG <br>&nbsp; As<br>&nbsp; &nbsp; Type ChargeCursor Is REF Cursor;<br>End ChargePKG;<br>1.当存储过程为<br>Create Or Replace Procedure GetCarSortChargeData(Dep VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ClassNO VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MorningShiftOnDuty VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MorningShiftOffDuty VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MiddleShiftOnDuty VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MiddleShiftOffDuty VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NightShiftOnDuty VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NightShiftOffduty VARCHAR2) <br>Is<br>Begin<br>&nbsp; Insert Into TempGratisCarTable(CarID,CarTpye,CriterionWeight,WholeWeight) Values(1,2,3,4);<br>End GetCarSortChargeData;<br>时,执行“SQLStoredProc1.ExecProc;”正常<br>2.当存储过程为<br>Create Or Replace Procedure GetCarSortChargeData(Dep Number,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ClassNO Number,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MorningShiftOnDuty VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MorningShiftOffDuty VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MiddleShiftOnDuty VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MiddleShiftOffDuty VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NightShiftOnDuty VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NightShiftOffduty VARCHAR2) <br>Is<br>Begin<br>&nbsp; Insert Into TempGratisCarTable(CarID,CarTpye,CriterionWeight,WholeWeight) Values(1,2,3,4);<br>End GetCarSortChargeData;<br>时(即包既具有数字型输入变量,又具有字符串型输入变量),执行“SQLStoredProc1.ExecProc;”时提示“BCD overflow”错误。<br>3.将存储过程改为<br>Create Or Replace Procedure GetCarSortChargeData(Dep VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ClassNO VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MorningShiftOnDuty VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MorningShiftOffDuty VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MiddleShiftOnDuty VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MiddleShiftOffDuty VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NightShiftOnDuty VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NightShiftOffduty VARCHAR2,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CarSortChargeCursor Out ChargePKG.ChargeCursor) <br>Is<br>Begin<br>&nbsp; Insert Into TempGratisCarTable(CarID,CarTpye,CriterionWeight,WholeWeight) Values(1,2,3,4);<br>&nbsp; Open CarSortChargeCursor For Select * From TempGratisCarTable;<br>End GetCarSortChargeData;<br>时(即在输入变量均为字符串型变量的基础上,增加了游标型输出变量),执行“SQLStoredProc1.Open;”时提示如下错误<br>ORA-06550:第1行,第1列;<br>PLS-00306:调用'GetCarSortChargeData'时参数个数或类型错误<br>ORA-06550:第1行,第1列;<br>PLS-00306:调用'GetCarSortChargeData'时参数个数或类型错误<br>ORA-06550:第1行,第1列;<br>PL/SQL:Statement ignored.<br>请大侠门指教是怎么回事?是dbexpress的bug吗?
 
现在大富翁oracle的人好少啊 兄弟 你去CSDN问问吧<br>第一次的错误往往是调用了已经释放的模块造成的,至于原因 也说不上来 <br>后面的问题 小弟都不甚明白 &nbsp;没做过package里面的存储过程<br>问一句 package有什么好处 比简单的procedure
 
把过程放到包里不能解决问题,包只是便于后台管理方便和PL/SQL编码规范而引入的。----------LZ描述不是很清楚,我觉得应该是参数的类型问题,要么是IN,OUT没有规范好。
 
谢谢各位的关注。参数个数和类型应该没有错误的,因为按照步骤1测试正常,再按步骤4增加了游标型输出变量就出错了。另,我在TSQLStoredProc中操作的方法如下: <br>&nbsp; SQLStoredProc1.Close; <br>&nbsp; SQLStoredProc1.Params.Clear; <br>&nbsp; SQLStoredProc1.PackageName:=''; <br>&nbsp; SQLStoredProc1.StoredProcName:='GETCARSORTCHARGEDATA'; <br>&nbsp; SQLStoredProc1.Params.CreateParam(ftString,'Dep',ptInput); <br>&nbsp; SQLStoredProc1.Params.CreateParam(ftString,'ClassNO',ptInput); <br>&nbsp; SQLStoredProc1.Params.CreateParam(ftString,'MorningShiftOnDuty',ptInput); <br>&nbsp; SQLStoredProc1.Params.CreateParam(ftString,'MorningShiftOffDuty',ptInput); <br>&nbsp; SQLStoredProc1.Params.CreateParam(ftString,'MiddleShiftOnDuty',ptInput); <br>&nbsp; SQLStoredProc1.Params.CreateParam(ftString,'MiddleShiftOffDuty',ptInput); <br>&nbsp; SQLStoredProc1.Params.CreateParam(ftString,'NightShiftOnDuty',ptInput); <br>&nbsp; SQLStoredProc1.Params.CreateParam(ftString,'NightShiftOffduty',ptInput); <br>&nbsp; SQLStoredProc1.Params.CreateParam(ftCursor,'CARSORTCHARGECURSOR',ptOutput); <br>&nbsp; SQLStoredProc1.ParamByName('Dep').Value:='1'; <br>&nbsp; SQLStoredProc1.ParamByName('ClassNO').Value:='2'; <br>&nbsp; SQLStoredProc1.ParamByName('MorningShiftOnDuty').Value:='2008-8-30 8:55:00'; <br>&nbsp; SQLStoredProc1.ParamByName('MorningShiftOffDuty').Value:='2008-9-29 16:5:00'; <br>&nbsp; SQLStoredProc1.ParamByName('MiddleShiftOnDuty').Value:='2008-8-30 15:55:00'; <br>&nbsp; SQLStoredProc1.ParamByName('MiddleShiftOffDuty').Value:='2008-9-30 00:05:00'; <br>&nbsp; SQLStoredProc1.ParamByName('NightShiftOnDuty').Value:='2008-8-30 23:55:00'; <br>&nbsp; SQLStoredProc1.ParamByName('NightShiftOffduty').Value:='2008-9-30 9:5:00'; <br>&nbsp; SQLStoredProc1.Open;
 
给个例子给你参考:<br>with qryProc do<br>&nbsp; begin<br>&nbsp; &nbsp; Close;<br>&nbsp; &nbsp; parameters.Clear;<br>&nbsp; &nbsp; ProcedureName:='PaginationQuery';<br>&nbsp; &nbsp; parameters.CreateParameter('p_selectSQL',ftString,pdInput,15000,'select * from tb_goodsmoney');<br>&nbsp; &nbsp; parameters.CreateParameter('p_curPage',ftInteger,pdInputOutput,20,1);<br>&nbsp; &nbsp; parameters.CreateParameter('p_pageSize',ftInteger,pdInputOutput,20,edtPage.Text);<br>&nbsp; &nbsp; parameters.CreateParameter('p_totalRecords',ftInteger,pdOutput,20,0);<br>&nbsp; &nbsp; parameters.CreateParameter('p_totalPages',ftInteger,pdOutput,20,0);<br>&nbsp; &nbsp; Open;<br>&nbsp; end;
 
To dengxh10大侠:<br>你用的是TADOStoredProc控件吗?我用的是dbExpress控件。
 
如何在Delphi中调用oracle的存储过程返回数据集 <br><br><br>1.利用AdoConnection1连接数据库(驱动为 oracle Provider for OLE DB),<br>&nbsp; **并在连接字符串中加入这一节: &nbsp;PLSQLRSet=1; 如下所示:<br>Provider=OraOLEDB.Oracle.1;Password=KXD;Persist Security Info=True;User ID=KXD;Data Source=TEST3;PLSQLRSet=1 <br><br><br>---------------------------<br>那么 dbExpress会不会因这有关呢?返回的数据集是不能修改只能看的。ORACLE不像SQL2000那样方便了
 
测试了一下TSQLStoredProc,感觉使用难道比TADOStoredProc大很多<br>调用Oracle存储过程成功,调用MSSQL的存储过程失败。<br>在Oracle下成功的调用代码:<br>&nbsp; with spProc1 do<br>&nbsp; begin<br>&nbsp; &nbsp; Close;<br>&nbsp; &nbsp; PackageName:='MYPKG_PUBLIC';<br>&nbsp; &nbsp; StoredProcName:=''; &nbsp;//先把StoredProcName名称清空,再赋值<br>&nbsp; &nbsp; StoredProcName:='PAGINATIONQUERY';//名称一定要是大写,赋名之后,Params的参数列表会自动创建,不需我们手动创建。<br>&nbsp; &nbsp; Params.ParamByName('p_selectSQL').AsString:=' select * from tb_goodsmoney ';<br>&nbsp; &nbsp; Params.ParamByName('p_curPage').Value:=1; &nbsp;//为参数赋值,类型一定要正确,最好用.Value。在有些数值类型时,用.AsInteger未毕对,可能需要用.AsBCD,要根据实际情况来定,否则也会报错。<br>&nbsp; &nbsp; Params.ParamByName('p_pageSize').Value:=StrToInt(edtPage.Text);<br>&nbsp; &nbsp; Open;<br>&nbsp; end;<br><br>TSQLStoredProc调用MSSQL存储过程,未能成功,还请有关能调用成功的朋友列出关键点。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
937
SUNSTONE的Delphi笔记
S
后退
顶部