Oracle Procedure - PLS-00306:参数的数量或类型错误

时间:2017-02-25 10:49:48

标签: oracle stored-procedures

我的执行程序出现以下错误:

Error starting at line : 1 in command -
exec p_matrika(2010,2.5,'26311330')
Error report -
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'P_MATRIKA'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

程序编译没有错误。我还检查了SQL语句,它可以正常工作,返回1行,所以我必须在程序本身做错了。我为SQL语句的一些混乱格式道歉。当我复制并粘贴它时,它以某种方式搞砸了。

create or replace PROCEDURE P_MATRIKA 
(
    leto IN NUMBER, 
    rating IN NUMBER,
    davcna IN VARCHAR2,
    unsec_out OUT NUMBER,
    supp_out OUT NUMBER,
    sec_out OUT NUMBER,
    unsec_limit OUT NUMBER,
    supp_limit OUT NUMBER,
    sec_limit OUT NUMBER,
    unsec_tenor OUT NUMBER,
    supp_tenor OUT NUMBER,
    sec_tenor OUT NUMBER
)
AS
    out_unsec NUMBER;
    out_supp NUMBER;
    out_sec NUMBER;
    limit_unsec NUMBER;
    limit_supp NUMBER;
    limit_sec NUMBER;
    tenor_unsec NUMBER;
    tenor_supp NUMBER;
    tenor_sec NUMBER;       
