如何在OBIEE 11g中将多个结果连接成一行?

时间:2017-10-27 10:20:03

标签: oracle oracle11g repository obiee listagg

我想在OBIEE中创建一个报告,其数据如下:

Table : CUST
CUST_INTRL_ID
1
2
3
4

Table : CUST_ID_DOC
CUST_INTRL_ID       DOC_TYPE_CD      DOC_NM
1                       1              A
1                       2              B
2                       1              A
2                       2              B

Table : CUST_EMAIL
CUST_INTRL_ID       EMAIL_ADDR_TX
1                   xyz@mail.com
1                   ghj@mail.com
2                   yui@mail.com

Table : CUST_PHON
CUST_INTRL_ID       PHON_NB
1                   123456
1                   765442
1                   845322
2                   342315
2                   423424
2                   874534

然后我想创建一个这样的报告:

CUST_INTRL_ID  DOC_TYPE_CD  DOC_NM    EMAIL_ADDR_TX              PHON_NB
1              1,2          A,B       xyz@mail.com,ghj@mail.com   123456,765442,845322                                     
2              1,2          A,B       yui@mail.com               342315,423424,874534

如何在OBIEE中完成此操作?在SQL Query中,我们可以使用

执行此操作
SELECT X.CUST_INTRL_ID
  , LTRIM(RTRIM(LISTAGG(CASE WHEN R1=1 THEN X.EMAIL_ADDR_TX ELSE '' END, ', ') WITHIN GROUP (ORDER BY X.EMAIL_ADDR_TX))) AGG_EMAIL
  , LTRIM(RTRIM(LISTAGG(CASE WHEN R2=1 THEN X.PHON_NB ELSE '' END, ', ') WITHIN GROUP (ORDER BY X.PHON_NB))) AGG_PHON
  , LTRIM(RTRIM(LISTAGG(CASE WHEN R3=1 THEN X.DOC_TYPE_CD ELSE '' END, ', ') WITHIN GROUP (ORDER BY X.DOC_TYPE_CD))) AGG_DOC_TYPE
  , LTRIM(RTRIM(LISTAGG(CASE WHEN R3=1 THEN X.DOC_NM ELSE '' END, ', ') WITHIN GROUP (ORDER BY X.DOC_NM))) AGG_DOC_NM
FROM (
  SELECT CUST.CUST_INTRL_ID
    , CUST_EMAIL_ADDR.EMAIL_ADDR_TX
    , CUST_PHON.PHON_NB
    , CUST_ID_DOC.DOC_NM
    , CUST_ID_DOC.DOC_TYPE_CD
    , ROW_NUMBER() OVER (PARTITION BY CUST.CUST_INTRL_ID, CUST_EMAIL_ADDR.EMAIL_ADDR_TX ORDER BY CUST.CUST_INTRL_ID) R1
    , ROW_NUMBER() OVER (PARTITION BY CUST.CUST_INTRL_ID, CUST_PHON.PHON_NB ORDER BY CUST.CUST_INTRL_ID) R2
    , ROW_NUMBER() OVER (PARTITION BY CUST.CUST_INTRL_ID, CUST_ID_DOC.DOC_TYPE_CD ORDER BY CUST.CUST_INTRL_ID) R3
  FROM BUSINESS.CUST
  LEFT JOIN BUSINESS.CUST_EMAIL_ADDR ON CUST.CUST_INTRL_ID = CUST_EMAIL_ADDR.CUST_INTRL_ID
  LEFT JOIN BUSINESS.CUST_PHON ON CUST.CUST_INTRL_ID = CUST_PHON.CUST_INTRL_ID
  LEFT JOIN BUSINESS.CUST_ID_DOC ON CUST.CUST_INTRL_ID = CUST_ID_DOC.CUST_INTRL_ID
) X
GROUP BY X.CUST_INTRL_ID

但是这个查询花了太长时间,OBIEE报告长时间没有加载。在OBIEE 11g存储库中有没有办法执行相同的操作,但更快?

谢谢。 问候, 热甘

1 个答案:

答案 0 :(得分:0)

在OBI内部执行此操作是可能的,但是没有意义,因为这应该是一次性和物理性的,而不是“在每个单独的查询和逻辑上”。

从概念的角度来看,这是一种错误的方法