0

我想在 C#/.NET 中使用以下存储过程:

CREATE OR REPLACE
procedure contact_return(
    v_urn IN VARCHAR2,
    p_cursor OUT SYS_REFCURSOR )
AS
  sql_statement VARCHAR2(4000) := '        

  SELECT URN,
    FIRSTNAME,
    LASTNAME,
    TITLE,
    MOBILE,
    WORK,
    EMAIL
  FROM CONTACT
  WHERE urn = NVL(:1,v_contact_urn)';
BEGIN
  OPEN p_cursor FOR sql_statement USING v_urn;

使用此代码,我收到错误消息:PLS-00201:必须声明标识符“CONTACT_RETURN”

        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "contact_return";
        cmd.Parameters.Add("v_urn", OracleDbType.Int64).Value = null;
        cmd.Parameters.Add("p_cursor", OracleDbType.RefCursor).Direction = ParameterDirection.Output;

据我所知,我已经正确声明了存储过程('contact_return'),所以无法弄清楚为什么会出现这个错误。

任何帮助将不胜感激,谢谢:)

4

2 回答 2

1

不应该;这

CREATE OR REPLACE
procedure contact_return(
    v_urn IN VARCHAR2,
    p_cursor OUT SYS_REFCURSOR )
AS
  sql_statement VARCHAR2(4000) := '        

  SELECT URN,
    FIRSTNAME,
    LASTNAME,
    TITLE,
    MOBILE,
    WORK,
    EMAIL
  FROM CONTACT
  WHERE urn = NVL(:1,v_contact_urn)';
BEGIN
  OPEN p_cursor FOR sql_statement USING v_urn;

CREATE OR REPLACE
procedure contact_return(
    v_urn IN VARCHAR2,
    p_cursor OUT SYS_REFCURSOR )
AS
BEGIN
  DECLARE sql_statement VARCHAR2(4000) := '';        

  SELECT URN,
    FIRSTNAME,
    LASTNAME,
    TITLE,
    MOBILE,
    WORK,
    EMAIL
  FROM CONTACT
  WHERE urn = NVL(:1,v_contact_urn)';

  OPEN p_cursor FOR sql_statement USING v_urn;

END;
于 2013-09-04T16:09:22.587 回答
1

要调用包含OUT类型参数的 Oracle 存储过程,SYS_REFCURSOR您需要使用ODP.NET
模板解决方案将是这样的:

using Oracle.DataAccess;
using Oracle.DataAccess.Client;

public DataTable Call_contact_return(string v_urn_value)
            {
                using (OracleConnection cn = new OracleConnection(DatabaseHelper.GetConnectionString()))
                {
                    OracleDataAdapter da = new OracleDataAdapter();
                    OracleCommand cmd = new OracleCommand();
                    cmd.Connection = cn;
                    cmd.InitialLONGFetchSize = 1000;
                    cmd.CommandText = DatabaseHelper.GetDBOwner() + "contact_return";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("v_urn", OracleDbType.Char).Value = v_urn_value;                    
                    cmd.Parameters.Add("p_cursor", OracleDbType.RefCursor).Direction = ParameterDirection.Output;

                    da.SelectCommand = cmd;
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    return dt;
                }
            }
于 2013-09-04T17:12:00.993 回答