1

我对甲骨文很生气。我一直在努力从 oracle 数据库中获取两个值(输出参数)。我需要根据 paymentType 和 vendor 获取两个值(o_unallocated_ledgercode 和 o_allocated_ledgercode)。

问题是:这些值在 C# 中仍然为空。我无法从数据库中获取这些值。可能有什么问题?请看我的 c# 代码。我需要别人的不同观点。我可能错过了什么。请给我代码示例。谢谢!

甲骨文包:

CREATE OR REPLACE package body BANKIMPORTS.pkg_vendor_config as

PROCEDURE get_ledger_codes (i_vendor in varchar2,
                            i_payment_type in varchar2,
                            o_allocated_ledgercode out varchar2,
                            o_unallocated_ledgercode out varchar2) is
BEGIN
  IF UPPER (i_payment_type) = 'SUBS' THEN
    SELECT CV.CONFIGVALUE
      INTO o_unallocated_ledgercode
      FROM VENDOR v
      JOIN VENDOR_CONFIG_ITEM_VALUE CV ON v.Id = CV.Vendor_Id
      JOIN CONFIG_ITEMS c ON CV.Config_Item_Id = c.Config_Item_Id
      WHERE C.ITEMNAME = 'Subs_Unallocated_LederCode'
        AND V.DESCRIPTION = i_vendor;

    SELECT CV.CONFIGVALUE
      INTO o_allocated_ledgercode
      FROM VENDOR v
      JOIN VENDOR_CONFIG_ITEM_VALUE CV ON v.Id = CV.Vendor_Id
      JOIN CONFIG_ITEMS c ON CV.Config_Item_Id = c.Config_Item_Id
      WHERE C.ITEMNAME = 'Subs_Payment_LedgerCode'
        AND V.DESCRIPTION = i_vendor;
  ELSIF UPPER (i_payment_type) = 'GOTV'
    ........same select statement as above

C#代码:

using (DbCommand command = connection.CreateCommand())
  {
  try
    {
    command.CommandType = CommandType.StoredProcedure;
    command.CommandText = "pkg_vendor_config.get_ledger_codes";
    command.AddParameter("i_vendor", DbType.String, vendor, ParameterDirection.Input);
    command.AddParameter("i_payment_type", DbType.String, paymentType, ParameterDirection.Input);

    command.AddParameter("o_unallocated_ledgercode", DbType.String, ParameterDirection.Output);
    command.AddParameter("o_allocated_ledgercode", DbType.String, ParameterDirection.Output);

    command.ExecuteNonQuery();

    var unallocated = (String)command.Parameters["o_unallocated_ledgercode"].Value;
    var allocated = (String)command.Parameters["o_allocated_ledgercode"].Value;
4

2 回答 2

1

tl;博士; 我认为您只需要设置参数的 Size 属性。

根据 docs.oracle.com 的OracleParameter 类对象页面,当我们单击 Size 属性时,我们看到参数类型的默认最大大小为 0!

当我设置所有 Varchar2 参数时,我不再获得空值。我已将它们设置为 50,但这将取决于您的 VENDOR_CONFIG_ITEM_VALUE.CONFIGVALUE 属性的限制设置为。

C#代码:

using (DbCommand command = connection.CreateCommand())
{
    connection.Open();

    command.CommandType = CommandType.StoredProcedure;
    command.CommandText = "pkg_vendor_config.get_ledger_codes";

    OracleParameter[] yourParams = new[] 
    { 
        new OracleParameter("i_vendor", OracleDbType.Varchar2, "subs", ParameterDirection.Input), 
        new OracleParameter("i_payment_type", OracleDbType.Varchar2, "cold hard cash", ParameterDirection.Input),
        new OracleParameter("o_allocated_ledgercode", OracleDbType.Varchar2, ParameterDirection.Output), 
        new OracleParameter("o_unallocated_ledgercode", OracleDbType.Varchar2, ParameterDirection.Output)
    };

    foreach(var param in yourParams)
    {
         param.Size = 50;
    }

    command.Parameters.AddRange (yourParams);

    command.ExecuteNonQuery();

    var unallocated = (String)command.Parameters["o_unallocated_ledgercode"].Value.ToString();
    var allocated = (String)command.Parameters["o_allocated_ledgercode"].Value.ToString();

    connection.Close();
}

甲骨文包:

CREATE OR REPLACE Procedure pkg_vendor_config.get_ledger_codes(i_vendor in varchar2,
                                i_payment_type in varchar2,
                                o_allocated_ledgercode out varchar2,
                                o_unallocated_ledgercode out varchar2) is
BEGIN
        SELECT 'Another value'
        INTO o_unallocated_ledgercode
        FROM dual;

        SELECT 'Some value'
        INTO o_allocated_ledgercode
        FROM dual;

    /* I'll assume this all behaved for you

    IF UPPER (i_payment_type) = 'SUBS' THEN
    SELECT CV.CONFIGVALUE
      INTO o_unallocated_ledgercode
      FROM VENDOR v
      JOIN VENDOR_CONFIG_ITEM_VALUE CV ON v.Id = CV.Vendor_Id
      JOIN CONFIG_ITEMS c ON CV.Config_Item_Id = c.Config_Item_Id
      WHERE C.ITEMNAME = 'Subs_Unallocated_LederCode'
        AND V.DESCRIPTION = i_vendor;

    SELECT CV.CONFIGVALUE
      INTO o_allocated_ledgercode
      FROM VENDOR v
      JOIN VENDOR_CONFIG_ITEM_VALUE CV ON v.Id = CV.Vendor_Id
      JOIN CONFIG_ITEMS c ON CV.Config_Item_Id = c.Config_Item_Id
      WHERE C.ITEMNAME = 'Subs_Payment_LedgerCode'
        AND V.DESCRIPTION = i_vendor;
  ELSIF UPPER (i_payment_type) = 'GOTV'
    ........same select statement as above
 */

end;

免责声明:

我似乎无法准确地重新创建您的 C# 设置;可能已经过时了,因为它已经快 6 年了。但这已确认有效

于 2019-02-14T23:21:49.543 回答
0

您只是设置变量的值。如果你想返回一些东西使用函数。

FUNCTION get_ledger_codes
( 
  i_vendor in varchar2
, i_payment_type in varchar2
) RETURN VARCHAR2
is
    o_allocated_ledgercode   varchar2(100);
    o_unallocated_ledgercode varchar2(100);
BEGIN
    IF UPPER (i_payment_type) = 'SUBS'  THEN
        SELECT CV.CONFIGVALUE
        INTO o_unallocated_ledgercode
        FROM VENDOR v
             JOIN VENDOR_CONFIG_ITEM_VALUE CV ON v.Id = CV.Vendor_Id
             JOIN CONFIG_ITEMS c ON CV.Config_Item_Id = c.Config_Item_Id
        WHERE     C.ITEMNAME = 'Subs_Unallocated_LederCode'
             AND V.DESCRIPTION = i_vendor;

        SELECT CV.CONFIGVALUE
        INTO o_allocated_ledgercode
        FROM VENDOR v
             JOIN VENDOR_CONFIG_ITEM_VALUE CV ON v.Id = CV.Vendor_Id
             JOIN CONFIG_ITEMS c ON CV.Config_Item_Id = c.Config_Item_Id
        WHERE     C.ITEMNAME = 'Subs_Payment_LedgerCode'
             AND V.DESCRIPTION = i_vendor;

    ELSIF UPPER (i_payment_type) = 'GOTV'
        ........same select statement as above

    RETURN o_allocated_ledgercode || ',' || o_unallocated_ledgercode;
END;
于 2013-06-11T12:02:30.313 回答