ORA-06550 第 10 行,第 41 列:PLS-00103:遇到以下符号之一时遇到符号“,”:

ORA-06550 line 10, column 41: PLS-00103: Encountered the symbol "," when expecting one of the following:

我正在从 C# 执行一个匿名 PL/SQL 块,但我收到如下错误:

ORA-06550 line 10, column 41: PLS-00103: Encountered the symbol "," when expecting one of the following:

我的代码:

OracleDB AppConn = new OracleDB();
OracleDataReader eligiblereader = null;

 string id = "2304502001101";
 long provider = 667;
 long policy = 150;
 DateTime to = Convert.ToDateTime("2015/05/06");
using (OracleConnection con = AppConn.Connection)
{
 OracleCommand cmd = con.CreateCommand();

 cmd.Connection = con;
cmd.CommandText = @"declare 
                  p_id   VARCHAR2;
                  p_policy_id   NUMBER;
                  p_provider_id   NUMBER;
                  p_date        DATE;
                  p_tob         tob_type;
                 begin
                                 pbm_pkg.get_member_tob(p_id,p_policy_id,p_provider_id,p_date,p_tob);
open :refcur for select tob_type.benefit_id from dual;
end;";
OracleParameter p = cmd.Parameters.Add(
                         "rs", OracleDbType.RefCursor,
                         DBNull.Value,
                         ParameterDirection.Output);
 OracleParameter p_id = new OracleParameter();
  p_id.OracleDbType = OracleDbType.Varchar2;
  p_id.Direction = ParameterDirection.Input;
  p_id.Value = id;

OracleParameter p_policy_id = new OracleParameter();
p_policy_id.OracleDbType = OracleDbType.Int64;
p_policy_id.Direction = ParameterDirection.Input;
p_policy_id.Value = policy;

OracleParameter p_provider_id = new OracleParameter();
p_provider_id.OracleDbType = OracleDbType.Int64;
p_provider_id.Direction = ParameterDirection.Input;
p_provider_id.Value = provider;

OracleParameter p_date = new OracleParameter();
p_date.OracleDbType = OracleDbType.Date;
p_date.Direction = ParameterDirection.Input;
p_date.Value = to;
cmd.Parameters.Add(p_id);
cmd.Parameters.Add(p_policy_id);
cmd.Parameters.Add(p_provider_id);
cmd.Parameters.Add(p_date);

    try
    {
    con.Open();

    cmd.ExecuteNonQuery();

eligiblereader = ((OracleRefCursor)cmd.Parameters[4].Value).GetDataReader();

 while (eligiblereader.Read())
 {
  string id = eligiblereader.GetValue(0).ToString();

}
}
catch (Exception ex)
 {
}
finally
 {
con.Close();
}
return View();
        }

执行命令时出现错误'cmd.ExecuteNonQuery();'

我想我在匿名块中遗漏了一些东西。

p_id VARCHAR2;

这肯定是不正确的语法,会引发编译错误。

重现错误:

SQL> DECLARE
  2    p_id VARCHAR2;
  3  BEGIN
  4    NULL;
  5  END;
  6  /
  p_id VARCHAR2;
       *
ERROR at line 2:
ORA-06550: line 2, column 8:
PLS-00215: String length constraints must be in range (1 .. 32767)


SQL>

因此,您必须在 1 .. 32767.

之间指定 字符串长度限制

解法:

指定字符串变量所需的长度。

SQL> DECLARE
  2    p_id VARCHAR2(20);
  3  BEGIN
  4    NULL;
  5  END;
  6  /

PL/SQL procedure successfully completed.

SQL>

open :refcur for select tob_type.benefit_id from dual;

您需要为 refcursor 声明绑定变量。

例如,

SQL> var r refcursor
SQL>
SQL> BEGIN
  2    OPEN :r FOR SELECT empno,ename FROM emp;
  3  END;
  4  /

PL/SQL procedure successfully completed.

SQL> print r

     EMPNO ENAME
---------- ----------
      7369 SMITH
      7499 ALLEN
      7521 WARD
      7566 JONES
      7654 MARTIN
      7698 BLAKE
      7782 CLARK
      7788 SCOTT
      7839 KING
      7844 TURNER
      7876 ADAMS
      7900 JAMES
      7902 FORD
      7934 MILLER

14 rows selected.

SQL>