简体   繁体   English

没有参数就无法执行sys_refcursor函数

[英]Can not execute a sys_refcursor function without parameters

I have this sys_refcursor function in a package 我在包装中有这个sys_refcursor函数

function frcBaanCompanies return SYS_REFCURSOR is
 x sys_refcursor;
begin
  open x for select t$comp, t$cpnm from baan.tttaad100000 order by t$comp;
  return x;
end;

and a net method calling this as so 和这样的净方法

listBox1.DataSource = lO.fRefCursor("priceWorx.frcBaanCompanies", null, false).Tables[0];

Here's how I call the function: 这是我调用该函数的方式:

public DataSet fRefCursor(String refCursorName, IDictionary<string, string> prms, bool leaveConnectionOpen = true)
{
    try
    {
        using (OracleCommand cmd = new OracleCommand("", conn))
        {
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = refCursorName;
            if (prms!=null) SetupParams(refCursorName, cmd, prms);
            using (OracleDataAdapter da = new OracleDataAdapter(cmd))
            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                    cmd.Connection = conn;
                }
                using (DataSet ds = new DataSet())
                {
                    da.Fill(ds);
                    return ds;
                }
            }
        }
    }
    catch (Exception ex)
    {
        Debugger.Break();
        Debug.WriteLine(ex);
        return null;
    }
    finally
    {
        if (!leaveConnectionOpen) conn.Close();
    }
}

The same method works fine when called with parameters(some other cursor function, but fails with 使用参数调用时,相同的方法可以正常工作(其他游标函数,但使用时失败

ORA-06550: line 1, column 7: PLS-00221: 'FRCBAANCOMPANIES' is not a procedure or is undefined ORA-06550: line 1, column 7: PL/SQL: Statement ignored ORA-06550:第1行,第7列:PLS-00221:“ FRCBAANCOMPANIES”不是过程或未定义ORA-06550:第1行,第7列:PL / SQL:语句被忽略

works fine when executed within (Oracle) sql developer too.. 在(Oracle)sql developer中执行时,也可以正常工作。

What am I doing wrong ? 我究竟做错了什么 ?

This is because you can't call a function without parameters, but you could call it with null parameters. 这是因为您不能在没有参数的情况下调用函数,但是可以在具有空参数的情况下调用它。 What you are currently calling when you do not input any parameters is: 不输入任何参数时当前正在调用的是:

FRCBAANCOMPANIES;

and this is different to 这与

variable := FRCBAANCOMPANIES;

In the first case oracle is looking for a procedure without any return and in the second case you call your function. 在第一种情况下,oracle正在寻找没有任何返回的过程,而在第二种情况下,您将调用函数。 So you have to set the return parameter also if you do not need it. 因此,如果不需要,还必须设置return参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM