Kindly help with rewriting the foll. query in a better way

IS there a better way of writing the foll query:
When I have 12,50,00,000 rows in Fact Table, the query is unable to execute. I use more than 200GB of temporary space. But I still get Temp Tablespace Full Error:
--Foll WITH Clause is to calculate Sum of Debit-Credit to calculate BLNC acc. to Group By values
WITH crnt_blnc_set
AS ( SELECT f.hrarchy_dmn_id,
f.prduct_dmn_id,
f.pstng_crncy_id AS crncy_dmn_id,
f.acnt_dmn_id,
f.txn_id AS txn_id,
f.acntng_entry_src AS txn_src,
f.acntng_entry_typ AS acntng_entry_typ,
f.val_dt_dmn_id,
f.revsn_dt,
SUM (
DECODE (
f.pstng_typ,
'Credit', f.pstng_amnt,
0))
- SUM (
DECODE (
f.pstng_typ,
'Debit', f.pstng_amnt,
0))
AS blnc
FROM FactTable f
GROUP BY f.hrarchy_dmn_id,
f.prduct_dmn_id,
f.pstng_crncy_id,
f.acnt_dmn_id,
f.txn_id,
f.acntng_entry_src,
f.acntng_entry_typ,
f.val_dt_dmn_id,
f.revsn_dt),
--Foll WITH Clause calculates Min and Max Date Ids for the Group By conditions as mentioned
min_mx_dt
AS ( SELECT /*+parallel(32)*/
f.hrarchy_dmn_id AS hrarchy_dmn_id,
f.prduct_dmn_id AS prduct_dmn_id,
f.crncy_dmn_id AS crncy_dmn_id,
f.acnt_dmn_id AS acnt_dmn_id,
f.txn_id AS txn_id,
f.txn_src AS txn_src,
f.acntng_entry_typ AS acntng_entry_typ,
MIN (f.val_dt_dmn_id) AS min_val_dt,
GREATEST (MAX (f.val_dt_dmn_id), 2689) AS max_val_dt
FROM crnt_blnc_set f
GROUP BY f.hrarchy_dmn_id,
f.prduct_dmn_id,
f.crncy_dmn_id,
f.acnt_dmn_id,
f.txn_id,
f.txn_src,
f.acntng_entry_typ),
/*Foll WITH Clause has a Cartesian Join on date_dmn to populate missing entries
This requirement is because if we have a distinct row for
hrarchy_dmn_id,
prduct_dmn_id,
crncy_dmn_id,
acnt_dmn_id,
txn_id,
txn_src,
acntng_entry_typ Combination and If wehave a missing entry for that in the max date provided then we actually create those missing entries*/
slctd_rcrds
AS ( SELECT /*+ ordered use_nl(d) parallel(mx, 4) */
mx.hrarchy_dmn_id AS hrarchy_dmn_id,
mx.prduct_dmn_id AS prduct_dmn_id,
mx.crncy_dmn_id AS crncy_dmn_id,
mx.acnt_dmn_id AS acnt_dmn_id,
mx.txn_id AS txn_id,
mx.txn_src AS txn_src,
mx.acntng_entry_typ AS acntng_entry_typ,
d.date_value AS val_dt,
d.date_dmn_id AS val_dt_dmn_id
FROM min_mx_dt mx, date_dmn d
WHERE mx.min_val_dt <= d.date_dmn_id
AND mx.max_val_dt >= d.date_dmn_id
--Foll. WITH clause actually has a outer Join with Firt With Clause to populate the values accordingly
cmbnd_rcrds
AS (
SELECT /*+ USE_HASH(c) */ s.hrarchy_dmn_id AS hrarchy_dmn_id,
s.prduct_dmn_id AS prduct_dmn_id,
s.crncy_dmn_id AS crncy_dmn_id,
s.acnt_dmn_id AS acnt_dmn_id,
s.txn_id AS txn_id,
s.txn_src AS txn_src,
s.acntng_entry_typ AS acntng_entry_typ,
s.val_dt_dmn_id AS val_dt_dmn_id,
NVL (c.revsn_dt, s.val_dt) AS revsn_dt,
NVL (c.blnc, 0) AS blnc,
0 AS prvs_rcrd_ind
FROM slctd_rcrds s, crnt_blnc_set c
WHERE s.hrarchy_dmn_id = c.hrarchy_dmn_id(+)
AND s.prduct_dmn_id = c.prduct_dmn_id(+)
AND s.crncy_dmn_id = c.crncy_dmn_id(+)
AND s.acnt_dmn_id = c.acnt_dmn_id(+)
AND s.txn_id = c.txn_id(+)
AND s.txn_src = c.txn_src(+)
AND s.acntng_entry_typ = c.acntng_entry_typ(+)
AND s.val_dt_dmn_id = c.val_dt_dmn_id(+))
Select * from cmbnd_rcrds

Thanks for the response Alfonso. I have tried that as well. But Create Table as Also uses Temp Storage till it's created. And that again gives the same error as well.
Anyways I am now trying with a smaller set. This much piece gets executed in Half an hour but the next piece where we pivot the data is taking forever now.
That piece is as follows:
(SELECT /*+parallel(8)*/
f.hrarchy_dmn_id,
f.prduct_dmn_id,
f.crncy_dmn_id,
f.acnt_dmn_id,
f.txn_id,
f.txn_src,
f.acntng_entry_typ,
f.val_dt_dmn_id,
f.revsn_dt,
SUM (
blnc)
OVER (
PARTITION BY f.hrarchy_dmn_id,
f.prduct_dmn_id,
f.crncy_dmn_id,
f.acnt_dmn_id,
f.txn_id,
f.txn_src,
f.acntng_entry_typ
ORDER BY d.date_value)
AS crnt_blnc,
SUM (
blnc)
OVER (
PARTITION BY f.hrarchy_dmn_id,
f.prduct_dmn_id,
f.crncy_dmn_id,
f.acnt_dmn_id,
f.txn_id,
f.txn_src,
f.acntng_entry_typ,
d.fin_mnth_num
|| d.fin_year_strt
|| d.fin_year_end
ORDER BY d.date_value)
/ d.mnth_to_dt
AS mtd_avg,
SUM (
blnc)
OVER (
PARTITION BY f.hrarchy_dmn_id,
f.prduct_dmn_id,
f.crncy_dmn_id,
f.acnt_dmn_id,
f.txn_id,
f.txn_src,
f.acntng_entry_typ,
d.fin_year_strt || d.fin_year_end
ORDER BY d.date_value)
/ yr_to_dt
AS ytd_avg,
f.prvs_rcrd_ind AS prvs_rcrd_ind
FROM cmbnd_rcrds f, thor_date_dmn d
WHERE d.holidaY_ind = 0 AND f.val_dt_dmn_id = d.date_dmn_id)
SELECT f.hrarchy_dmn_id,
f.prduct_dmn_id,
f.crncy_dmn_id,
f.acnt_dmn_id,
f.txn_id AS txn_id,
f.txn_src AS acntng_entry_src,
f.acntng_entry_typ AS acntng_entry_typ,
f.val_dt_dmn_id,
f.revsn_dt,
f.crnt_blnc,
f.mtd_avg,
f.ytd_avg,
'EOD TB ETL' AS crtd_by,
SYSTIMESTAMP AS crtn_dt,
NULL AS mdfd_by,
NULL AS mdfctn_dt
FROM fnl_set f
WHERE f.prvs_rcrd_ind = 0
ORDER BY f.hrarchy_dmn_id,
f.prduct_dmn_id,
f.crncy_dmn_id,
f.acnt_dmn_id,
f.txn_id,
f.txn_src,
f.acntng_entry_typ,
f.val_dt_dmn_id
Any other way to pivot this?
Also I am getting a lot of foll wait events:
PX Deq Credit :Send blkd
PX Deq :Table Q Normal
Direct Path Write Temp
And Direct Path Read Temp.

Similar Messages

  • Help with rewriting the query for faster execution.

    Hello Everybody,
    We are on Version
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    I am trying to get data from tab1 where col8 is equal to ' ' at the same time If we 2 or 3 records matched on col1 and col2 with different dates(col3) i am only interested in getting one record with the least date....
    Here is the sample data...
    Col1 col2 col3 COL4 COl5 Col6 COL7 COL8 COL9
    12 1 17-JAN-13 1 5 7 9 1233333 25
    10 2 16-JAN-13 2 5 7 9 1233333 25
    10 2 14-JAN-13 2 5 7 9 1233333 25
    16 6 16-JAN-13 6 5 7 9 1233333 28
    16 6 09-OCT-12 5 5 7 9 1233333 29
    16 6 15-JAN-13 6 5 7 9 1233333 28
    17 5 09-OCT-12 5 5 7 9 1233333 29
    17 5 16-JAN-13 6 5 7 9 1233333 28
    17 5 10-OCT-12 5 5 7 9 1233333 29
    I am expecting output like this only should pull records...with min or least date
    Col1 col2 col3 COL4 COl5 Col6 COL7 COL8 COL9
    10 2 14-JAN-13 2 5 7 9 1233333 25
    16 6 09-OCT-12 5 5 7 9 1233333 29
    17 5 09-OCT-12 5 5 7 9 1233333 29
    Below query works and we have close to billion rows in a table but the where clause would filter out to 100 mill records.
    and i am trying to see if there is an effecient way of writing this....we have an index on COL3.
    Select col1,col2,col3,col4,col5,col6,col7,col8,col9 from(Selct of.,row_number() over (partition by col1,col2 order by col3 asc) as rnk
    from tabl of where of.col8 = '1233333') where rnk = 1*
    From the above query i get the below explain plan
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Pstart| Pstop |
    | 0 | SELECT STATEMENT | | 1016M| 118G| | 13M (2)| 45:46:43 | | |
    |* 1 | VIEW | | 1016M| 118G| | 13M (2)| 45:46:43 | | |
    |* 2 | WINDOW SORT PUSHED RANK| | 1016M| 43G| 64G| 13M (2)| 45:46:43 | | |
    | 3 | PARTITION LIST SINGLE | | 1016M| 43G| | 1878K (3)| 06:15:47 | 4 | 4 |
    | 4 | TABLE ACCESS FULL | TAB1 | 1016M| 43G| | 1878K (3)| 06:15:47 | 4 | 4 |
    Predicate Information (identified by operation id):
    1 - filter("RNK"=1)
    2 - filter(ROW_NUMBER() OVER ( PARTITION BY "COL1","COl2" ORDER BY "COl3")<=1)
    17 rows selected
    Thanks In Advance!
    Edited by: 983949 on Jan 24, 2013 11:50 AM

    983949 wrote:
    Hello Everybody,
    I am trying to get data from tab1 where col8 is equal to ' ' at the same time.
    If we 2 or 3 records matched on col1 and col2 with different dates(col3)
    i am only interested in getting one record with the least date...
    Below query works and we have close to billion rows in a table but the where clause would filter out to 100 mill records.
    and i am trying to see if there is an effecient way of writing this....we have an index on COL3.
    Select col1,col2,col3,col4,col5,col6,col7,col8,col9
    from(Selct of.*,row_number() over (partition by col1,col2 order by col3 asc) as rnk
    from tabl of where of.col8 = '1233333') where rnk = 1
    Thanks In Advance!How do I ask a question on the forums?
    SQL and PL/SQL FAQ

  • Need Help with Creating the SQl query

    Hi,
    SQL query gurus...
    INFORMATION:
    I have two table, CURRENT and PREVIOUS.(Table Defs below).
    CURRENT:
    Column1 - CURR_PARENT
    Column2 - CURR_CHILD
    Column3 - CURR_CHILD_ATTRIBUTE 1
    Column4 - CURR_CHILD_ATTRIBUTE 2
    Column5 - CURR_CHILD_ATTRIBUTE 3
    PREVIOUS:
    Column1 - PREV_PARENT
    Column2 - PREV_CHILD
    Column3 - PREV_CHILD_ATTRIBUTE 1
    Column4 - PREV_CHILD_ATTRIBUTE 2
    Column5 - PREV_CHILD_ATTRIBUTE 3
    PROBLEM STATEMENT
    Here the columns 3 to 5 are the attributes of the Child. Lets assume that I have two loads, One Today which goes to the CURRENT table and one yesterday which goes to the PREVIOUS table. Between these two loads there is a CHANGE in the value for Columns either 3/4/5 or all of them(doesnt matter if one or all).
    I want to determine what properties for the child have changed with the help of a MOST efficient SQL query.(PARENT+CHILD is unique key). The Database is ofcourse ORACLE.
    Please help.
    Regards,
    Parag

    Hi,
    The last message was not posted by the same user_name that started the thread.
    Please don't do that: it's confusing.
    Earlier replies give you the information you want, with one row of output (maximum) per row in current_tbl. There may be 1, 2 or 3 changes on a row.
    You just have to unpivot that data to get one row for every change, like this:
    WITH     single_row  AS
         SELECT     c.curr_parent
         ,     c.curr_child
         ,     c.curr_child_attribute1
         ,     c.curr_child_attribute2
         ,     c.curr_child_attribute3
         ,     DECODE (c.curr_child_attribute1, p.prev_child_attribute1, 0, 1) AS diff1
         ,     DECODE (c.curr_child_attribute2, p.prev_child_attribute2, 0, 2) AS diff2
         ,     DECODE (c.curr_child_attribute3, p.prev_child_attribute3, 0, 3) AS diff3
         FROM     current_tbl    c
         JOIN     previous_tbl   p     ON  c.curr_parent     = p.prev_parent
                                AND c.curr_child     = p.prev_child
         WHERE     c.curr_child_attribute1     != p.prev_child_attribute1
         OR     c.curr_child_attribute2     != p.prev_child_attribute2
         OR     c.curr_child_attribute3     != p.prev_child_attribute3
    ,     cntr     AS
         SELECT     LEVEL     AS n
         FROM     dual
         CONNECT BY     LEVEL <= 3
    SELECT     s.curr_parent     AS parent
    ,     s.curr_child     AS child
    ,     CASE     c.n
              WHEN  1  THEN  s.curr_child_attribute1
              WHEN  2  THEN  s.curr_child_attribute2
              WHEN  3  THEN  s.curr_child_attribute3
         END          AS attribute
    ,     c.n          AS attribute_value
    FROM     single_row     s
    JOIN     cntr          c     ON     c.n IN ( s.diff1
                                    , s.diff2
                                    , s.diff3
    ORDER BY  attribute_value
    ,            parent
    ,            child
    ;

  • Help Required(Rewriting the query to reduce steps)

    With and Without Group ID,I am populating a value into a column,Can anyone please help to write the same query in an other way.This is a sample column.Likewise,there are 5 more columns to be populated.So that I have to write 2 left outer joins for a single column with a little difference.
    SELECT
    CASE
         WHEN T6.ACTUAL_FUNCTION IS NOT NULL
         THEN T6.ACTUAL_FUNCTION
         WHEN T10.ACTUAL_FUNCTION IS NOT NULL
         THEN T10.ACTUAL_FUCNTION
              ELSE T5.ACTUAL_FUCNTION
    END AF_NOM_PRE_GTEES
    FROM
    ABC_WT17 T1
         INNER JOIN
         ABC_CUSTOMER_WT01 T3
         ON T1.ORIGINAL_SDS_PARTY_IDR=T3.ORIGINAL_SDS_PARTY_IDR
         AND T1.IDR_TYPE_CODE=T3.IDR_TYPE_CODE
         LEFT OUTER JOIN /* This is the condition with group ID*/
         RESIDUAL_CONTROL T6
         ON
         T1.NOM_PRE_GTEES = T6.VALUE_MAX
         OR
         T1.NOM_PRE_GTEES > T6.VALUE_GREATER_THAN
         AND
         T1.NOM_PRE_GTEES < T6.VALUE_MAX
         AND
    _     T1.GROUP_ID = T6.GROUP_ID_
         AND
         T6.FALLBACK_IND = ‘N’
    LEFT OUTER JOIN /* this is the condition without Group ID*/
         RESIDUAL_CONTROL T10
         ON
         T1.NOM_PRE_GTEES = T10.VALUE_MAX
         OR
         T1.NOM_PRE_GTEES > T10.VALUE_GREATER_THAN
         AND
         T1.NOM_PRE_GTEES < T10.VALUE_MAX
         AND
         T10.FALLBACK_IND = ‘N’
         CROSS JOIN
         RESIDUAL_CONTROL T5
         ON T5.FALLBACK_IND = ‘Y’
    Thanks in advance.

    KVB wrote:
    With and Without Group ID,I am populating a value into a column,Can anyone please help to write the same query in an other way.This is a sample column.Likewise,there are 5 more columns to be populated.So that I have to write 2 left outer joins for a single column with a little difference.
    SELECT
    CASE
         WHEN T6.ACTUAL_FUNCTION IS NOT NULL
         THEN T6.ACTUAL_FUNCTION
         WHEN T10.ACTUAL_FUNCTION IS NOT NULL
         THEN T10.ACTUAL_FUCNTION
              ELSE T5.ACTUAL_FUCNTION
    END AF_NOM_PRE_GTEES
    FROM
    ABC_WT17 T1
         INNER JOIN
         ABC_CUSTOMER_WT01 T3
         ON T1.ORIGINAL_SDS_PARTY_IDR=T3.ORIGINAL_SDS_PARTY_IDR
         AND T1.IDR_TYPE_CODE=T3.IDR_TYPE_CODE
         LEFT OUTER JOIN /* This is the condition with group ID*/
         RESIDUAL_CONTROL T6
         ON
         T1.NOM_PRE_GTEES = T6.VALUE_MAX
         OR
         T1.NOM_PRE_GTEES > T6.VALUE_GREATER_THAN
         AND
         T1.NOM_PRE_GTEES < T6.VALUE_MAX
         AND
    _     T1.GROUP_ID = T6.GROUP_ID_
         AND
         T6.FALLBACK_IND = ‘N’
    LEFT OUTER JOIN /* this is the condition without Group ID*/
         RESIDUAL_CONTROL T10
         ON
         T1.NOM_PRE_GTEES = T10.VALUE_MAX
         OR
         T1.NOM_PRE_GTEES > T10.VALUE_GREATER_THAN
         AND
         T1.NOM_PRE_GTEES < T10.VALUE_MAX
         AND
         T10.FALLBACK_IND = ‘N’
         CROSS JOIN
         RESIDUAL_CONTROL T5
         ON T5.FALLBACK_IND = ‘Y’
    Thanks in advance.Thread: HOW TO: Post a SQL statement tuning request - template posting
    HOW TO: Post a SQL statement tuning request - template posting

  • Help to rewrite the query --performance issue

    Hi ,
    Please help to rewrite the query since it's performance is not good.Especially second inline query(CASE statements are therein select caluse ..)is taking more cost.
    Database Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bi
    SELECT *
    FROM
      (SELECT q.*,
        COUNT(*) OVER() AS record_count,
        ROWNUM          AS row_num
      FROM
        (SELECT ExName.examiner_code,
          examiner_name,
          :v_year,
          :v_month,
          count_fb,
          NVL(count_entered_fb, 0) count_entered_fb,
          NVL(count_sent_fb, 0) count_sent_fb,
          NVL(count_edited_fb, 0) count_edited_fb,
          NVL(count_complete_fb, 0) count_complete_fb,
          NVL(count_withibcardiff_fb, 0) count_withibcardiff_fb
        FROM
          (SELECT examiner_code,
            COUNT(*) AS count_fb
          FROM
            (SELECT
                        examiner_code,
              paper_code,
              assessment_school
            FROM
              ( SELECT DISTINCT ce.examiner_code,
                ce.paper_code,
                ce.assessment_school
              FROM
                (SELECT
                  DISTINCT assessment_school,
                  paper_code,
                  examiner_code
                FROM candidate_examiner_allocation cea
                WHERE cea.element = 'Moderation of IA'
                AND cea.year      = :v_year
                AND cea.month     = :v_month
                ) ce,
                subject_group sg,
                subject_component sc
              WHERE (:v_padded_examiner_code IS NULL
              OR ce.examiner_code            = :v_padded_examiner_code)
              AND (:v_subject_group          IS NULL
              OR sg.group_number             = :v_subject_group)
              AND sg.year                    = :v_year
              AND sg.month                   = :v_month
              AND sc.year                    = :v_year
              AND sc.month                   = :v_month
              AND sc.paper_code              = ce.paper_code
              AND sc.subject                 = sg.subject
              AND sc.lvl                     = sg.lvl
              AND (:v_subject                IS NULL
              OR sc.subject                  = :v_subject)
              AND (:v_lvl                    IS NULL
              OR sc.lvl                      = :v_lvl)
              ) ea
          GROUP BY examiner_code
          ) ExName,
          (SELECT examiner_code,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'ENTERED'
              THEN 1
              ELSE NULL
            END) AS count_entered_fb,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'SENT'
              THEN 1
              ELSE NULL
            END) AS count_sent_fb,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'EDITED'
              THEN 1
              ELSE NULL
            END) AS count_edited_fb,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'COMPLETE'
              THEN 1
              ELSE NULL
            END) AS count_complete_fb,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'WITH IBCARDIFF'
              THEN 1
              ELSE NULL
            END) AS count_withibcardiff_fb
          FROM ia_instances ia1,
            workflow_instance wfi
          WHERE wfi.instance_id = ia1.workflow_instance_id
          AND ia1.year          = :v_year
          AND ia1.month         = :v_month
          GROUP BY ia1.year,
            ia1.month,
            examiner_code
          ) iaF,
          (SELECT person_code,
            title
            || ' '
            || firstname
            || ' '
            || lastname AS examiner_name
          FROM person
          WHERE :v_examiner_name IS NULL
          OR UPPER(title
            || ' '
            || firstname
            || ' '
            || lastname) LIKE :v_search_examiner_name
          ) P
        WHERE ExName.examiner_code = iaF.examiner_code (+)
        AND ExName.examiner_code   = p.person_code
        ORDER BY ExName.examiner_code
        ) q
      ) rc
    WHERE row_num >= :v_start_row
    AND row_num   <= (:v_start_row+(:v_max_row-1));explain plan
    line 1: SQLPLUS Command Skipped: set linesize 130
    line 2: SQLPLUS Command Skipped: set pagesize 0
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                           
    Plan hash value: 1581970599                                                                                                                                                                                                                                                                                 
    | Id  | Operation                                 | Name                           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |                                                                                                                                                                        
    |   0 | SELECT STATEMENT                          |                                |     1 |   276 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |*  1 |  FILTER                                   |                                |       |       |       |            |          |                                                                                                                                                                        
    |*  2 |   VIEW                                    |                                |     1 |   276 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |   3 |    WINDOW BUFFER                          |                                |     1 |   250 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |   4 |     COUNT                                 |                                |       |       |       |            |          |                                                                                                                                                                        
    |   5 |      VIEW                                 |                                |     1 |   250 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |   6 |       SORT ORDER BY                       |                                |     1 |   119 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |   7 |        NESTED LOOPS                       |                                |     1 |   119 |       |  2186   (6)| 00:00:34 |                                                                                                                                                                        
    |*  8 |         HASH JOIN OUTER                   |                                |     1 |    92 |       |  2185   (6)| 00:00:34 |                                                                                                                                                                        
    |   9 |          VIEW                             |                                |     1 |    20 |       |    51   (4)| 00:00:01 |                                                                                                                                                                        
    |  10 |           SORT GROUP BY                   |                                |     1 |     7 |       |    51   (4)| 00:00:01 |                                                                                                                                                                        
    |  11 |            VIEW                           |                                |     1 |     7 |       |    51   (4)| 00:00:01 |                                                                                                                                                                        
    |  12 |             SORT UNIQUE                   |                                |     1 |   127 |       |    51   (4)| 00:00:01 |                                                                                                                                                                        
    |  13 |              NESTED LOOPS                 |                                |     1 |   127 |       |    50   (2)| 00:00:01 |                                                                                                                                                                        
    |* 14 |               HASH JOIN                   |                                |     1 |    68 |       |    44   (3)| 00:00:01 |                                                                                                                                                                        
    |* 15 |                TABLE ACCESS BY INDEX ROWID| SUBJECT_COMPONENT              |    13 |   520 |       |    40   (0)| 00:00:01 |                                                                                                                                                                        
    |* 16 |                 INDEX RANGE SCAN          | SUBJECT_COMPONENT_ASSESS_TYPE  |  1059 |       |       |     9   (0)| 00:00:01 |                                                                                                                                                                        
    |* 17 |                INDEX RANGE SCAN           | SUBJECT_GROUP_PK               |    41 |  1148 |       |     3   (0)| 00:00:01 |                                                                                                                                                                        
    |* 18 |               INDEX RANGE SCAN            | CEA_AUTOMATIC_ALLOCATION_STATS |     5 |   295 |       |     6   (0)| 00:00:01 |                                                                                                                                                                        
    |  19 |          VIEW                             |                                |   679 | 48888 |       |  2133   (6)| 00:00:33 |                                                                                                                                                                        
    |  20 |           SORT GROUP BY                   |                                |   679 | 25123 |       |  2133   (6)| 00:00:33 |                                                                                                                                                                        
    |* 21 |            HASH JOIN                      |                                | 52408 |  1893K|  1744K|  2126   (6)| 00:00:33 |                                                                                                                                                                        
    |  22 |             TABLE ACCESS BY INDEX ROWID   | IA_INSTANCES                   | 52408 |  1125K|       |   688   (1)| 00:00:11 |                                                                                                                                                                        
    |* 23 |              INDEX RANGE SCAN             | IND_IA_INSTANCES               | 49077 |       |       |   137   (2)| 00:00:03 |                                                                                                                                                                        
    |  24 |             TABLE ACCESS FULL             | WORKFLOW_INSTANCE              |  1075K|    15M|       |   960   (7)| 00:00:15 |                                                                                                                                                                        
    |* 25 |         TABLE ACCESS BY INDEX ROWID       | PERSON                         |     1 |    27 |       |     1   (0)| 00:00:01 |                                                                                                                                                                        
    |* 26 |          INDEX UNIQUE SCAN                | PERSON_PK                      |     1 |       |       |     0   (0)| 00:00:01 |                                                                                                                                                                        
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                         
       1 - filter(TO_NUMBER(:V_START_ROW)<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1))                                                                                                                                                                                                                   
       2 - filter("ROW_NUM">=TO_NUMBER(:V_START_ROW) AND "ROW_NUM"<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1))                                                                                                                                                                                          
       8 - access("EXNAME"."EXAMINER_CODE"="IAF"."EXAMINER_CODE"(+))                                                                                                                                                                                                                                            
      14 - access("SC"."SUBJECT"="SG"."SUBJECT" AND "SC"."LVL"="SG"."LVL")                                                                                                                                                                                                                                      
      15 - filter((:V_SUBJECT IS NULL OR "SC"."SUBJECT"=:V_SUBJECT) AND ("SC"."LVL"=:V_LVL OR :V_LVL IS NULL))                                                                                                                                                                                                  
      16 - access("SC"."YEAR"=TO_NUMBER(:V_YEAR) AND "SC"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                     
      17 - access("SG"."YEAR"=TO_NUMBER(:V_YEAR) AND "SG"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                     
           filter(:V_SUBJECT_GROUP IS NULL OR "SG"."GROUP_NUMBER"=TO_NUMBER(:V_SUBJECT_GROUP))                                                                                                                                                                                                                  
      18 - access("CEA"."YEAR"=TO_NUMBER(:V_YEAR) AND "CEA"."MONTH"=:V_MONTH AND "SC"."PAPER_CODE"="PAPER_CODE" AND                                                                                                                                                                                             
                  "CEA"."ELEMENT"='Moderation of IA')                                                                                                                                                                                                                                                           
           filter("CEA"."ELEMENT"='Moderation of IA' AND (:V_PADDED_EXAMINER_CODE IS NULL OR                                                                                                                                                                                                                    
                  "EXAMINER_CODE"=:V_PADDED_EXAMINER_CODE))                                                                                                                                                                                                                                                     
      21 - access("WFI"."INSTANCE_ID"="IA1"."WORKFLOW_INSTANCE_ID")                                                                                                                                                                                                                                             
      23 - access("IA1"."YEAR"=TO_NUMBER(:V_YEAR) AND "IA1"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                   
      25 - filter(:V_EXAMINER_NAME IS NULL OR UPPER("TITLE"||' '||"FIRSTNAME"||' '||"LASTNAME") LIKE :V_SEARCH_EXAMINER_NAME)                                                                                                                                                                                   
      26 - access("EXNAME"."EXAMINER_CODE"="PERSON_CODE")                                                                                                                                                                                                                                                       
    53 rows selected

    Hi,
    please find the below rigjt explan paln.
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                           
    SQL_ID  2ct41vyyzqyh7, child number 0                                                                                                                                                                                                                                                                       
    SELECT *  FROM    (SELECT q.*,      COUNT(*) OVER() AS record_count,      ROWNUM          AS row_num    FROM      (SELECT                                                                                                                                                                                   
    ExName.examiner_code,        examiner_name,        :v_year,        :v_month,        count_fb,        NVL(count_entered_fb,                                                                                                                                                                                  
    0) count_entered_fb,        NVL(count_sent_fb, 0) count_sent_fb,        NVL(count_edited_fb, 0) count_edited_fb,                                                                                                                                                                                            
    NVL(count_complete_fb, 0) count_complete_fb,        NVL(count_withibcardiff_fb, 0) count_withibcardiff_fb      FROM                                                                                                                                                                                         
    (SELECT examiner_code,          COUNT(*) AS count_fb        FROM          (SELECT                                                                                                                                                                                                 
           examiner_code,            paper_code,            assessment_school          FROM            ( SELECT DISTINCT                                                                                                                                                                                        
    ce.examiner_code,              ce.paper_code,              ce.assessment_school            FROM              (SELECT                                                                                                                                                                                        
                            DISTINCT assessment_school,                                                                                                                                                                                                          
    paper_code,                examiner                                                                                                                                                                                                                                                                         
    Plan hash value: 651311258                                                                                                                                                                                                                                                                                  
    | Id  | Operation                                | Name                           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |                                                                                                                                                                         
    |   0 | SELECT STATEMENT                         |                                |       |       |       |  2785 (100)|          |                                                                                                                                                                         
    |*  1 |  FILTER                                  |                                |       |       |       |            |          |                                                                                                                                                                         
    |*  2 |   VIEW                                   |                                |     4 |  1104 |       |  2785   (7)| 00:00:43 |                                                                                                                                                                         
    |   3 |    WINDOW BUFFER                         |                                |     4 |  1000 |       |  2785   (7)| 00:00:43 |                                                                                                                                                                         
    |   4 |     COUNT                                |                                |       |       |       |            |          |                                                                                                                                                                         
    |   5 |      VIEW                                |                                |     4 |  1000 |       |  2785   (7)| 00:00:43 |                                                                                                                                                                         
    |   6 |       NESTED LOOPS                       |                                |     4 |   476 |       |  2785   (7)| 00:00:43 |                                                                                                                                                                         
    |   7 |        MERGE JOIN OUTER                  |                                |     4 |   368 |       |  2781   (7)| 00:00:43 |                                                                                                                                                                         
    |   8 |         VIEW                             |                                |     4 |    80 |       |    72   (3)| 00:00:02 |                                                                                                                                                                         
    |   9 |          SORT GROUP BY                   |                                |     4 |    28 |       |    72   (3)| 00:00:02 |                                                                                                                                                                         
    |  10 |           VIEW                           |                                |     4 |    28 |       |    72   (3)| 00:00:02 |                                                                                                                                                                         
    |  11 |            SORT UNIQUE                   |                                |     4 |   508 |       |    72   (3)| 00:00:02 |                                                                                                                                                                         
    |  12 |             NESTED LOOPS                 |                                |     4 |   508 |       |    71   (2)| 00:00:02 |                                                                                                                                                                         
    |* 13 |              HASH JOIN                   |                                |     1 |    68 |       |    44   (3)| 00:00:01 |                                                                                                                                                                         
    |* 14 |               TABLE ACCESS BY INDEX ROWID| SUBJECT_COMPONENT              |    13 |   520 |       |    40   (0)| 00:00:01 |                                                                                                                                                                         
    |* 15 |                INDEX RANGE SCAN          | SUBJECT_COMPONENT_ASSESS_TYPE  |  1059 |       |       |     9   (0)| 00:00:01 |                                                                                                                                                                         
    |* 16 |               INDEX RANGE SCAN           | SUBJECT_GROUP_PK               |    41 |  1148 |       |     3   (0)| 00:00:01 |                                                                                                                                                                         
    |* 17 |              INDEX RANGE SCAN            | CEA_AUTOMATIC_ALLOCATION_STATS |    30 |  1770 |       |    27   (0)| 00:00:01 |                                                                                                                                                                         
    |* 18 |         SORT JOIN                        |                                |   576 | 41472 |       |  2709   (7)| 00:00:42 |                                                                                                                                                                         
    |  19 |          VIEW                            |                                |   576 | 41472 |       |  2708   (7)| 00:00:42 |                                                                                                                                                                         
    |  20 |           SORT GROUP BY                  |                                |   576 | 21312 |       |  2708   (7)| 00:00:42 |                                                                                                                                                                         
    |* 21 |            HASH JOIN                     |                                | 52408 |  1893K|  1744K|  2701   (7)| 00:00:41 |                                                                                                                                                                         
    |* 22 |             TABLE ACCESS FULL            | IA_INSTANCES                   | 52408 |  1125K|       |  1263   (6)| 00:00:20 |                                                                                                                                                                         
    |  23 |             TABLE ACCESS FULL            | WORKFLOW_INSTANCE              |  1075K|    15M|       |   960   (7)| 00:00:15 |                                                                                                                                                                         
    |* 24 |        TABLE ACCESS BY INDEX ROWID       | PERSON                         |     1 |    27 |       |     1   (0)| 00:00:01 |                                                                                                                                                                         
    |* 25 |         INDEX UNIQUE SCAN                | PERSON_PK                      |     1 |       |       |     0   (0)|          |                                                                                                                                                                         
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                         
       1 - filter(TO_NUMBER(:V_START_ROW)<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1))                                                                                                                                                                                                                   
       2 - filter(("ROW_NUM">=TO_NUMBER(:V_START_ROW) AND "ROW_NUM"<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1)))                                                                                                                                                                                        
      13 - access("SC"."SUBJECT"="SG"."SUBJECT" AND "SC"."LVL"="SG"."LVL")                                                                                                                                                                                                                                      
      14 - filter(((:V_SUBJECT IS NULL OR "SC"."SUBJECT"=:V_SUBJECT) AND ("SC"."LVL"=:V_LVL OR :V_LVL IS NULL)))                                                                                                                                                                                                
      15 - access("SC"."YEAR"=TO_NUMBER(:V_YEAR) AND "SC"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                     
      16 - access("SG"."YEAR"=TO_NUMBER(:V_YEAR) AND "SG"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                     
           filter((:V_SUBJECT_GROUP IS NULL OR "SG"."GROUP_NUMBER"=TO_NUMBER(:V_SUBJECT_GROUP)))                                                                                                                                                                                                                
      17 - access("CEA"."YEAR"=TO_NUMBER(:V_YEAR) AND "CEA"."MONTH"=:V_MONTH AND "SC"."PAPER_CODE"="PAPER_CODE" AND                                                                                                                                                                                             
                  "CEA"."ELEMENT"='Moderation of IA')                                                                                                                                                                                                                                                           
           filter(("CEA"."ELEMENT"='Moderation of IA' AND (:V_PADDED_EXAMINER_CODE IS NULL OR                                                                                                                                                                                                                   
                  "EXAMINER_CODE"=:V_PADDED_EXAMINER_CODE)))                                                                                                                                                                                                                                                    
      18 - access("EXNAME"."EXAMINER_CODE"="IAF"."EXAMINER_CODE")                                                                                                                                                                                                                                               
           filter("EXNAME"."EXAMINER_CODE"="IAF"."EXAMINER_CODE")                                                                                                                                                                                                                                               
      21 - access("WFI"."INSTANCE_ID"="IA1"."WORKFLOW_INSTANCE_ID")                                                                                                                                                                                                                                             
      22 - filter(("IA1"."MONTH"=:V_MONTH AND "IA1"."YEAR"=TO_NUMBER(:V_YEAR)))                                                                                                                                                                                                                                 
      24 - filter((:V_EXAMINER_NAME IS NULL OR UPPER("TITLE"||' '||"FIRSTNAME"||' '||"LASTNAME") LIKE :V_SEARCH_EXAMINER_NAME))                                                                                                                                                                                 
      25 - access("EXNAME"."EXAMINER_CODE"="PERSON_CODE")                                                                                                                                                                                                                                                       
    66 rows selected

  • Can I rewrite the following query without using Row_number() function ??!!

    Hello every one, can I rewrite the following query without using the 'ROW_NUMBER() OVER ' part.
    The query is supposed to pull out the records whose CODE is not NULL and has most
    recent date for UPDATE_DATE . The reason I wanted to do this is, When I embed this query
    in between many other queries along with JOINs, My oracle server is unable to execute. So, I thought
    its better to supplant 'ROW_NUMBER() OVER ' logic with something else and try it. .
    SELECT a.* FROM
    (SELECT b.*, ROW_NUMBER() OVER (PARTITION BY b.PIDM
    ORDER BY b.UPDATE_DATE DESC) AS Rno
    FROM
    SELECT *
    FROM SHYNCRO WHERE CODE IS NOT NULL
    )b
    )a
    WHERE a.Rno = 1

    Hi,
    You didn't write over 150 lines of code and then start testing it, did you?
    Don't.
    Take baby steps. Write as little as pssiblem test that. Debug and test again until you have something that does exactly what you want it to do.
    When you have somehting that works perfectly, take one baby step. Add a tiny amount of code, maybe 1 or 2 lines more, and test again.
    When you do get an error, or wrong results, you'll have a much better idea of where the problem is. also, you won't be building code on a flimsy foundation.
    If you need help, post the last working version and the new version with the error. Explain what you're trying to do in the new version.
    The error message indicates line 133. It looks like line 133 of your code is blank. Does your front end allow completely blank lines in the middle of a query? SQL*Plus doesn't by default; you have to say
    SET  SQLBLANKLINES  ONto have a completely blank line in SQL*Plus. (However, lines containing nothing but at commnet are always allowed.)
    You may have noticed that this site normally doesn't display multiple spaces in a row.
    Whenever you post formatted text (such as indented code) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    The 4 people who posted small code fragments for you to read all did this.  It would be so much easier for people to read your humongeous query if it were formatted.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Question: Need help with overcoming the following message:  "Nothing was imported.

    Need help with overcoming the following message:  “Nothing was imported.  The file(s) or folder(s) selection to import did not contain any supported file types, or the files are already in this catalogue”.
    The photos being scanned are old film shots.  They have NOT been previously scanned.  I am using Photoshop Elements 9 software.
    QUESTION:  how do I override this STOP and or circumvent the photo comparison option????
    Thanks for the help. Bob K ---  [email protected]

      Are you scanning as jpeg, tiff or some other format?
    Are you using continuous numbering for files names as by definition scanned files have no exif data.
     

  • Hello  I need your help with installing the flash drive into my laptop

    Hi
    I am Rachel Friedman asking for your help with installing the flashdrive player into my laptop.
    Thanks
    Rachel

    To give you any useful advice, I'm going to need to know more about your computer and browser:
    https://forums.adobe.com/message/5249945#5249945

  • Help with updates - The software change returned error code 0x87D00215(-2016411115).

    I have rolled out bunch of updates across few hundred workstation systems.
    Few of the desktops have failed to install SOME of the updates and just can't get my head around as to why?
    Looking at one of the workstations, I can see 5 updates are pending download at 0%.
    Some of these fail after a while and with in Software Centre, I can see 'Help with updates - The software change returned error code 0x87D00215(-2016411115).'. Not exactly sure what this means, but I have tried clearing the cache and
    rebooting the workstations few times.
    (I have also tried to use Windows Update and install one of these manually, which worked.)

    Investigating this further, I have found the following in CAS.log:
    ICcmContentTransferManager::ModifyJobPriority failed with error 0x87d00215 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    No need to change timeout settings ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Successfully created download request {ED6E9E5C-E806-43CA-9F93-49AC72D1DEAD} for content 53bf87a2-bedf-4def-b0ec-9637613c3429.1 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Requesting locations synchronously for content 99ddb078-b780-4605-8fac-9607fe56450d.1 with priority Foreground ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    The number of discovered DPs(including Branch DP and Multicast) is 1 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Calling back with the following distribution points ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Distribution Point='http://DPSERVER.com/SMS_DP_SMSPKG$/99ddb078-b780-4605-8fac-9607fe56450d', Locality='LOCAL' ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Requesting content 99ddb078-b780-4605-8fac-9607fe56450d.1, size(KB) 0, under context System with priority Foreground ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    ICcmContentTransferManager::ModifyJobPriority failed with error 0x87d00215 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    No need to change timeout settings ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Successfully created download request {67B7E59B-A386-4EA8-BF39-2EB64B108A6C} for content 99ddb078-b780-4605-8fac-9607fe56450d.1 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Requesting locations synchronously for content 61d33de7-9582-41e3-82fc-3e0f970b60f3.1 with priority Foreground ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    The number of discovered DPs(including Branch DP and Multicast) is 1 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Calling back with the following distribution points ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Distribution Point='http://DPSERVER.com/SMS_DP_SMSPKG$/61d33de7-9582-41e3-82fc-3e0f970b60f3', Locality='LOCAL' ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Requesting content 61d33de7-9582-41e3-82fc-3e0f970b60f3.1, size(KB) 0, under context System with priority Foreground ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    ICcmContentTransferManager::ModifyJobPriority failed with error 0x87d00215 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    No need to change timeout settings ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Successfully created download request {12E48136-B545-4C42-9745-9FF97CE38D52} for content 61d33de7-9582-41e3-82fc-3e0f970b60f3.1 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)

  • Please help to set the time zone in a porper way

    Dear Folks please help to set the time zone in a porper way
    select sessiontimezone from dual;
    Database: Oracle 11.2.0.2
    Operating system: AIX 5.3
    SESSIONTIMEZONE
    +00:00
    SQL> select systimestamp from dual;
    SYSTIMESTAMP
    06-NOV-12 04.21.07.438426 AM +00:00
    SQL> select dbtimezone from dual;
    DBTIME
    +00:00
    SQL> Select DBMS_SCHEDULER.get_sys_time_zone_name from dual;
    GET_SYS_TIME_ZONE_NAME
    Asia/Kuala_Lumpur
    By looking Doc ID: Note:149120.1 in Metalink:
    ALTER DATABASE <my db name> SET TIME_ZONE = 'Asia/Kuala_Lumpur'
    or
    ALTER DATABASE <my db name> SET TIME_ZONE = '+08:00'
    For reflecting the change I refreshed the db by shutdown and restart.
    but still the returning no timezone value for user schema, please help how to set the time zone in a proper way?

    SQL> conn sys/sys as sysdba
    Connected.
    DBNAME
    db
    SQL> select u.name || '.' || o.name || '.' || c.name "Col TSLTZ"
      2    from sys.obj$ o, sys.col$ c, sys.user$ u
      3   where c.type# = 231
      4     and o.obj# = c.obj#
      5     and u.user# = o.owner#;
    no rows selected
    SQL>  select DBTIMEZONE from dual;
    DBTIME
    +00:00
    SQL> alter database set time_zone='Asia/Kuala_Lumpur';
    Database altered.
    SQL> select DBTIMEZONE from dual;
    DBTIME
    +00:00
    SQL> startup force;
    ORACLE instance started.
    Total System Global Area  426852352 bytes
    Fixed Size                  1375060 bytes
    Variable Size             260048044 bytes
    Database Buffers          159383552 bytes
    Redo Buffers                6045696 bytes
    Database mounted.
    Database opened.
    SQL> select DBTIMEZONE from dual;
    DBTIMEZONE
    Asia/Kuala_LumpurRefer:
    Re: how to check db time zone
    Edited by: Ora on 5 Nov, 2012 11:36 PM

  • Help in rewrite the Query

    Hello
    I have one query taking time to fetch the records. Table contains just 40,000 thousands records but lots of case statement in the query, I just remove lots of case statement there are lot more...
    Can you please help me out to rewrite the query to fetch the records faster. Also Right now there are no indexes on the table....
    SELECT O.cn,
           O.BEN_LAST_NAME,
           O.BEN_FIRST_NAME,
           O.BEN_MI,
           O.SSN,
           O.DOB,
           O.SEX,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 00 AND 34 THEN
               1
              ELSE
               0
           END AS AGE_GROUP0_34_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 35 AND 44 THEN
               1
              ELSE
               0
           END AS AGE_GROUP35_44_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 45 AND 54 THEN
               1
              ELSE
               0
           END AS AGE_GROUP45_54_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 55 AND 59 THEN
               1
              ELSE
               0
           END AS AGE_GROUP55_59_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 60 AND 64 THEN
               1
              ELSE
               0
           END AS AGE_GROUP60_64_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 65 AND 69 THEN
               1
              ELSE
               0
           END AS AGE_GROUP65_69_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 70 AND 74 THEN
               1
              ELSE
               0
           END AS AGE_GROUP70_74_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 75 AND 79 THEN
               1
              ELSE
               0
           END AS AGE_GROUP75_79_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 80 AND 84 THEN
               1
              ELSE
               0
           END AS AGE_GROUP80_84_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 85 AND 89 THEN
               1
              ELSE
               0
           END AS AGE_GROUP85_89_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 90 AND 94 THEN
               1
              ELSE
               0
           END AS AGE_GROUP90_94_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 95 AND 00 THEN
               1
              ELSE
               0
           END AS AGE_GROUP95_GT_F,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 00 AND 34 THEN
               1
              ELSE
               0
           END AS AGE_GROUP0_34_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 35 AND 44 THEN
               1
              ELSE
               0
           END AS AGE_GROUP35_44_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 45 AND 54 THEN
               1
              ELSE
               0
           END AS AGE_GROUP45_54_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 45 AND 59 THEN
               1
              ELSE
               0
           END AS AGE_GROUP55_59_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 60 AND 64 THEN
               1
              ELSE
               0
           END AS AGE_GROUP60_64_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 65 AND 69 THEN
               1
              ELSE
               0
           END AS AGE_GROUP65_69_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 70 AND 74 THEN
               1
              ELSE
               0
           END AS AGE_GROUP70_74_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 75 AND 79 THEN
               1
              ELSE
               0
           END AS AGE_GROUP75_79_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 80 AND 84 THEN
               1
              ELSE
               0
           END AS AGE_GROUP80_84_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 85 AND 89 THEN
               1
              ELSE
               0
           END AS AGE_GROUP85_89_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 90 AND 94 THEN
               1
              ELSE
               0
           END AS AGE_GROUP90_94_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 95 AND 00 THEN
               1
              ELSE
               0
           END AS AGE_GROUP95_GT_M,
           O.YEAR,
          CASE WHEN EXISTS (SELECT m1.hcc_model_category1 FROM HCC_MODEL_DIAGNOSIS M1 , HCC_MODEL_DIAGNOSIS_MAPPING HM
                            ,mor222 m2 WHERE m1.map_id = hm.map_id_ref
                            AND m2.YEAR = hm.YEAR
                            AND o.cn = m2.cn
                            AND o.YEAR = hm.YEAR
                            AND m1.hcc_model_category1 = 1
                            AND m2.diag_code = m1.icd9cmscode) THEN 1 ELSE 0 END AS DISEASE_COEF_HCC1,
          CASE WHEN EXISTS (SELECT m1.hcc_model_category1 FROM HCC_MODEL_DIAGNOSIS M1 , HCC_MODEL_DIAGNOSIS_MAPPING HM
                            ,mor222 m2 WHERE m1.map_id = hm.map_id_ref
                            AND m2.YEAR = hm.YEAR
                            AND o.cn = m2.cn
                            AND o.YEAR = hm.YEAR
                            AND m1.hcc_model_category1 = 2
                            AND m2.diag_code = m1.icd9cmscode) THEN 1 ELSE 0 END AS DISEASE_COEF_HCC2,
           CASE WHEN EXISTS (SELECT m1.hcc_model_category1 FROM HCC_MODEL_DIAGNOSIS M1 , HCC_MODEL_DIAGNOSIS_MAPPING HM
                            ,mor222 m2 WHERE m1.map_id = hm.map_id_ref
                            AND m2.YEAR = hm.YEAR
                            AND o.cn = m2.cn
                            AND o.YEAR = hm.YEAR
                            AND m1.hcc_model_category1 = 5
                             AND m2.diag_code = m1.icd9cmscode) THEN 1 ELSE 0 END AS       DISEASE_COEF_HCC5,
            CASE WHEN EXISTS (SELECT m1.hcc_model_category1 FROM HCC_MODEL_DIAGNOSIS M1 , HCC_MODEL_DIAGNOSIS_MAPPING HM
                            ,mor222 m2 WHERE m1.map_id = hm.map_id_ref
                            AND m2.YEAR = hm.YEAR
                            AND o.cn = m2.cn
                            AND o.YEAR = hm.YEAR
                            AND m1.hcc_model_category1 = 7
                            AND m2.diag_code = m1.icd9cmscode) THEN 1 ELSE 0 END AS      DISEASE_COEF_HCC7,
           CASE WHEN EXISTS (SELECT m1.hcc_model_category1 FROM HCC_MODEL_DIAGNOSIS M1 , HCC_MODEL_DIAGNOSIS_MAPPING HM
                            ,mor222 m2 WHERE m1.map_id = hm.map_id_ref
                            AND m2.YEAR = hm.YEAR
                            AND o.cn = m2.cn
                            AND o.YEAR = hm.YEAR
                            AND m1.hcc_model_category1 = 8
                            AND m2.diag_code = m1.icd9cmscode) THEN 1 ELSE 0 END AS       DISEASE_COEF_HCC8                   
      FROM (SELECT T.cn,
                   T.BEN_LAST_NAME,
                   T.BEN_FIRST_NAME,
                   T.BEN_MI,
                   T.SSN,
                   TO_DATE(T.DOB, 'YYYYMMDD') AS DOB,
                   T.SEX,
                   TRUNC(MONTHS_BETWEEN(TO_DATE('01/01/' || T.YEAR, 'MM/DD/YYYY'),
                                        TO_DATE(T.DOB, 'YYYYMMDD')) / 12) AS AGE,
                   T.YEAR
              FROM mor111 T ) O Thanks in advance!
    Kind regards,
    Nik

    Ok, so I am going to be a little bit kinder then your first reply, but not much.
    From what can tell you are doing medical management and are trying to select by AGE/GENDER CELLS and this is common when trying to deal with RBRVS.
    This is by far some of the worst sql I have ever seen, sorry but it just is.
    So please report this either as a new post or as a reply and:
    1. At least post the table definitions and if you can some sample data.
    2. Get rid of almost all the case selectors.
    3. Describe the output you need.
    As it is this is unreadable.
    After that we can talk more.
    Edited by: FlyingGuy on Oct 11, 2011 5:13 PM

  • Help with aggregate function max query

    I have a large database which stores daily oil life, odo readings from thousands of vehicles being tested but only once a month.
    I am trying to grab data from one month where only the EOL_READ = 0 and put all of those values into the previous month's query where EOL_READ = anything.
    Here is the original query which grabs everything
    (select distinct vdh.STID, vdh.CASE_SAK,
    max(to_number(decode(COMMAND_ID,'EOL_READ',COMMAND_RESULT,-100000))) EOL_READ,
    max(to_number(decode(COMMAND_ID,'ODO_READ',COMMAND_RESULT,-100000))) ODO_READ,
    max(to_number(decode(COMMAND_ID,'OIL_LIFE_PREDICTION',COMMAND_RESULT,-100000))) OIL_LIFE_PREDICTION
    from veh_diag_history vdh, c2pt_data_history cdh
    where vdh.veh_diag_history_sak = cdh.veh_diag_history_sak
    and cdh.COMMAND_ID in ('EOL_READ','ODO_READ','OIL_LIFE_PREDICTION')
    and vdh.LOGICAL_TRIGGER_SAK = 3
    and cdh.CREATED_TIMESTAMP =vdh.CREATED_TIMESTAMP
    and cdh.CREATED_TIMESTAMP >= to_date('03/01/2007 12:00:00 AM','mm/dd/yyyy HH:MI:SS AM')
    and cdh.CREATED_TIMESTAMP < to_date('04/01/2007 12:00:00 AM','mm/dd/yyyy HH:MI:SS AM')
    group by vdh.STID, vdh.case_sak
    having count(distinct command_id) = 3
    order by OIL_LIFE_PREDICTION)
    which gives 5 columns:
    STID, CASE_SAK, EOL_READ, ODO_READ, and OIL_LIFE_PREDICTION
    and gives me about 80000 rows returned for the above query
    I only want one reading per month, but sometimes I get two.
    STID is the unique identifier for a vehicle.
    I tried this query:
    I tried this query which nests one request within the other and SQL times out every time:
    select distinct vdh.STID, vdh.CASE_SAK,
    max(to_number(decode(COMMAND_ID,'EOL_READ',COMMAND_RESULT,-100000))) EOL_READ,
    max(to_number(decode(COMMAND_ID,'ODO_READ',COMMAND_RESULT,-100000))) ODO_READ,
    max(to_number(decode(COMMAND_ID,'OIL_LIFE_PREDICTION',COMMAND_RESULT,-100000))) OIL_LIFE_PREDICTION
    from veh_diag_history vdh, c2pt_data_history cdh
    where vdh.veh_diag_history_sak = cdh.veh_diag_history_sak
    and cdh.COMMAND_ID in ('EOL_READ','ODO_READ','OIL_LIFE_PREDICTION')
    and vdh.LOGICAL_TRIGGER_SAK = 3
    and cdh.CREATED_TIMESTAMP =vdh.CREATED_TIMESTAMP
    and cdh.CREATED_TIMESTAMP >= to_date('02/01/2007 12:00:00 AM','mm/dd/yyyy HH:MI:SS AM')
    and cdh.CREATED_TIMESTAMP < to_date('03/01/2007 12:00:00 AM','mm/dd/yyyy HH:MI:SS AM')
    group by vdh.STID, vdh.case_sak
    having count(distinct command_id) = 3
    and vdh.stid in (select distinct vdh.STID, vdh.CASE_SAK,
    max(to_number(decode(COMMAND_ID,'EOL_READ',COMMAND_RESULT,-100000))) EOL_READ,
    max(to_number(decode(COMMAND_ID,'ODO_READ',COMMAND_RESULT,-100000))) ODO_READ,
    max(to_number(decode(COMMAND_ID,'OIL_LIFE_PREDICTION',COMMAND_RESULT,-100000))) OIL_LIFE_PREDICTION
    from veh_diag_history vdh, c2pt_data_history cdh
    where vdh.veh_diag_history_sak = cdh.veh_diag_history_sak
    and cdh.COMMAND_ID in ('EOL_READ','ODO_READ','OIL_LIFE_PREDICTION')
    and vdh.LOGICAL_TRIGGER_SAK = 3
    and cdh.CREATED_TIMESTAMP =vdh.CREATED_TIMESTAMP
    and cdh.CREATED_TIMESTAMP >= to_date('03/01/2007 12:00:00 AM','mm/dd/yyyy HH:MI:SS AM')
    and cdh.CREATED_TIMESTAMP < to_date('04/01/2007 12:00:00 AM','mm/dd/yyyy HH:MI:SS AM')
    group by vdh.STID, vdh.case_sak
    having count(distinct command_id) = 3
    and (max(to_number(decode(COMMAND_ID,'EOL_READ',COMMAND_RESULT,-100000)))) = 0)
    order by OIL_LIFE_PREDICTION
    so in summary I am trying to select values from the previous month only from those stids where this month's value for EOL_READ = 0
    Any ideas.....please help.

    You can use row_number() within each stid and each month to determine the first read of each month. Then you can use lag() to get the previous month's reading of the current month's reading is zero.
    with all_data as (
    select stid,
           case_sak,
           eol_read,
           timestamp,
           row_number() over (partition by stid, trunc(timestamp,'mm') order by timestamp) AS rn
      from veh_diag_history
    select stid,
           case_sak,
           case
             when eol_read = 0
               then lag(eol_read) over (partition by stid order by timestamp)
             else eol_read
           end as eol_read
      from all_data
    where rn = 1;

  • Help with mapping the mod_plsql path with Apache

    Hi,
    I need help with mapping my pl/SQL Handler path.
    Currently i have an URL like this :
    http://myhost.com/pls/DADUSER/PLSQLPROC?param1=123
    But I need something like :
    http://myhost.com/d/PLSQLPROC?param1=123
    I tried to rename the "Location Handler" from "pls" to "d", works great, but it always appends my Default DAD User to the URL.
    And I tried to map my PL/SQL Handler to "/" and create a DAD User called "d" and set it to default. Didn't worked...
    Any help is appreciated....
    Bye,
    Oliver
    null

    Oliver,
    try to use the rewrite directive or the
    rewrite engine (mod_rewrite).
    Please see the Online documentation for how
    to do this:
    http://technet.oracle.com/docs/products/ias/doc_library/1021doc_otn/comm.102/a87562/apptroub.htm
    Hope it helps
    -Stefan

  • Help with Converting an Access query

    Hello:
    First time poster and would appreciate some help in converting this Access query into T-SQL so I can use in a Stored Procedure. I don't need help in resolving the syntax for the variables as parameter in the second query, but stuck in writing the first query
    in T-SQL . I assume I need some type of nested query with a left join to another query in T-SQL. 
    How do I convert this from Access into MS-SQL
    SELECT TBL_MONTH.L_Month, TBL_MONTH.L_MonthName
    FROM TBL_MONTH LEFT JOIN qry_MonthCheck ON TBL_MONTH.L_Month = qry_MonthCheck.L_Month
    WHERE (((qry_MonthCheck.L_Month) Is Null));
    qryMonthCheck in Access is defined as
    SELECT TBL_MONTH.L_Month, TBL_SIGNOFF.SO_YEAR, TBL_SIGNOFF.SO_USER, TBL_SIGNOFF.SO_LOCATION
    FROM TBL_MONTH RIGHT JOIN TBL_SIGNOFF ON TBL_MONTH.L_Month = TBL_SIGNOFF.SO_MONTH
    WHERE (((TBL_SIGNOFF.SO_YEAR)=[forms]![frm_signoff]![cboyear]) AND ((TBL_SIGNOFF.SO_LOCATION)=[Tempvars]![tmpVarUserLOC]));

    It is very much up to personal taste. For tables I use no prefix at all. Or suffix. I prefer plural: categories, products, etc. For junction tables, I drop the plural in the first entity, for instance productcategories. As for the case, many people prefer
    initial uppercase, while I go for lowercase only. But initial uppercase has its points, particularly in documentation. I am a staunch advocate of using case-sensitive collation for metadata. I don't see any point in mixing productcategories, Productcategories,
    ProductCategories etc. That can only cause confusion.
    As for either entities, I don't use views much, and I don't have any prefix for these either. In fact, several views I've been involved used to be tables once upon a time.
    If you want to add a marker to the object name, I recommend using a suffix. It is much easier to find objects in the version control system and other browser, when not everything is cluttered on the same letter. For instance, I typically add _sp at the end
    of stored procedure names.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Help with count and sum query

    Hi I am using oracle 10g. Trying to aggregate duplicate count records. I have so far:
    SELECT 'ST' LEDGER,
    CASE
    WHEN c.Category = 'E' THEN 'Headcount Exempt'
    ELSE 'Headcount Non-Exempt'
    END
    ACCOUNTS,
    CASE WHEN a.COMPANY = 'ZEE' THEN 'OH' ELSE 'NA' END MARKET,
    'MARCH_12' AS PERIOD,
    COUNT (a.empl_id) head_count
    FROM essbase.employee_pubinfo a
    LEFT OUTER JOIN MMS_DIST_COPY b
    ON a.cost_ctr = TRIM (b.bu)
    INNER JOIN MMS_GL_PAY_GROUPS c
    ON a.pay_group = c.group_code
    WHERE a.employee_status IN ('A', 'L', 'P', 'S')
    AND FISCAL_YEAR = '2012'
    AND FISCAL_MONTH = 'MARCH'
    GROUP BY a.company,
    b.district,
    a.cost_ctr,
    c.category,
    a.fiscal_month,
    a.fiscal_year;
    which gives me same rows with different head_counts. I am trying to combine the same rows as a total (one record). Do I use a subquery?

    Hi,
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    user610131 wrote:
    ... which gives me same rows with different head_counts.If they have different head_counts, then the rows are not the same.
    I am trying to combine the same rows as a total (one record). Do I use a subquery?Maybe. It's more likely that you need a different GROUP BY clause, since the GROUP BY clause determines how many rows of output there will be. I'll be able to say more after you post the sample data, results, and explanation.
    You may want both a sub-query and a different GROUP BY clause. For example:
    WITH    got_group_by_columns     AS
         SELECT  a.empl_id
         ,     CASE
                        WHEN  c.category = 'E'
                  THEN  'Headcount Exempt'
                        ELSE  'Headcount Non-Exempt'
                END          AS accounts
         ,       CASE
                        WHEN a.company = 'ZEE'
                        THEN 'OH'
                        ELSE 'NA'
                END          AS market
         FROM              essbase.employee_pubinfo a
         LEFT OUTER JOIN  mms_dist_copy             b  ON   a.cost_ctr     = TRIM (b.bu)
         INNER JOIN       mms_gl_pay_groups        c  ON   a.pay_group      = c.group_code
         WHERE     a.employee_status     IN ('A', 'L', 'P', 'S')
         AND        fiscal_year           = '2012'
         AND        fiscal_month          = 'MARCH'
    SELECT    'ST'               AS ledger
    ,       accounts
    ,       market
    ,       'MARCH_12'          AS period
    ,       COUNT (empl_id)       AS head_count
    FROM       got_group_by_columns
    GROUP BY  accounts
    ,            market
    ;But that's just a wild guess.
    You said you wanted "Help with count and sum". I see the COUNT, but what do you want with SUM? No doubt this will be clearer after you post the sample data and results.
    Edited by: Frank Kulash on Apr 4, 2012 5:31 PM

Maybe you are looking for