在oracle报表查询中的选择中使用选择

在oracle报表查询中的选择中使用选择,oracle,oracle10g,oraclereports,Oracle,Oracle10g,Oraclereports,我正在创建一个新的报告,其中报告中只有一个光标,并且报告没有纸张布局,它直接转换为CSV格式 我有一个查询,我需要做一个子查询,比如 SELECT grou.GROUP_ID GROUP_ID ,grou.group_name group_name .... (((SELECT SUM(nett_instalment_in

我正在创建一个新的报告,其中报告中只有一个光标,并且报告没有纸张布局,它直接转换为CSV格式

我有一个查询,我需要做一个子查询,比如

SELECT
         grou.GROUP_ID                            GROUP_ID
         ,grou.group_name                          group_name
         ....
         (((SELECT SUM(nett_instalment_invoice_amount) 
            FROM instalments
            WHERE member_product_id = member_product_id)) subscription)
FROM
。。。。 等等

在编写报告时,我遇到一个错误,即

Encountered Symbol SELECT while expecting one of the following symbols:
(  +  - 
如果不在末尾添加GROUPBY子句,这是否有帮助

因为我尝试了另一种方法,加入一个GROUPBY子句,直接使用sum函数而不是SELECTSUM

如有需要,请提供紧急帮助


谢谢。

这当然是允许的:

select d.dname, (sum(e.sal) from emp e where e.deptno = d.deptno) as dept_sal
from dept d;
这也是:

select d.dname, sum(e.sal)
from dept d
left outer join emp e on e.deptno = d.deptno
group by d.dname;

那么您到底做了什么?

Oracle报告的哪个版本

SELECT /*+ ORDERED PUSH_SUBQ*/
          11
         ,'SQ'
         ,grou.GROUP_ID                            GROUP_ID
         ,grou.group_name                          group_name
         ,intm.intermediary_id                     intermediary_id          --R3352 AUS Regulatory added new field
         ,intm.intermediary_name                   intermediary_name 
         ,regi.registration_id                     registration_id
         ,mere.member_id                           member_id
         ,memb.title_code                          title_code
         ,memb.given_name||' '||memb.family_name   member_name
         --,mech.birth_date                          birth_date
         ,mere.company_employee_ref                company_employee_ref
         ,memb.orig_risk_start_date                orig_risk_start_date
         ,mere.original_bi_joining_date            orig_joining_date
         ,mepr.member_product_id                   member_product_id
         ,mepr.member_product_risk_start_date      mp_risk_start_date
         ,mepr.product_id                          product_id
         ,INITCAP(prod.product_name)               product_name
         ,cont.currency_code
         ,mere.customer_status_code
         /* ,((SELECT SUM(inst.nett_instalment_invoice_amount) 
            FROM instalments inst
            WHERE inst.member_product_id = mepr.member_product_id)) subscription */
         ,SUM(inst.nett_instalment_invoice_amount) subscription
  FROM    registrations                 regi
         ,member_registrations          mere
         ,member_products               mepr
         ,contracts                     cont
         ,products                      prod
         ,members                       memb
         ,groups                        grou
         ,intermediaries                intm
         ,insurers                      insu        
         ,instalments                   inst
  WHERE  insu.insurer_id                = i_insurerid
  AND    NVL(i_reportdate  ,Sysdate)    >= cont.contract_risk_start_date
  AND   NVL(i_reportdate  ,Sysdate)     < cont.renewal_date      
  --AND    regi.GROUP_ID                   IN (77648,77658) --Arv
  AND    prod.insurer_id                 = insu.insurer_id(+)
  AND    mere.member_id                  = memb.member_id
  AND    mere.member_id                  = mepr.member_id
  AND    mepr.contract_pk                = cont.contract_pk
  AND    mepr.product_id                 = prod.product_id(+)
  AND    mepr.intermediary_id            = intm.intermediary_id(+)
  AND    mere.registration_id            = regi.registration_id 
  AND    mere.registration_id            = mepr.registration_id
  AND    regi.GROUP_ID                   = grou.group_id 
  AND    inst.member_product_id          = mepr.member_product_id
  AND    grou.group_level_code       IN ('G','R')
  AND    mere.customer_status_code       IN ('A','L')      
  AND    family_name_uppercase          <> UPPER('zz** Please Ignore This Member **zz') 
  AND    given_name_uppercase           <> UPPER('zz** Please Ignore **zz') --l_given_name_uppercase

    AND    NOT EXISTS
         ( SELECT 'X'
           FROM   customer_lapses
           WHERE  GROUP_ID               = regi.GROUP_ID
           AND    suspend_lapse_ind      = 'L'
           AND    reinstatement_ind      = 'N'
           AND    lapse_effective_date  <= NVL(i_reportdate  ,Sysdate)
           UNION
           SELECT 'X'
           FROM   customer_lapses
           WHERE  registration_id        = regi.registration_id
           AND    suspend_lapse_ind      = 'L'
           AND    reinstatement_ind      = 'N'
           AND    lapse_effective_date  <= NVL(i_reportdate  ,Sysdate)
         )

  AND    NOT EXISTS
         ( SELECT 'X'
           FROM   customer_lapses
           WHERE  mem_reg_member_id        = mere.member_id
           AND    mem_reg_registration_id  = mere.registration_id
           AND    suspend_lapse_ind        = 'L'
           AND    reinstatement_ind        = 'N'
           AND    lapse_effective_date    <= NVL(i_reportdate  ,Sysdate)
         )

  AND    NOT EXISTS
         ( SELECT 'X'
           FROM   customer_lapses
           WHERE  member_product_id        = mepr.member_product_id
           AND    suspend_lapse_ind        = 'L'
           AND    reinstatement_ind        = 'N'
           AND    lapse_effective_date    <= NVL(i_reportdate  ,Sysdate)
           UNION
           SELECT 'X'
           FROM   customer_lapses
           WHERE  cust_prod_contract_pk    = mepr.contract_pk
           AND    cust_prod_product_id     = mepr.product_id
           AND    suspend_lapse_ind        = 'L'
           AND    reinstatement_ind        = 'N'
           AND    lapse_effective_date    <= NVL(i_reportdate  ,Sysdate)
         )

         Group BY    11
         ,'SQ'
         ,grou.GROUP_ID                           -- GROUP_ID
         ,grou.group_name                         -- group_name
         ,intm.intermediary_id                    -- intermediary_id          --R3352 AUS Regulatory added new field
         ,intm.intermediary_name                  -- intermediary_name 
         ,regi.registration_id                  --   registration_id
         ,mere.member_id                         --  member_id
         ,memb.title_code                        --  title_code
         ,memb.given_name||' '||memb.family_name  -- member_name
         --,mech.birth_date                          birth_date
         ,mere.company_employee_ref               -- company_employee_ref
         ,memb.orig_risk_start_date              --  orig_risk_start_date
         ,mere.original_bi_joining_date          --  orig_joining_date
         ,mepr.member_product_id                 --  member_product_id
         ,mepr.member_product_risk_start_date     -- mp_risk_start_date
         ,mepr.product_id                         -- product_id
         ,INITCAP(prod.product_name)              -- product_name
         ,cont.currency_code
         ,mere.customer_status_code
标量子查询语法是在Oracle 8/8i前后出现的,但Oracle报表的开发在石器时代的某个时候停止了。在过去的10多年中,许多增强的SQL语法都没有得到应用


如果您可以在数据库中创建大部分查询作为视图,并且只需从报表中的视图中进行选择,那么您就有了更大的灵活性

通过创建一个函数,我们将其称为get\u installation\u inv\u sum,其中有一个参数member\u product\u id,如下所示:

create or replace function get_installment_inv_sum (p_member_product_id number) return number
as 
 v_sum number
begin
 SELECT SUM(nett_instalment_invoice_amount) 
            into v_sum
            FROM instalments
            WHERE member_product_id = p_member_product_id;
 return v_sum;
end;
然后您可以调用您的选择,如:

SELECT
         grou.GROUP_ID                            GROUP_ID
         ,grou.group_name                          group_name
         ....
         ,
         get_installment_inv_sum(member_product_id) subscription
FROM ...

这个问题非常模糊。请显示实际的SQL和实际的错误消息。这应该添加到问题中,而不是作为答案给出。运行时会发生什么?它在plsql编辑器中运行平稳,但在oracle报告中添加到编译时,它会给出错误