国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > Oracle > 正文

用.NET調用Oracle存儲過程返回記錄集

2024-08-29 13:32:26
字體:
來源:轉載
供稿:網友

  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
 {
dataset dataset = new dataset();
hashtable ht=new hashtable();
ht.add("p_customer_id",customer_id);
if(runprocedure("re_cursor",oracletype.cursor,ref dataset,
ht,bmsoracleuser+".yy_pkg_bill_point_no.bill_point_no",
bmsoracleconnectionstring))
{
;
}
else
{
dataset=null;
}
return dataset;
 }
public bool runprocedure(string returnparameter,
oracletype paramtype,ref dataset dataset,hashtable ht ,
string procedurename,string oracleconnection)
 {
system.data.oracleclient.oracleconnection dsconnection =
new system.data.oracleclient.oracleconnection(oracleconnection);
system.data.oracleclient.oraclecommand dacommand =
new system.data.oracleclient.oraclecommand(procedurename,dsconnection);
dsconnection.open();
dacommand.commandtype=commandtype.storedprocedure;
idictionaryenumerator enumerator;
enumerator = ht.getenumerator();
object value=null;
oracleparameter oracleparam;
oracleparam = dacommand.parameters.
add(new oracleparameter(returnparameter,paramtype));
oracleparam.direction = parameterdirection.output;
while(enumerator.movenext())
{
value = enumerator.value;
oracleparam=dacommand.parameters.
add(new oracleparameter
(enumerator.key.tostring(), value));
}
oracledataadapter odadapter=new oracledataadapter(dacommand);
try
{
odadapter.fill(dataset);
return true;
}
catch(system.exception e)
{
e.tostring();
return false;
}
finally
{
ht.clear();
dacommand.parameters.clear();
dsconnection.close();
}
}

,歡迎訪問網頁設計愛好者web開發。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 旺苍县| 淄博市| 渭南市| 博野县| 登封市| 麻城市| 秦安县| 乌拉特前旗| 格尔木市| 花垣县| 大悟县| 革吉县| 西吉县| 九寨沟县| 昂仁县| 甘德县| 云浮市| 邯郸市| 自治县| 巴南区| 鹰潭市| 马鞍山市| 彭水| 新巴尔虎右旗| 普宁市| 习水县| 育儿| 安新县| 石景山区| 廉江市| 公安县| 江阴市| 义乌市| 吉林市| 天津市| 诸城市| 新乡市| 东城区| 梁平县| 西贡区| 格尔木市|