BEGIN
    with 
        matrika_osnova 
    as
    (
    select distinct a.par_davcna, nvl(a.unsecured,0) unsec_out,
                 nvl(a.supported,0) supp_out, nvl(a.secured,0) sec_out,
                 x.tip_sub, x.cispri, x.kraban, x.dolfinobv,
                 y.ltv_tip, y.rating, y.unsec_pct, q.supp_pct,
                 w.sec_pct, p.unsec_maxznes, s.sec_maxznes,
                 case when y.unsec_pct * nvl(x.cispri,0) > nvl(p.unsec_maxznes,0) then
                                     nvl(p.unsec_maxznes,0) - nvl(x.kraban,0) + (nvl(x.dolfinobv,0)/5)
                            else
                                    case when y.unsec_pct * nvl(x.cispri,0) - 
                                                        nvl(x.kraban,0) + (nvl(x.dolfinobv,0)/5) < 0 then
                                                        0
                                            else
                                                        y.unsec_pct * nvl(x.cispri,0) - nvl(x.kraban,0) + 
                                                        (nvl(x.dolfinobv,0)/5)
                                    end
                 end unsec_max,
                 case when q.supp_pct * nvl(x.cispri,0) > nvl(s.sec_maxznes,0) then
                                     nvl(s.sec_maxznes,0) - nvl(x.kraban,0) + (nvl(x.dolfinobv,0)/5)
                            else
                                    case when q.supp_pct * nvl(x.cispri,0) - nvl(x.kraban,0) + 
                                                        (nvl(x.dolfinobv,0)/5) < 0 then
                                                        0
                                            else
                                                        q.supp_pct * nvl(x.cispri,0) - nvl(x.kraban,0) + 
                                                        (nvl(x.dolfinobv,0)/5)
                                    end
                 end supp_max,
                 case when w.sec_pct * nvl(x.cispri,0) > nvl(s.sec_maxznes,0) then
                                     nvl(s.sec_maxznes,0) - nvl(x.kraban,0) + (nvl(x.dolfinobv,0)/5)
                            else
                                    case when w.sec_pct * nvl(x.cispri,0) - nvl(x.kraban,0) + 
                                                        (nvl(x.dolfinobv,0)/5) < 0 then
                                                        0
                                            else
                                                        w.sec_pct * nvl(x.cispri,0) - nvl(x.kraban,0) + 
                                                        (nvl(x.dolfinobv,0)/5)
                                    end
                 end sec_max,
                 d.unsec_tenor, e.supp_tenor, f.sec_tenor                               
    from sco_matrika_banka a
    inner join
                        (select b.tip_sub, b.par_davcna, b.cispri, b.kraban, b.dolfinobv
                         from scoring_gvin b
                         where b.leto = leto) x --IN parameter
    on a.par_davcna = x.par_davcna
    inner join 
                        (select a.tip_sub, a.ltv_tip, 
                         a.max_znesek unsec_maxznes
                         from sco_sif_ltv_maxznes a
                         where a.ltv_tip = 1) p
    on x.tip_sub = p.tip_sub
    inner join 
                        (select a.tip_sub, a.ltv_tip, 
                         a.max_znesek sec_maxznes
                         from sco_sif_ltv_maxznes a
                         where a.ltv_tip = 3) s
    on x.tip_sub = s.tip_sub
    inner join
                        (select a.tip_sub, a.ltv_tip, 
                                        a.rating, a.ltv_pct unsec_pct
                         from sco_sif_ltv_pct a
                         where a.ltv_tip = 1
                         and a.rating = rating) y --IN parameter
    on x.tip_sub = y.tip_sub
    inner join
                        (select a.tip_sub, a.ltv_tip, 
                                        a.rating, a.ltv_pct supp_pct
                         from sco_sif_ltv_pct a
                         where a.ltv_tip = 2
                         and a.rating = rating) q --IN parameter
    on x.tip_sub = y.tip_sub
    inner join
                        (select a.tip_sub, a.ltv_tip, 
                                        a.rating, a.ltv_pct sec_pct
                         from sco_sif_ltv_pct a
                         where a.ltv_tip = 3
                         and a.rating = rating) w --IN parameter
    on x.tip_sub = y.tip_sub
    inner join
                         (select a.tip_sub, a.tenor unsec_tenor
                            from sco_sif_ltv_tenor a
                            where a.ltv_tip = 1) d
    on x.tip_sub = d.tip_sub
    inner join
                         (select a.tip_sub, a.tenor supp_tenor
                            from sco_sif_ltv_tenor a
                            where a.ltv_tip = 2) e
    on x.tip_sub = e.tip_sub
    inner join
                         (select a.tip_sub, a.tenor sec_tenor
                            from sco_sif_ltv_tenor a
                            where a.ltv_tip = 3) f
    on x.tip_sub = f.tip_sub
    where a.par_davcna = davcna) --IN parameter

    select a.unsec_out, a.supp_out, a.sec_out,
                 case when a.unsec_max - a.unsec_out < 0 then
                                     0
                            else
                                     a.unsec_max - a.unsec_out
                 end unsec_limit,
                             case when a.supp_max - a.supp_out < 0 then
                                     0
                            else
                                     a.supp_max - a.supp_out
                 end supp_limit,
                             case when a.sec_max - a.sec_out < 0 then
                                     0
                            else
                                     a.sec_max - a.sec_out
                 end sec_limit,
                 a.unsec_tenor, a.supp_tenor, a.sec_tenor
                 into
                 out_unsec, out_supp, out_sec, limit_unsec, limit_supp,
                 limit_sec, tenor_unsec, tenor_supp, tenor_sec
    from matrika_osnova a;

    unsec_out := out_unsec;
    supp_out := out_supp;
    sec_out := out_sec;
    unsec_limit := limit_unsec;
    supp_limit := limit_supp;
    sec_limit := limit_sec;
    unsec_tenor := tenor_unsec;
    supp_tenor := tenor_supp;
    sec_tenor := tenor_sec;             
END P_MATRIKA;

2 个答案:

答案 0 :(得分:1)

您的调用中必须具有相同数量的参数,因为在过程指定中存在形式参数(除非存在任何默认的IN参数,这不是这里的情况)。每个OUT参数必须具有来自调用者的相应变量才能输入值。您的程序有12个正式参数。目前您正在为三个IN参数提供值,但您没有提供变量来接受九个OUT参数。

您可以使用在同一个匿名块中声明的本地PL / SQL变量作为您的调用,或者 - 可能更有用且接近您的C#调用 - 绑定变量,这些变量在SQL * Plus或SQL Developer中(基于您对{的使用) {1}})您可以使用exec命令进行定义:

variable

例如,您可以在脚本的后续代码中使用绑定变量,并且可以通过您的调用在C#中使用它们。

设置测试有点麻烦,尽管SQL Developer可以对其进行半自动化。它还假设总会有一个结果,你说的就是这种情况,但如果没有结果或多于一个,你将从程序中得到一个例外。

