Oracle APEX 交互式报告中的错误 - ORA-01427:单行子查询返回多于一行

Posted

技术标签:

【中文标题】Oracle APEX 交互式报告中的错误 - ORA-01427:单行子查询返回多于一行【英文标题】:Error in Oracle APEX interactive report - ORA-01427: single-row subquery returns more than one row 【发布时间】:2018-11-27 09:54:27 【问题描述】:

我正在尝试使用以下查询创建交互式报告。

这在 SQLPLUS 中完美运行,但是当我在 APEX 中编写此查询并运行报告时,它会抛出错误:

ORA-01427: 单行子查询返回多于一行

        SELECT --count(*) --31335
           hou.name ORGANISATION_NAME,            asp.vendor_name SUPPLIER_NAME,              asa.vendor_id SUPPLIER_NUMBER,
          asa.country SUPPLIER_SITE_COUNTRY_CODE,              ft1.territory_short_name  SUPPLIER_SITE_COUNTRY_DESC,                 
          case when  nvl(asa.inactive_date,sysdate) >= sysdate then             'Active'               else             'Inactive'             End SUPPLIER_SITE_STATUS,
          cbbv.bank_name BANK_NAME,
          ieb.IBAN IBAN,
         (select nvl(ppf.full_name, fu.user_name) 
          from fnd_user fu,  per_all_people_f ppf
          where fu.user_id = ieb.created_by
          and ppf.person_id (+) = fu.employee_id ) CREATED_BY,
          ieb.creation_date  CREATION_DATE,
          (select nvl(ppf.full_name, fu.user_name) 
          from fnd_user fu,  per_all_people_f ppf
          where fu.user_id = ieb.last_updated_by
          and ppf.person_id (+) = fu.employee_id ) UPDATED_BY,
          payees.bank_charge_bearer BANK_CHARGE_BEARER

         FROM apps.iby_pmt_instr_uses_all instrument,
          apps.iby_account_owners owners,
          apps.iby_external_payees_all payees,
          apps.iby_ext_bank_accounts ieb,
          apps.ap_supplier_sites_all asa,
          apps.ap_suppliers asp,
          apps.ce_bank_branches_v cbbv, 
          hr_operating_units hou  ,  fnd_lookup_values flv,  
          fnd_territories_tl ft1,
          fnd_territories_tl ft2

        WHERE  owners.ext_bank_account_id = ieb.ext_bank_account_id
        AND owners.ext_bank_account_id = instrument.instrument_id(+)
        AND payees.ext_payee_id        = instrument.ext_pmt_party_id(+)
        AND payees.payee_party_id      = owners.account_owner_party_id
        AND payees.supplier_site_id    = asa.vendor_site_id
        AND asa.vendor_id              = asp.vendor_id
        AND cbbv.branch_party_id(+)    = ieb.branch_id  
        and payees.org_id = 101
        and hou.organization_id = PAYEES.ORG_ID
        and FLV.LOOKUP_CODE = asp.vendor_type_lookup_code
        and flv.lookup_type  = 'VENDOR TYPE'
        and ft1.territory_code(+) = asa.country
        and ft2.territory_code(+) = ieb.country_code
        and PAYEES.BANK_CHARGE_BEARER = 'SHA';

如果我只是取消注释最后一个 where 条件,则不会发生此错误,即 " --and PAYEES.BANK_CHARGE_BEARER = 'SHA'; "

最后一个条件甚至不是子查询,所以我无法理解为什么 APEX 会出现此错误。在 SQLPLUS 中一切正常。 此外,如果我在 APEX 应用程序生成器的 SQL Workshop 中运行查询,它也可以正常工作。只有在我们运行应用程序时才会出现此错误。

另外,如果我从查询中删除此条件,应用程序运行正常,但是当我过滤此值“SHA”时,它会给我同样的错误。如果我选择任何其他值,例如“OUR”,它就可以正常工作。

您能否建议我应该做些什么来避免这个错误。

【问题讨论】:

如果您保留最后一个条件 ('SHA'),但删除一个和/或两个 UPDATED_BY 和 CREATED_BY 查询,会发生什么情况?因为,这两个似乎是唯一明显的抛出 TOO_MANY_ROWS 的候选人。 【参考方案1】:

您的投影中有两个子查询:

(select nvl(ppf.full_name, fu.user_name) 
 from fnd_user fu,  per_all_people_f ppf
 where fu.user_id = ieb.created_by
 and ppf.person_id (+) = fu.employee_id ) CREATED_BY,

(select nvl(ppf.full_name, fu.user_name) 
 from fnd_user fu,  per_all_people_f ppf
 where fu.user_id = ieb.last_updated_by
 and ppf.person_id (+) = fu.employee_id ) UPDATED_BY,

其中一个或两个查询为特定用户/个人组合返回了多个记录。您的表似乎是 Oracle E-Business Suite 表。如果是这样,per_all_people_f 是一个日期跟踪表,并且对于给定的person_id 可能有多个记录。您应该在连接条件中添加一个附加谓词,以将 ppf 限制为每个 fu 的单个记录。如果您已在 ieb 中创建日期和更新日期,那么我会使用那些否则使用 sysdate:

(select nvl(ppf.full_name, fu.user_name) 
 from fnd_user fu
 left join per_all_people_f ppf
   on ppf.person_id = fu.employee_id
  and trunc(sysdate) between ppf.effective_start_date and ppf.effective_end_date
 where fu.user_id = ieb.created_by) CREATED_BY,

(select nvl(ppf.full_name, fu.user_name) 
 from fnd_user fu
 left join per_all_people_f ppf
   on ppf.person_id = fu.employee_id
  and trunc(ieb.creation_date) between ppf.effective_start_date and ppf.effective_end_date
 where fu.user_id = ieb.created_by) CREATED_BY,

updated by 的更改类似,但留给读者练习;)

【讨论】:

非常感谢...这确实发生了,因为 per_all_people_f 表中有多个记录。谢谢指点。

以上是关于Oracle APEX 交互式报告中的错误 - ORA-01427:单行子查询返回多于一行的主要内容,如果未能解决你的问题,请参考以下文章

无法使用 ORACLE APEX 删除交互式报表中的行

交互式报表 Oracle Apex 5 上的 LOV

在交互式报告中动态隐藏/显示区域(Oracle APEX 5.1)

Oracle Apex 有用笔记系列 6 - 可编辑交互报告 Editable Interactive Report

在 Oracle APEX 中访问报表输出表

Oracle APEX 18 - 经典报告错误缓冲区小