我的查询不是在Apex图表中填充数据,但它在Toad中有效

时间:2015-07-16 21:47:14

标签: sql oracle oracle-apex

    Select
    null link,
    a.Time_Frame "Start_Date",
    (a.Row_Number*(REGR_SLOPE(a.Failures, a.Row_Number) Over (Partition by a.State)) + (REGR_INTERCEPT(a.Failures, a.Row_Number) OVER (Partition by a.State))) Trendline

    FROM
    (
    SELECT ROW_NUMBER() OVER (ORDER BY (Case :P1_DATE_CHOOSER 
                     WHEN 'Daily' THEN trunc(start_time)
                     WHEN 'Weekly' THEN trunc(start_time, 'WW')
                     WHEN 'Monthly' THEN trunc(start_time, 'MM') 
                END))  Row_Number,
     (Case :P1_DATE_CHOOSER 
                     WHEN 'Daily' THEN trunc(start_time)
                     WHEN 'Weekly' THEN trunc(start_time, 'WW')
                     WHEN 'Monthly' THEN trunc(start_time, 'MM') 
                END) Time_Frame,
      count(job_id) Failures, State
    --FROM apps.NI_INFA_ACTIVITY_LOG_V@util.world
    FROM NI_INFA_ACTIVITY_LOG_V
    WHERE
    STATE = 1
    and
    (
    :P1_JOB_TYPE_CHOOSER = 'Workflow' AND INFA_TYPE_CODE = 'WORKFLOW'
    OR
    :P1_JOB_TYPE_CHOOSER = 'DSS' AND INFA_TYPE_CODE = 'DSS'
    OR
    :P1_JOB_TYPE_CHOOSER = 'MTT' AND INFA_TYPE_CODE = 'MTT'
    OR
    :P1_JOB_TYPE_CHOOSER NOT IN ('Workflow','DSS','MTT')
    )

    group by (Case :P1_DATE_CHOOSER 
                     WHEN 'Daily' THEN trunc(start_time)
                     WHEN 'Weekly' THEN trunc(start_time, 'WW')
                     WHEN 'Monthly' THEN trunc(start_time, 'MM') 
                END), state
    ORDER BY State,(Case :P1_DATE_CHOOSER 
                     WHEN 'Daily' THEN trunc(start_time)
                     WHEN 'Weekly' THEN trunc(start_time, 'WW')
                     WHEN 'Monthly' THEN trunc(start_time, 'MM') 
                END)
    ) a
    Group by a.Row_Number, a.Time_Frame,a.Failures, a.State
    order by a.State,a.Row_Number;

中间是来源。此查询适用于Toad,但当我将其移至Oracle Apex App开发人员时,图表将不会填充数据。唯一的变化是我在中间切换FROM子句。我知道“apps.NI_INFA_ACTIVITY_LOG_V@util.world”是一个来源,因为我在应用程序中的其他查询中使用它。如果我摆脱CASE / WHENS并将它们自己切换到像trunc(start_time)这样的单行,则填充数据。任何帮助将不胜感激。

表格和样本数据:

CREATE TABLE NI_INFA_ACTIVITY_LOG 
( TASK_ID        VARCHAR2(30 BYTE)
, OBJECT_NAME    VARCHAR2(1000 BYTE)
, JOB_ID         VARCHAR2(30 BYTE) NOT NULL
, INFA_TYPE_CODE VARCHAR2(10 BYTE)
, RUN_ID         NUMBER(10)
, START_TIME     DATE
, END_TIME       DATE 
, STATE          NUMBER(1)
);

INSERT INTO NI_INFA_ACTIVITY_LOG
(TASK_ID, OBJECT_NAME, JOB_ID, INFA_TYPE_CODE, RUN_ID, START_TIME, END_TIME, STATE)
VALUES
( '000T0W0N0000000000000U'
, 'CampSync_ERP_SFDC_v1.2'
, '000T0WC1000000001I6W'
, 'WORKFLOW'
, NULL
, TO_DATE('5/22/2015 11:20:10','MM/DD/YYYY HH24:MI:SS')
, TO_DATE('5/22/2015 11:21:02','MM/DD/YYYY HH24:MI:SS')
, 1
);

INSERT INTO NI_INFA_ACTIVITY_LOG
(TASK_ID, OBJECT_NAME, JOB_ID, INFA_TYPE_CODE, RUN_ID, START_TIME, END_TIME, STATE)
VALUES
( '000T0W0N00000000000H'
, 'PMDM_ORA_ORA_ClnLoad_v1.0'
, '000T0WC1000000001J5X'
, 'WORKFLOW'
, NULL
, TO_DATE('5/24/2015 10:30:11','MM/DD/YYYY HH24:MI:SS')
, TO_DATE('5/24/2015 10:32:34','MM/DD/YYYY HH24:MI:SS')
, 1
);

COMMIT;

我找到了解决方案。我不完全确定为什么这会使它在Apex中起作用:

             Select
             Null Link,
             tf.Time_Frame LABEL,
               (tf.Row_number*(REGR_SLOPE(count(data.job_id), tf.Row_number) Over (Partition by data.State)) + (REGR_INTERCEPT(count(data.job_id), tf.Row_number) OVER (Partition by data.State))) Trendline

                FROM APPS.NI_INFA_ACTIVITY_LOG_V@util.world data
                ,
                (
        Select RowNum Row_number, Time_Frame
           from
            (    
             Select 
                 Case :P1_DATE_CHOOSER 
                         WHEN 'Daily' THEN trunc(start_time)
                         WHEN 'Weekly' THEN trunc(start_time, 'WW')
                         WHEN 'Monthly' THEN trunc(start_time, 'MM') 
                    END Time_Frame
             From  APPS.NI_INFA_ACTIVITY_LOG_V@util.world
             group by Case :P1_DATE_CHOOSER 
                         WHEN 'Daily' THEN trunc(start_time)
                         WHEN 'Weekly' THEN trunc(start_time, 'WW')
                         WHEN 'Monthly' THEN trunc(start_time, 'MM') 
                    END
             order by 1
             )
        ) tf 
        where
        tf.Time_Frame = (Case :P1_DATE_CHOOSER 
                         WHEN 'Daily' THEN trunc(data.start_time)
                         WHEN 'Weekly' THEN trunc(data.start_time, 'WW')
                         WHEN 'Monthly' THEN trunc(data.start_time, 'MM') 
                    END)
        AND
        STATE = 1
                AND

              (
                :P1_JOB_TYPE_CHOOSER = 'Workflow' AND data.INFA_TYPE_CODE =  'WORKFLOW'
                OR
                :P1_JOB_TYPE_CHOOSER = 'DSS' AND data.INFA_TYPE_CODE = 'DSS'
                OR
                :P1_JOB_TYPE_CHOOSER = 'MTT' AND data.INFA_TYPE_CODE = 'MTT'
                OR
                :P1_JOB_TYPE_CHOOSER NOT IN ('Workflow','DSS','MTT')
              )
        group by tf.Time_Frame, tf.Row_number, data.State 

0 个答案:

没有答案