(顺便提一下,您的过程中不需要局部变量;您的查询可以直接选择variable out_unsec NUMBER; variable out_supp NUMBER; variable out_sec NUMBER; variable limit_unsec NUMBER; variable limit_supp NUMBER; variable limit_sec NUMBER; variable tenor_unsec NUMBER; variable tenor_supp NUMBER; variable tenor_sec NUMBER; exec p_matrika(2010, 2.5, '26311330', :out_unsec, :out_supp, :out_sec, - :limit_unsec, :limit_supp, :limit_sec, :tenor_unsec, :tenor_supp, :tenor_sec); print out_unsec print out_supp ... ,您不需要单独的中间unsec_out。您可能还需要思考关于命名约定,例如out_unsec用于形式参数,ans p_out_unsec用于局部变量,如果您决定保留它。使您更容易看到您正在使用和修改的内容,您当前的名字很容易混淆。)

另一种方法是使用引用游标:

l_out_unsec

然后你可以这样做:

create or replace PROCEDURE P_MATRIKA 
(
    leto IN NUMBER, 
    rating IN NUMBER,
    davcna IN VARCHAR2,
    p_refcur OUT SYS_REFCURSOR
)
AS
BEGIN
    OPEN p_refcur FOR
    ... your query
END;

或者你可以使它成为一个返回引用游标的函数。然后,您的C#代码可以像处理任何其他结果集一样处理绑定的引用游标。

答案 1 :(得分:0)

好的,我设法解决了我的问题。或者更好地说,Alex Poole解决了它,所以对他赞不绝口: - )。

Oracle存储过程:

create or replace PROCEDURE P_MATRIKA 
(
    p_leto IN NUMBER, 
    p_rating IN NUMBER,
    p_davcna IN VARCHAR2,
    p_refcur OUT SYS_REFCURSOR
)
IS
BEGIN
    OPEN p_refcur FOR
    with 
        matrika_osnova 
    as
    (
    select distinct a.par_davcna, nvl(a.unsecured,0) unsec_out,
                 nvl(a.supported,0) supp_out, nvl(a.secured,0) sec_out,
                 x.tip_sub, x.cispri, x.kraban, x.dolfinobv,
                 y.ltv_tip, y.rating, y.unsec_pct, q.supp_pct,
                 w.sec_pct, p.unsec_maxznes, s.sec_maxznes,
                 case when y.unsec_pct * nvl(x.cispri,0) > nvl(p.unsec_maxznes,0) then
                                     nvl(p.unsec_maxznes,0) - nvl(x.kraban,0) + (nvl(x.dolfinobv,0)/5)
                            else
                                    case when y.unsec_pct * nvl(x.cispri,0) - 
                                                        nvl(x.kraban,0) + (nvl(x.dolfinobv,0)/5) < 0 then
                                                        0
                                            else
                                                        y.unsec_pct * nvl(x.cispri,0) - nvl(x.kraban,0) + 
                                                        (nvl(x.dolfinobv,0)/5)
                                    end
                 end unsec_max,
                 case when q.supp_pct * nvl(x.cispri,0) > nvl(s.sec_maxznes,0) then
                                     nvl(s.sec_maxznes,0) - nvl(x.kraban,0) + (nvl(x.dolfinobv,0)/5)
                            else
                                    case when q.supp_pct * nvl(x.cispri,0) - nvl(x.kraban,0) + 
                                                        (nvl(x.dolfinobv,0)/5) < 0 then
                                                        0
                                            else
                                                        q.supp_pct * nvl(x.cispri,0) - nvl(x.kraban,0) + 
                                                        (nvl(x.dolfinobv,0)/5)
                                    end
                 end supp_max,
                 case when w.sec_pct * nvl(x.cispri,0) > nvl(s.sec_maxznes,0) then
                                     nvl(s.sec_maxznes,0) - nvl(x.kraban,0) + (nvl(x.dolfinobv,0)/5)
                            else
                                    case when w.sec_pct * nvl(x.cispri,0) - nvl(x.kraban,0) + 
                                                        (nvl(x.dolfinobv,0)/5) < 0 then
                                                        0
                                            else
                                                        w.sec_pct * nvl(x.cispri,0) - nvl(x.kraban,0) + 
                                                        (nvl(x.dolfinobv,0)/5)
                                    end
                 end sec_max,
                 d.unsec_tenor, e.supp_tenor, f.sec_tenor                               
    from sco_matrika_banka a
    inner join
                        (select b.tip_sub, b.par_davcna, b.cispri, b.kraban, b.dolfinobv
                         from scoring_gvin b
                         where b.leto = p_leto) x --IN parameter
    on a.par_davcna = x.par_davcna
    inner join 
                        (select a.tip_sub, a.ltv_tip, 
                         a.max_znesek unsec_maxznes
                         from sco_sif_ltv_maxznes a
                         where a.ltv_tip = 1) p
    on x.tip_sub = p.tip_sub
    inner join 
                        (select a.tip_sub, a.ltv_tip, 
                         a.max_znesek sec_maxznes
                         from sco_sif_ltv_maxznes a
                         where a.ltv_tip = 3) s
    on x.tip_sub = s.tip_sub
    inner join
                        (select a.tip_sub, a.ltv_tip, 
                                        a.rating, a.ltv_pct unsec_pct
                         from sco_sif_ltv_pct a
                         where a.ltv_tip = 1
                         and a.rating = p_rating) y --IN parameter
    on x.tip_sub = y.tip_sub
    inner join
                        (select a.tip_sub, a.ltv_tip, 
                                        a.rating, a.ltv_pct supp_pct
                         from sco_sif_ltv_pct a
                         where a.ltv_tip = 2
                         and a.rating = p_rating) q --IN parameter
    on x.tip_sub = y.tip_sub
    inner join
                        (select a.tip_sub, a.ltv_tip, 
                                        a.rating, a.ltv_pct sec_pct
                         from sco_sif_ltv_pct a
                         where a.ltv_tip = 3
                         and a.rating = p_rating) w --IN parameter
    on x.tip_sub = y.tip_sub
    inner join
                         (select a.tip_sub, a.tenor unsec_tenor
                            from sco_sif_ltv_tenor a
                            where a.ltv_tip = 1) d
    on x.tip_sub = d.tip_sub
    inner join
                         (select a.tip_sub, a.tenor supp_tenor
                            from sco_sif_ltv_tenor a
                            where a.ltv_tip = 2) e
    on x.tip_sub = e.tip_sub
    inner join
                         (select a.tip_sub, a.tenor sec_tenor
                            from sco_sif_ltv_tenor a
                            where a.ltv_tip = 3) f
    on x.tip_sub = f.tip_sub
    where a.par_davcna = p_davcna) --IN parameter

    select a.unsec_out, a.supp_out, a.sec_out,
                 case when a.unsec_max - a.unsec_out < 0 then
                                     0
                            else
                                     a.unsec_max - a.unsec_out
                 end unsec_limit,
                             case when a.supp_max - a.supp_out < 0 then
                                     0
                            else
                                     a.supp_max - a.supp_out
                 end supp_limit,
                             case when a.sec_max - a.sec_out < 0 then
                                     0
                            else
                                     a.sec_max - a.sec_out
                 end sec_limit,
                 a.unsec_tenor, a.supp_tenor, a.sec_tenor
    from matrika_osnova a;
