【问题标题】:Execute Oracle Stored Proc using .Net使用 .Net 执行 Oracle 存储过程
【发布时间】:2014-03-13 02:52:22
【问题描述】:

我创建了一个包:

create or replace PACKAGE merc
AS 
 TYPE resultcurtyp is REF CURSOR;
END merc;

然后是存储过程:

create or replace PROCEDURE merc_results
(
 testP IN VARCHAR2 DEFAULT NULL,
 CURSOR_ IN OUT merc.resultcurtyp

) AS 
BEGIN
    OPEN CURSOR_ FOR
    SELECT /*csv*/
    FR.*
    FROM DS.table1 FR 
    INNER JOIN DS.price PN ON PN.OBJECTID = FR.SOURCEID 
    WHERE FR.NAME = testP   
END merc_results;

调用存储过程表单时,.Net 代码给了我:

ORA-06550: line 1, column 15:
PLS-00222: no function with name 'merc' exists in this scope
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

我是否需要创建一个 包,从中存储调用,然后从 .Net 调用该包?我现在直接从代码中调用存储过程。 我以前没有使用过 oracle db。

【问题讨论】:

  • 是否有理由需要声明自己的弱类型游标,而不仅仅是声明 cursor_ 类型为 sys_refcursor?您真的希望cursor_ 参数为IN OUT 而不仅仅是OUT?你为什么在存储过程中使用/*csv*/ 提示——这只是一个SQL Developer 指令。你已经为 SQL Developer 标记了这个,这让我怀疑 csv 提示应该做一些功能性的事情?
  • 好吧,你没有显示 C# 调用代码。
  • @JustinCave,他并没有真正使用 csv 提示,他错过了加号,/*+csv*/ 所以这只是一个评论。
  • 看起来你要么使用包作为函数,要么你的包与你连接的架构不同

标签: c# oracle oracle11g oracle-sqldeveloper


【解决方案1】:

在 C# 中:

OracleCommand cmd = new OracleCommand("yourshema.merc.merc_results", Connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("testP", testP);
cmd.Parameters.Add("CURSOR_", OracleDbType.RefCursor).Direction = ParameterDirection.Output;
OracleDataAdapter da = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;

Oracle 包:

CREATE OR REPLACE PACKAGE merc
IS
    TYPE resultcurtyp IS REF CURSOR;
    PROCEDURE merc_results(
        testP IN VARCHAR2 DEFAULT NULL,
        CURSOR_ OUT resultcurtyp );
END;
/

CREATE OR REPLACE PACKAGE BODY merc
IS
  PROCEDURE merc_results(
    testP IN VARCHAR2 DEFAULT NULL,
    CURSOR_ OUT resultcurtyp )
  AS
  BEGIN
   OPEN CURSOR_ FOR SELECT
    FR.* FROM DS.table1 FR INNER JOIN DS.price PN ON PN.OBJECTID = FR.SOURCEID WHERE FR.NAME = testP;
  END merc_results;
END merc;
/

【讨论】:

    猜你喜欢
    • 2019-08-26
    • 1970-01-01
    • 2011-06-19
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    相关资源
    最近更新 更多