在PLS-00221中从VB执行Oracle功能结果

时间:2019-06-05 16:34:43

标签: vb.net oracle plsql

我有一个下面定义的函数:

 FUNCTION foo (
        param1      IN    VARCHAR2(20)
      , param2      IN    VARCHAR2(255)
      , param3      IN    VARCHAR2(3)
      , param4      IN    VARCHAR2(4)
      , param5      OUT   VARCHAR2(1000)
   )
   RETURN INTEGER IS
   BEGIN
   --Function Code Here
   END foo;

我想用表格调用,我在下面做了以下尝试:

Dim conn As New Oracle.DataAccess.Client.OracleConnection()
conn.ConnectionString = DBOraConnectString
Dim cmd As New OracleCommand
Dim param As OracleParameter

cmd.Connection = conn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "foo"

param = New Oracle.DataAccess.Client.OracleParameter
param.ParameterName = "param1"
param.DbType = DbType.AnsiString
param.Value = val1
param.Size = 20
param.Direction = ParameterDirection.Input
cmd.Parameters.Add(param)

param = New Oracle.DataAccess.Client.OracleParameter
param.ParameterName = "param2"
param.DbType = DbType.AnsiString
param.Value = val2
param.Size = 255
param.Direction = ParameterDirection.Input
cmd.Parameters.Add(param)

param = New Oracle.DataAccess.Client.OracleParameter
param.ParameterName = "param3"
param.DbType = DbType.AnsiString
param.Value = val3
param.Size = 3
param.Direction = ParameterDirection.Input
cmd.Parameters.Add(param)

param = New Oracle.DataAccess.Client.OracleParameter
param.ParameterName = "param4"
param.DbType = DbType.AnsiString
param.Value = val4
param.Size = 4
param.Direction = ParameterDirection.Input
cmd.Parameters.Add(param)

param = New Oracle.DataAccess.Client.OracleParameter
param.ParameterName = "param5"
param.DbType = DbType.AnsiString
param.Size = 1000
param.Direction = ParameterDirection.Output
cmd.Parameters.Add(param)

conn.Open()
Try
    cmd.ExecuteNonQuery()
    Dim vStr As String
    vStr = cmd.Parameters.Item("outVal").Value.ToString
Catch ex As Exception
    MessageBox.Show(ex.Message)
End Try
conn.Close()

运行此命令将导致以下错误:

ORA-06550: line 1 column 7:
PLS-00221: 'FOO' is not a procedure or is undefined
ORA-06550: line 1 column 7:
PL/SQL: Statement ignored

我不明白为什么会这样。我与架构的连接是正确的,并且我的函数已编译并正确定义,所以为什么不执行它?

1 个答案:

答案 0 :(得分:1)

您可以像这样紧凑地编写代码:

Dim conn As New Oracle.DataAccess.Client.OracleConnection()
conn.ConnectionString = DBOraConnectString
Dim cmd As New OracleCommand

cmd.Connection = conn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "foo"

cmd.Parameters.Add("outVal", ParameterDirection.ReturnValue, OracleDbType.Int32)
cmd.Parameters.Add("param1", ParameterDirection.Input, OracleDbType.Varchar2, 20).Value = val1
cmd.Parameters.Add("param2", ParameterDirection.Input, OracleDbType.Varchar2, 255).Value = val2
cmd.Parameters.Add("param3", ParameterDirection.Input, OracleDbType.Varchar2, 3).Value = val3
cmd.Parameters.Add("param4", ParameterDirection.Input, OracleDbType.Varchar2, 4).Value = val4
cmd.Parameters.Add("param5", ParameterDirection.Output, OracleDbType.Varchar2, 1000)