END;

C#代码:

public void LoadMatrika(string davcna)
{
    using (OracleConnection conn = CreateConnection())
    {
        using (OracleCommand cmd = new OracleCommand())
        {
            cmd.Connection = conn;
            cmd.CommandText = "P_MATRIKA";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new OracleParameter("p_leto", Util.letoc));
            cmd.Parameters.Add(new OracleParameter("p_rating", Score.Rating));
            cmd.Parameters.Add(new OracleParameter("p_davcna", davcna));
            cmd.Parameters.Add(new OracleParameter("p_refcur", OracleDbType.RefCursor, ParameterDirection.Output));
            cmd.BindByName = true;

            using (OracleDataReader dr = cmd.ExecuteReader())
            {
                if (dr.HasRows)
                {
                    dr.Read();
                    Matrika.UnsecuredOut = dr.GetDecimal(0);
                    Matrika.SupportedOut = dr.GetDecimal(1);
                    Matrika.SecuredOut = dr.GetDecimal(2);
                    Matrika.UnsecuredLimit = dr.GetDecimal(3);
                    Matrika.SupportedLimit = dr.GetDecimal(4);
                    Matrika.SecuredLimit = dr.GetDecimal(5);
                    Matrika.UnsecuredTenor = dr.GetDecimal(6);
                    Matrika.SupportedTenor = dr.GetDecimal(7);
                    Matrika.SecuredTenor = dr.GetDecimal(8);
                }
            }
        }
    }
}