引用地址:http://www.alixixi.com/program/a/2008050727634.shtml
 
本例在VS2005+Oracle 92010 + WindowsXp Sp2测试通过
1、创建一个游标变量,为返回值使用
create or replace package types as
  type
cursorType is ref cursor;
end;
2、创建函数(或者存储过程)
create or replace function testpro return
types.cursorType is
lc types.cursorType;
begin
  open lc for select *
from test;
  return lc;
end testpro;
3、编写C#程序(注意:要先应用System.Data.OracleClient)
            OracleConnection conn = new
OracleConnection("YourConnectString");
            OracleCommand cmd = new OracleCommand("testpro",
conn);
            cmd.CommandType = CommandType.StoredProcedure;
 
            OracleParameter op = new OracleParameter("c",
OracleType.Cursor);
            op.Direction =
ParameterDirection.ReturnValue; 
            cmd.Parameters.Add(op);
 
            DataSet ds = new DataSet();
            OracleDataAdapter da = new
OracleDataAdapter(cmd);
 
            da.Fill(ds,"test");
 
            this.dataGridView1.DataSource =
ds.Tables["test"];
PS:使用储过程方法类似。
 
1、创建一个游标变量,为返回值使用

CREATE OR REPLACE PACKAGE types_mei1
AS
TYPE myrctype1 IS REF CURSOR;

PROCEDURE get (p_id NUMBER, p_rc OUT myrctype1);
END types_mei1 ;

2、创建函数(或者存储过程)
create or replace function testpro_mei1(IV IN NUMBER) return types_mei1.myrctype1 is
lc types_mei1.myrctype1;
begin
open lc for select * from classes where ID=IV;
return lc;
end testpro_mei1;

=====================================下面是对通过单个ID查询的数据

create or replace package types_mei as
type cursorType is ref cursor;
end;

=============================================

CREATE OR REPLACE PACKAGE types_mei
AS
TYPE myrctype IS REF CURSOR;

PROCEDURE get (p_id NUMBER, p_rc OUT myrctype);
END types_mei ;

create or replace function testpro_mei(IV IN NUMBER) return types_mei.myrctype is
lc types_mei.myrctype;
begin
open lc for select * from test where ID=IV;
return lc;
end testpro;

=================================================

CREATE OR REPLACE PACKAGE types_mei1
AS
TYPE myrctype1 IS REF CURSOR;

PROCEDURE get (p_id NUMBER, p_rc OUT myrctype1);
END types_mei1 ;

create or replace function testpro_mei1(IV IN NUMBER) return types_mei1.myrctype1 is
lc types_mei1.myrctype1;
begin
open lc for select * from classes where ID=IV;
return lc;
end testpro_mei1;

===================================================

===================================

存储过程:
插入数据:
CREATE OR REPLACE Procedure p_insert_t_cls --存储过程名称
(
p_stuid in CLASSES.ID%type,
p_stuname in varchar
)
as
BEGIN
insert into classes
values
(p_stuid,p_stuname);
commit;
end;

===============================================
删除 :(带返回参数)
create or replace procedure proc_delete
(
isid in number , P_ROWS OUT NUMBER
)
is
begin
delete classes where id=isid;
If SQL%Found Then
DBMS_OUTPUT.PUT_LINE('删除成功!');
P_ROWS := 1;
Else
DBMS_OUTPUT.PUT_LINE('删除失败!');
P_ROWS := 0;
End If;
commit;
end
;

删除 : (不带返回参数)
create or replace procedure p_delete_t_cls1(
cla_id in Number
)
is
begin
DELETE FROM classes WHERE id = cla_id;
commit;
end p_delete_t_cls1;

删除 : (不带返回参数)指定ID删除
create or replace procedure p_delete_t_cls is
begin
DELETE FROM classes WHERE id = 7;
commit;
end p_delete_t_cls;
====================================================

修改数据:(不带返回参数)
create or replace procedure p_update_t_cls1(
p_stuid in Number,
p_stuname in Nvarchar2
)
is
begin
update classes x set x.classname = p_stuname where x.id = p_stuid;
commit;
end p_update_t_cls1;

修改数据: :(带返回参数)

create or replace procedure proc_update(
p_stuid in Number,
p_stuname in Nvarchar2,
P_ROW out number
)
is
begin
update classes set classname = p_stuname where id = p_stuid;
If SQL%Found Then
DBMS_OUTPUT.PUT_LINE('更新成功!');
P_ROW := 1;
Else
DBMS_OUTPUT.PUT_LINE('更新失败!');
P_ROW := 0;
End If;
commit;
end proc_update;

修改数据: : (不带返回参数)指定ID修改
create or replace procedure p_update_t_cls
is
begin
update classes x set x.classname = '44' where x.id = 3;
commit;
end p_update_t_cls;

====================================================

查询所有数据:(带返回参数 游标)
create or replace package types1 as
type cursorType1 is ref cursor;
end;

create or replace function testpro1 return types1.cursorType1 is
lc1 types1.cursorType1;
begin
open lc1 for select id,classname from classes;
return lc1;
end testpro1;

