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;
1 个解决方案
#1
1
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连接吗?
#1
1
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连接吗?