C 呼叫ORACLE儲存過程返回結果集及函式

2021-05-23 06:00:01 字數 3172 閱讀 4617

oracle的儲存過程返回記錄集,找到兩個oracle段都一樣,只是c#部份有點區別,都放上來,個人偏向使用用第乙個。

c#呼叫oracle儲存過程返回結果集及函式

oracle段:

首先在oracle建立package和package body,將在這裡面定義函式和儲存過程返回結果集。

1:建立package:

create or replace package scott.pk_wt

is type mytype is ref cursor;

procedure p_wt(mycs out mytype);

function f_get(str in varchar2)

return varchar2;

end;

/ 說明:其實package只是個宣告罷了。我們在這裡定義了乙個儲存過程返回結集和乙個函式,返回字串。

2:建立package body:

create or replace package body scott.pk_wt

is procedure p_wt(mycs out mytype)

is begin

open mycs for select * from test;

end p_wt;

function f_get(str varchar2)

return varchar2

is str_temp varchar2(100) := ''good luck!'';

begin

str_temp := str_temp || str;

return str_temp;

end f_get;

end pk_wt;

/ 說明:這裡建立package body是具體的說明和使用,將採用什麼方式實現。。

c#呼叫oracle返回結果集:

oraclecommand cmd=new oraclecommand("pk_wt.p_wt",orcn);

cmd.commandtype=commandtype.storedprocedure;

oracleparameter p1=new oracleparameter("mycs",oracletype.cursor);

p1.direction=system.data.parameterdirection.output;

cmd.parameters.add(p1);

oracledataadapter da=new oracledataadapter(cmd);

dataset ds=new dataset();

da.fill(ds,"test");

this.datagrid1.datasource=ds;

this.datagrid1.databind();

這裡沒什麼可說的類。。只是定義的資料型別是游標,型別是output,另外沒什麼了。。

oracle的儲存過程返回記錄集

oracle的儲存過程返回記錄集,關鍵之處是要用游標。

關於資料庫的游標(cursor)大家肯定都接觸不少,我們可以通過 open,fetch,close操作控制游標進行各種方便的操作,這方面的例子我就不在重複了。我們現在要介紹的是游標變數(cursor variable)。類似游標,游標變數也是指向乙個查詢結果集的當前行。不同的是,游標變數能為任何型別相似(type-compatible)的查詢 開啟,而並不是繫結到某乙個特定的查詢。通過游標變數,你可以在資料庫的資料提取中獲得更多的方便。

首先是建立表。

create table lihuan.bill_points

( points_id number(10,0) not null,

customer_id number(10,0) not null,

bill_point_no number(2,0) default 1 not null,

constraint pk_bill_points primary key (points_id)

) /

其次,建package

create or replace package lihuan.yy_pkg_bill_point_no/*取得使用者的所有計費電序號*/

is type t_cursor is ref cursor;

procedure bill_point_no(p_customer_id bill_points.customer_id%type,

re_cursor out t_cursor);

end;

/ 再次,建package body

create or replace package body lihuan.yy_pkg_bill_point_no/*取得使用者的所有計費電序號*/

is procedure bill_point_no(p_customer_id bill_points.customer_id%type,

re_cursor out t_cursor)

is v_cursor t_cursor;

begin

open v_cursor for

select bill_point_no from bill_points where customer_id =p_customer_id;

re_cursor := v_cursor;

end;

end;

/ 最後,在.net中程式呼叫。

public dataset bill_point_no(string customer_id)//ok

else

return dataset;

} public bool runprocedure(string returnparameter,oracletype paramtype,ref dataset dataset,hashtable ht ,string procedurename,string oracleconnection)

oracledataadapter odadapter=new oracledataadapter(dacommand);

try

catch(system.exception e)

finally

c 呼叫oracle儲存過程返回資料集

2008 12 20 10 59 57 分類 net 字型大小訂閱 create or replace package pkg tabletype istype tabletype is ref cursor procedure sp cpzd cpno in varchar2,status in ...

C 呼叫Oracle 儲存過程返回資料集 例項

1.在oracle 下建立表 t user id varchar 20 name varchar 20 2.新增資料 1 張三 2 李四 3.建立包並且定義變數和宣告儲存過程 create or replace package pkg user as 定義返回值 游標型別 type myrctype...

關於c 呼叫oracle儲存過程返回資料集的寫法

create or replace package body report.clinic rate asprocedure clinic master start date date,end date date,i number,t rate out t cursor is begin open t...