【问题标题】:Return an Oracle Ref Cursor to a SqlServer T-SQL caller将 Oracle Ref Cursor 返回给 SqlServer T-SQL 调用者
【发布时间】:2010-11-02 11:54:02
【问题描述】:

是否可以将 Oracle Ref Cursor 返回给 SqlServer T-SQL 中的调用方?在处理普通的 .Net 程序时,有这篇知识库文章:http://support.microsoft.com/kb/322160

但是 T-SQL 可以实现相同类型的事情吗?

【问题讨论】:

  • “T-SQL 中的调用者”是什么意思?您是指通过链接服务器调用 Oracle 的 SQL Server 作业或进程吗?
  • 从 SqlServer 中的存储过程调用

标签: .net sql-server oracle tsql plsql


【解决方案1】:

我相信这就是您正在寻找的 http://social.msdn.microsoft.com/Forums/en-US/sqlintegrationservices/thread/fcdaa97e-8415-4c3e-8ffd-1ad45b590d57/ (从那里):

我们可以使用 Script Component 来执行 oracle 存储过程,以 ref cursor 为参数

将输出列添加到组件中。

例如:我有一个 oracle 包 Get_Employees.GetEmployees,它采用 ref cursor 类型的 put put 参数

我添加了 2 个这样的列 EmpID 和 EmpName,然后将 CreateNewOutputRows() 覆盖为

Public Overrides Sub CreateNewOutputRows()

Try

Dim dr As OracleDataReader = oracleCmd.ExecuteReader()

While dr.Read

Output0Buffer.AddRow()

Output0Buffer.EmpID = CDec(dr(0).ToString)

Output0Buffer.EmpName = dr(1).ToString

End While

Catch ex As Exception

Me.ComponentMetaData.FireError(-1, "InitExtract", ex.Message, String.Empty, 0, True)

End Try

Output0Buffer.SetEndOfRowset()

End Sub

在此之前我们需要在 PreExecute 子程序中设置 oracle 命令对象为:

Dim plsql As String = "BEGIN Get_Employees.GetEmployees(:curEmployeesbyID);END;"

oracleCmd = New OracleCommand(plsql, oracleConn)

With oracleCmd

.CommandType = CommandType.Text

.Parameters.Add(":curEmployeesbyID", OracleType.Cursor).Direction = ParameterDirection.Output

End With

【讨论】:

    猜你喜欢
    • 2012-01-13
    • 2022-07-21
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    相关资源
    最近更新 更多