1

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

System.Data.OracleClient.OracleException:

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

当我将其更改为“从双重选择测试()”并将 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;
4

1 回答 1

1

我不再使用 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)

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

于 2013-06-10T14:41:00.917 回答