vb.net 从 .NET 作为存储过程调用 Oracle 函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17026217/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 13:54:12  来源:igfitidea点击:

Call Oracle Function From .NET As Stored Procedure

asp.netvb.netoraclestored-proceduresplsql

提问by Kelly

I have written a simple Oracle function called Testing with no parameters that returns a string. When I try to call it from my .NET app, I get an error:

我编写了一个简单的 Oracle 函数,名为 Testing,没有返回字符串的参数。当我尝试从我的 .NET 应用程序调用它时,出现错误:

System.Data.OracleClient.OracleException:

System.Data.OracleClient.OracleException:

ORA-06550: line 1, column 7:" "PLS-00221: 'TESTING2' is not a procedure or is undefined".

ORA-06550:第 1 行,第 7 列:”“PLS-00221:'TESTING2' 不是过程或未定义”。

When I change it to do "Select testing() from dual" and change CommandType to Text, it works. What am I missing?

当我将其更改为“从双重选择测试()”并将 CommandType 更改为文本时,它可以工作。我错过了什么?

Dim oracleConn As OracleConnection = CreateConnection(<connection info here>)

    Dim oracleCmd As New OracleCommand()
    oracleCmd.Connection = oracleConn
    'oracleCmd.CommandText = "SELECT TESTING2() FROM DUAL" 'this works
    oracleCmd.CommandText = "TESTING2"   'this does not work

    oracleCmd.CommandType = CommandType.StoredProcedure

    'oracleCmd.ExecuteReader()  'also tried this
    Dim tmpVar As String = oracleCmd.ExecuteScalar()

create or replace FUNCTION testing2
RETURN VARCHAR2
AS      
begin
  return 'hello';
end;

采纳答案by Steve

I don't work with Oracle anymore, so I can't test it now, but you tell me if this example works or not

我不再使用 Oracle 了,所以我现在不能测试它,但是你告诉我这个例子是否有效

Dim oracleConn As OracleConnection = CreateConnection(<connection info here>)
Dim oracleCmd As New OracleCommand()
oracleCmd.Connection = oracleConn
oracleCmd.CommandText = "TESTING2"   
oracleCmd.CommandType = CommandType.StoredProcedure
Dim prm = new OracleParameter("returnvalue", OracleType.VarChar)
prm.Size = 1024
prm.Direction = ParameterDirection.ReturnValue
oracleCmd.Parameters.Add(prm)
oracleCmd.ExecuteNonQuery()

Console.WriteLine(prm.Value.ToString)

And by the way, I suppose that CreateConnection returns an OPEN connection right?

顺便说一句,我想 CreateConnection 返回一个 OPEN 连接对吗?