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中調用返回數據集的存儲過程
可以通過TstoredProc或TQuery控件來調用執行返回數據集的存儲,數據集通過TstoredProc或TQuery控件的參數返回,注意參數的DataType類型為ftCursor,而參數的ParamType類型為ptInputOutput。
使用TstoredProc執行UpdatefuxjExample的相關設置為:
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
執行方法為:
StoredProc1.Params.Items[0].AsString:=Edit1.Text; //給參數賦值;
StoredProc1.Params.Items[1].AsString:=Edit2.Text; //給參數賦值;
StoredProc1.Active:=False;
StoredProc1.Active:=True; //返回結果集
使用TQuery執行InsertfuxjExample的相關設置為:
object Query1: TQuery
DatabaseName = 'UseProc'
SQL.Strings = (
'begin'
' InsertfuxjExample(sDM=>M,sMC=>:mc,pRecCur=>:RecCur);'
'end;')
ParamData = <
item
DataType = ftString
Name = 'DM'
ParamType = ptInput
end
item
DataType = ftString
Name = 'mc'
ParamType = ptInput
end
item
DataType = ftCursor
Name = 'RecCur'
ParamType = ptInputOutput
end>
end
執行方法為:
Query1.Params.Items[0].AsString:=Edit3.Text; //給參數賦值;
Query1.Params.Items[1].AsString:=Edit4.Text; //給參數賦值;
Query1.Active:=False;
Query1.Active:=True;
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中調用返回數據集的存儲過程
可以通過TstoredProc或TQuery控件來調用執行返回數據集的存儲,數據集通過TstoredProc或TQuery控件的參數返回,注意參數的DataType類型為ftCursor,而參數的ParamType類型為ptInputOutput。
使用TstoredProc執行UpdatefuxjExample的相關設置為:
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
執行方法為:
StoredProc1.Params.Items[0].AsString:=Edit1.Text; //給參數賦值;
StoredProc1.Params.Items[1].AsString:=Edit2.Text; //給參數賦值;
StoredProc1.Active:=False;
StoredProc1.Active:=True; //返回結果集
使用TQuery執行InsertfuxjExample的相關設置為:
object Query1: TQuery
DatabaseName = 'UseProc'
SQL.Strings = (
'begin'
' InsertfuxjExample(sDM=>M,sMC=>:mc,pRecCur=>:RecCur);'
'end;')
ParamData = <
item
DataType = ftString
Name = 'DM'
ParamType = ptInput
end
item
DataType = ftString
Name = 'mc'
ParamType = ptInput
end
item
DataType = ftCursor
Name = 'RecCur'
ParamType = ptInputOutput
end>
end
執行方法為:
Query1.Params.Items[0].AsString:=Edit3.Text; //給參數賦值;
Query1.Params.Items[1].AsString:=Edit4.Text; //給參數賦值;
Query1.Active:=False;
Query1.Active:=True;
附:創建返回數據集的存儲過程 簡單框架
1.
create or replace package TestPackage is
type TestResultSet is ref cursor;
end TestPackage ;
2.
create or replace procedure Test
(
pRecCur in out TestPackage .TestResultSet
)
as
begin
open pRecCur for
select * from table;
end;