传递ID查询数据:(带返回参数 游标)传递ID查询数据
CREATE OR REPLACE PACKAGE pkg_test1
AS
TYPE myrctype IS REF CURSOR;
PROCEDURE get (p_id NUMBER, p_rc OUT myrctype);
END pkg_test1 ;

create or replace function testpro(IV IN NUMBER) return types.cursorType is
lc types.cursorType;
begin
open lc for select * from classes where ID=IV;
return lc;
end testpro;
====================================================

Oracle利用游标返回结果集的的例子(C#)...(最爱)的更多相关文章

  1. 利用游标返回结果集的的例子(Oracle 存储过程)JAVA调用方法和.NET调用方法

    在sqlplus中建立如下的内容: 1.程序包 SQL> create or replace package types  2  as  3      type cursorType is re ...

  2. PB中用oracle的存储过程返回记录集做数据源来生成数据窗口,PB会找不到此存储过程及不能正常识别存储过程的参数问题(转)

    (转)在PB中用oracle的存储过程返回记录集做数据源来生成数据窗口 首先oracle的存储过程写法与MSSQL不一样,差别比较大. 如果是返回数据集的存储过程则需要利用oracle的包来定义游标. ...

  3. Oracle中游标返回多条数据的情况

    DECLARE -- 定义类型. TYPE test_type IS TABLE OF test_main%ROWTYPE; test_data test_type; -- 定义游标. CURSOR ...

  4. mybatis springmvc调用oracle存储过程,返回记录集

    参考: http://bbs.csdn.net/topics/390866155 辅助参考: http://www.2cto.com/kf/201307/226848.html http://blog ...

  5. java调用oracle存储过程,返回结果集

    package com.srie.db.pro; import java.sql.CallableStatement; import java.sql.Connection; import java. ...

  6. 怎样让Oracle的存储过程返回结果集

    Oracle存储过程: CREATE OR REPLACE PROCEDURE getcity ( citycode IN VARCHAR2, ref_cursor OUT sys_refcursor ...

  7. oracle自定义函数返回结果集

    首先要弄两个type,不知道什么鬼: 1. create or replace type obj_table as object ( id ), name ), ) ) 2. create or re ...

  8. oracle 存储过程 返回结果集

      oracle 存储过程 返回结果集 CreationTime--2018年8月14日09点50分 Author:Marydon 1.情景展示 oracle存储过程如何返回结果集 2.解决方案 最简 ...

  9. Oracle 存储过程调用返回游标的另一个存储过程。

    一个扩展存储过程调用另一个存储过程,示例: 被调用存储过程:最后会返回一个游标,游标返回一个值.调用这个存储过程的存储过程同样需要获取它. procedure SearchBill --根据到货单号查 ...

随机推荐

  1. JavaScript中的特殊数据类型

    JavaScript中的特殊数据类型 制作人:全心全意 转义字符 以反斜杠开头的不可显示的特殊字符通常为控制字符,也被称为转义字符.通常转义字符可以在字符串中添加不可显示的特殊字符,或者防止引号匹配混 ...

  2. CodeForcesGym 100524J Jingles of a String

    Jingles of a String Time Limit: 2000ms Memory Limit: 524288KB This problem will be judged on CodeFor ...

  3. Spring data jpa 复杂动态查询方式总结

    一.Spring data jpa 简介 首先我并不推荐使用jpa作为ORM框架,毕竟对于负责查询的时候还是不太灵活,还是建议使用mybatis,自己写sql比较好.但是如果公司用这个就没办法了,可以 ...

  4. android源码mm时的编译错误no ruler to make target `out/target/common/obj/JAVA_LIBRARIES/xxxx/javalib.jar', needed by `out/target/common/obj/APPS/xxxx_intermediates/classes-full-debug.jar'. Stop.

    瞧见没有,就因为多了这一个反斜杠,浪费了一下午时间找问题,哭了~~~~

  5. CALayer之 customizing timing of an animation

    customizing timing of an animation Timing is an important part of animations, and with Core Animatio ...

  6. SOJ 2785_Binary Partitions

    [题意]将一个数用二进制数表示,求一共有多少种表示方法. [分析]思路一:完全背包 [代码] #include <iostream> #include <cstdio> #in ...

  7. UVA 10603_Fill

    题意: 给定三个杯子容量,初始只有第三个杯子满,其余为空,求最少需要倒多少水才能让某一杯子中有d升水,如果不能达到,则小于d且尽量接近. 分析: 因为要求转移水量最少,所以采用优先级队列保存每次的状态 ...

  8. POJ——T 2976 Dropping tests

    http://poj.org/problem?id=2976 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13861   ...

  9. BZOJ——2190: [SDOI2008]仪仗队

    思路: 我们将其所在的位置设为(0,0),那么如果存在一个点(x,y),且有gcd(x,y)=k(k!=1),那么点(x/k,y/k)一定会将(x,y)挡住.而如果k=1,那么点(x,y)就一定会被看 ...

  10. css3 模拟标牌震荡效果

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...