惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
宝玉的分享
宝玉的分享
G
Google Developers Blog
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
V2EX
V
Visual Studio Blog
博客园 - Franky
S
SegmentFault 最新的问题
Jina AI
Jina AI
爱范儿
爱范儿
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
D
DataBreaches.Net
C
Check Point Blog
月光博客
月光博客
P
Proofpoint News Feed
T
The Blog of Author Tim Ferriss
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MongoDB | Blog
MongoDB | Blog
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
Martin Fowler
Martin Fowler

博客园 - yellowwood

cmder简单使用 回想一下2013中国软件技术大会 Should Assertion Library 数字用千分位表示 从AD( Active Directory )读取 Email 报表产生方式之二比较 报表产生方式之一图示 报表订阅 報表部署 via VS2005 报表参数 报表rdl嵌入网页(ASP.NET) 報表与子報表 RDL之矩陣 [Oracle整理]数据类型大全 [Oracle整理]Oracle游标(显示游标&隐式游标&动态游标&参数游标) [Oracle整理]Oracle之Procedure参数类型 [Oracle整理]Oracle之数组 [Oracle整理]Oracle之ROWTYPE和RECORD [Oracle整理]synonym及其应用
[Oracle整理].NET 调用 Oracle之REF Cursor
yellowwood · 2012-02-11 · via 博客园 - yellowwood

一、创建测试数据

--创建message表-- 
create table message 
( 
Msg_Id number primary key, 
Msg_Title varchar2(100) not null, 
Msg_Body varchar2(2000), 
Msg_Createtime date default sysdate, 
Msg_UserName varchar2(30) 
); 
--初始化message表数据-- 
create or replace procedure prd_InitMessage 
is

begin 
  
    for i in 1..15 loop 
      insert into scott.message(msg_id,msg_title,msg_body,msg_username) 
      values 
        (i, 'Test独上高楼望断天涯路', 'Test衣带渐宽终不悔', 'king'||i);  

    end loop; 
    commit; 
end ;

二、创建存储过程

/* 
包声明 
*/ 
create or replace package pkg_message 
is 
  --声明变量、过程 
  type type_refcur is ref cursor;--游标变量,由于返回多条记录 
  procedure GetAllMessage( 
    result1 out type_refcur 
  ); 
end; 
/* 
包主体 
*/ 
create or replace package body pkg_message 
is 
  --要注意一点是 procedure 前面不能有create 
  procedure GetAllMessage( 
    result1 out type_refcur 
  ) 
  is 
   
  begin 
    open result1 for 
    select * from scott.message; 
  end GetAllMessage; 
end;

三、VB.NET 调用PROCEDURE

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim conn As New System.Data.OracleClient.OracleConnection

        conn.ConnectionString = "user id=scott;data source=orcl;password=123"
        Try
            
            conn.Open()

            Dim comm As New OracleCommand
            comm.Connection = conn
            comm.CommandType = CommandType.StoredProcedure
            comm.CommandText = "pkg_message.GetAllMessage"

            Dim result1 As New OracleClient.OracleParameter
            result1.OracleType = OracleType.Cursor
            result1.Direction = ParameterDirection.Output
            comm.Parameters.Add(result1)

            'comm.Parameters.Add("result", OracleType.Cursor)
            'comm.Parameters("result").Direction = ParameterDirection.Output

            Dim ds As DataSet = New DataSet
            Dim ada As New System.Data.OracleClient.OracleDataAdapter(comm)
            ada.Fill(ds)


            'Me.DataGrid1.DataSource = ds.Tables("message")
            conn.Close()
            MsgBox("success!!!")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

_

狦_