【问题标题】:What should be the DbType in case of oracle raw output parameter如果是 oracle 原始输出参数,DbType 应该是什么
【发布时间】:2017-09-19 09:24:22
【问题描述】:

我正在使用 C# .net 4.5.2 并使用 oracle DB。 我正在调用一个具有 RAW 输出参数 (pPF) 的函数:

FUNCTION GET_ACCESS_CONTEXT(pTId     IN NUMBER,
                            pUId       IN RAW,
                            pOId     IN RAW,
                            pFId     IN NUMBER,
                            pPF OUT RAW) RETURN RAW IS
  TYPE IDS_TP IS TABLE OF RAW(32);
  IDS IDS_TP;
BEGIN
  WITH BASE AS(
    select fl.*

      from t_folders_access fa
     inner join t_folders_links fl on fl.tenant_id = fa.tenant_id
                                  and fl.from_family_id = fa.family_id
                                  and fl.from_object_id = fa.object_id

     where fa.user_object_id = pUId
       and fa.tenant_id = pTId
       and fa.family_id = 12345
       and fl.deleted_object_flag = 0
       and fl.from_family_id = 12345
       and fl.family_id = 54321)
      select base.from_object_id BULK COLLECT
        INTO IDS
        from base
       start with base.family_id = 54321
              and base.to_family_id = 12345
              and base.to_object_id = pOId
      connect by nocycle prior base.from_object_id = base.to_object_id
             and base.family_id = 54321;


  IF IDS.LAST = 0 OR IDS is null or IDS.LAST is null THEN
    pPF := null;

    DBMS_OUTPUT.put_line ('return ' || pOId);
    return pOId;
  else
  DBMS_OUTPUT.put_line ('return ' || (IDS(IDS.FIRST)));
    pPF := IDS(IDS.FIRST);
    DBMS_OUTPUT.put_line ('return ' || IDS(IDS.LAST));
    return IDS(IDS.LAST);
  end if;
END;

在我的代码中,我初始化输出参数:

DbType = DbType.Guid,
Size = 32,
Direction = ParameterDirection.Output,
ParameterName = "pPF"

当我从我的 c# 代码调用函数时,我得到了这个异常(当我使用相同的参数直接运行函数时没有异常......):“ORA-06502: PL/SQL: numeric or值错误:原始变量长度太长”, 从这一行:pPF := IDS(IDS.FIRST);IDS(IDS.FIRST) 的值为 5093A4805899EB448F96BF9976F230AF。 我尝试了不同的 DbType,但没有帮助。

我做错了什么?

【问题讨论】:

  • 能不能显示完整的功能代码?

标签: c# oracle output-parameter dbtype


【解决方案1】:

原来我们的系统中有一个愚蠢的错误,但也许这可以帮助其他人: 我的输出参数的“Direction”属性值被“ParameterDirection.Input”值覆盖。 当我修复它时,即使使用 DBType:'Binary' 和 'String' 也能正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-25
    • 1970-01-01
    • 2022-07-09
    • 1970-01-01
    • 2018-04-17
    • 2021-10-25
    相关资源
    最近更新 更多