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

时间:2018-11-27 09:54:28

标签: oracle oracle-apex

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

这在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”之类的其他值,效果很好。

能否请您提出我应该做些什么以避免这种错误。

1 个答案:

答案 0 :(得分:0)

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

(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,

对update by的更改将是相似的,尽管留给读者练习;)