go
在 oracle 中,请按以下步骤操作:
(1)创建一个包,含有一个游标类型:(一个数据库中只需作一次)
create or replace package test
as
type test_cursor is ref cursor;
end test;
(2)过程:
create or replace procedure getcategorybooks
(
p_cursor out test.test_cursor, -- 这里是上面包中的类型,输出参数
p_catogoryid integer
)
as
begin
open p_cursor for
select * from books
where categoryid=p_catogoryid;
end getcategorybooks;
(3).net 程序中:
oracleparameters parameters = {
new oracleparameter("p_cursor", oracletype.cursor, 2000, parameterdirection.output, true, 0, 0, "",
datarowversion.default, convert.dbnull),
new oracleparameter("p_catogoryid", oracletype.int32)
};
parameters[1].value = 22;
oracleconnection connection = new oracleconnection( connectionstring );
oraclecommand command = new oraclecommand("getcategorybooks", connection);
command.commandtype = commandtype.storedprocedure;
foreach(oracleparameter parameter in parameters)
command.parameters.add( parameter );
connection.open();
oracledatareader dr = command.executereader();
while(dr.read())
{
// 你的具体操作。这个就不需要我教吧?
}
connection.close();
另外有一点需要指出的是,如果使用 datareader 取得了一个记录集,那么在 datareader 关闭之前,程序无法访问输出参数和返回值的数据。
好了,先这些,总之 .net 访问 oracle 还是有很多地方和 sql server 不同的,慢慢学习了