SQL Code help

Hi There,
We have a table "ALL_POS" that looks like the following:
ROHO@rohopr> desc all_pos
Name                                                  Null?    Type
OFFICE_TYPE_DESCRIPTION                                        VARCHAR2(60)
POSITION_ABBREVIATION                                          VARCHAR2(10)
POSITION                                                       VARCHAR2(60)
SD                                                             VARCHAR2(43)
HIRED                                                          NUMBER
OPEN                                                           NUMBERHere is the table sample data:
pss@pssd> select * from all_pos where ed = 'SD-100'
OFFICE_TYPE_DESCRIPTION                            POSITION_A POSITION                                 ED          HIRED       OPEN
DISTRICT                                           RL         Revision Lead                            SD-100          1          1
DISTRICT                                           SBHV       SBO - Home Visits                        SD-100          1          0
DISTRICT                                           SBS        SBO - Standby                            SD-100          0          1
DISTRICT                                           SBO        Special Ballot Officer                   SD-100          2          0
DISTRICT                                           TS         TECHNICAL SUPPORT                        SD-100          1          0
DISTRICT                                           TO         TRAINING OFFICER                         SD-100          3          0
DISTRICT                                           ICC                                                 SD-100          0          1
DISTRICT                                           EC         EVENT CLERK                              SD-100          1          0
DISTRICT                                           FO         Finance Officer                          SD-100          1          0
DISTRICT                                           APIA       Info. Asst - Adv Offices                 SD-100          4          0
DISTRICT                                           REC        RECRUITMENT OFFICER                      SD-100          2          0
DISTRICT                                           RES        RESOURCE STAFF                           SD-100         13          0
DISTRICT                                           RO         RETURNING OFFICER                        SD-100          1          1
DISTRICT                                           RA         REVISING AGENT                           SD-100         25         53
DISTRICT                                           RAS        REVISION ASSISTANT                       SD-100          0          2
DISTRICT                                           RC         Recruitment Clerk                        SD-100          0          2
OFFICE                                             DRO        RETURNING OFFICER                        SD-100        261          0
OFFICE                                             SBDRO      RETURNING OFFICER ON STAND-BY            SD-100         15          1
OFFICE                                             PC         OFFICE CLERK CC                          SD-100        261          0
AREA                                               APAM       AREA AREA MANAGER                        SD-100          1          0
AREA                                               AM         AREA MANAGER                             SD-100          5          0
LOCATION                                           IA         INFORMATION ASSISTANT                    SD-100         60          0
LOCATION                                           PDRA       DAY REVISION ASSISTANT                   SD-100         79          0
LOCATION                                           SDRO       SUPERVISING DEPUTY RETURNING OFFICER     SD-100         43          0
LOCATION                                           TD         Tabulator-DRO                            SD-100          1          0
OFFICE                                             APC        OFFICE CLERK                             SD-100         10          4
OFFICE                                             APDRO      OFFICE RETURNING OFFICER                 SD-100          5          2
27 rows selected.The SDs goes from SD-01 all through to SD-100. There are 40 distinct values for POSITION_ABBREVIATION as per the following:
pss@pssd> select distinct(POSITION_ABBREVIATION),POSITION from all_pos order by 1;
POSITION_A POSITION
ALO        ABORIGINAL L. OFFICER
AM         AREA MANAGER
APAM       OFFICE AREA MANAGER
APC        OFFICE CLERK
APC-R      OFFICE CLERK - REPLACEMENT
APDRO      OFFICE RETURNING OFFICER
APDRO-R    OFFICE RETURNING OFFICER - REPLACEMENT
APIA       Info. Asst - Adv OFFICEs
CLO        Community Liaison Officer
DRO        RETURNING OFFICER
DRO-R      RETURNING OFFICER - REPLACEMENT
EC         ELECTION CLERK
FO         Finance Officer
HLO        HOME L. OFFICER
IA         INFORMATION ASSISTANT
ICC
OEO        Other Election Officer
PC         OFFICE CLERK
PC-R       OFFICE CLERK - REPLACEMENT
PDRA       OFFICEING DAY REVISION ASSISTANT
PDRA-R     OFFICEING DAY REVISION ASSISTANT - REPLACEMENT
RA         REVISING AGENT
RAS        REVISION ASSISTANT
RC         Recruitment Clerk
REC        RECRUITMENT OFFICER
RES        RESOURCE STAFF
RL         Revision Lead
RO         RETURNING OFFICER
SBDRO      RETURNING OFFICER ON STAND-BY
SBHO       SBO - Hospital
SBHV       SBO - Home Visits
SBO        Special Ballot Officer
SBS        SBO - Standby
SDRO       SUPERVISING RETURNING OFFICER
SDRO-R     SUPERVISING RETURNING OFFICER - REPLACEMENT
SLO        Student L. Officer
TD         Tabulator-DRO
TD-R       Tabulator-DRO-Replacement
TO         TRAINING OFFICER
TS         TECHNICAL SUPPORTWe need to create a report that takes the POSITION_ABBREVIATION data displaying it in columns (horizontally), for all the SDs (1 to 100) something like the following:
SD      total_open  total_hired   ABO L. OFFICER   AREA MANAGER   OFFICE AREA MANAGER   OFFICE CLERK   OFFICE CLERK - REPLACEMENT   ...etc
SD-1           125            35              10              5                    10              10                          8 
SD-2           110            87              10             10                    25               3                          0
..etc
SD-100         300           120              20             22                    20              15                         28Can you kindly help us with the sql code to do that please.
P.S. oracle version 11.2.0.1 x64.
Thanks
Edited by: rsar001 on Nov 4, 2011 6:56 AM

Hi Frank,
Here is the table DDL, and inserts for 2 SDs (SD-1 and SD-2).
CREATE TABLE "ALL_POS"
(    "OFFICE_TYPE_DESCRIPTION" VARCHAR2(60),
      "POSITION_ABBREVIATION" VARCHAR2(10),
      "POSITION" VARCHAR2(60),
      "SD" VARCHAR2(43),
      "HIRED" NUMBER,
      "OPEN" NUMBER
insert into all_pos values ('DISTRICT'         ,'TS',     'TECHNICAL SUPPORT',              'SD-1',    2,0);
insert into all_pos values ('DISTRICT'         ,'TO',     'TRAINING OFFICER',               'SD-1',    1,0);
insert into all_pos values ('DISTRICT'         ,'EC',     'EVENT CLERK',                    'SD-1',    1,0);
insert into all_pos values ('DISTRICT'         ,'FO',     'Finance Officer',                'SD-1',    1,0);
insert into all_pos values ('DISTRICT'         ,'REC',    'RECRUITMENT OFFICER',            'SD-1',    1,0);
insert into all_pos values ('DISTRICT'         ,'RES',    'RESOURCE STAFF',                 'SD-1',   19,3);
insert into all_pos values ('DISTRICT'         ,'RO',     'RETURNING OFFICER',              'SD-1',    1,0);
insert into all_pos values ('DISTRICT'         ,'RA',     'REVISING AGENT',                 'SD-1',   25,9);
insert into all_pos values ('DISTRICT'         ,'RAS',    'REVISION ASSISTANT',             'SD-1',    2,0);
insert into all_pos values ('OFFICE'           , 'DRO',   'RETURNING OFFICER',              'SD-1',  218,4);
insert into all_pos values ('OFFICE'           , 'PC',    'OFFICE CLERK',                   'SD-1',  221,1);
insert into all_pos values ('OFFICE'           , 'APC',   'ADVANCE OFFICE CLERK',           'SD-1',    7,1);
insert into all_pos values ('OFFICE'           , 'APC-R', 'ADVANCE OFFICE CLERK - REPLACEMENT','SD-1', 2,0);
insert into all_pos values ('OFFICE'           , 'APDRO', 'OFFICE RETURNING OFFICER',           'SD-1',    5,0);
insert into all_pos values ('EVENT AREA'       , 'AM',    'AREA MANAGER',                   'SD-1',    4,0);
insert into all_pos values ('EVENT LOCATION'   , 'IA',    'INFORMATION ASSISTANT',          'SD-1',   28,0);
insert into all_pos values ('EVENT LOCATION'   , 'PDRA',  'OFFICEING DAY REVISION ASSISTANT','SD-1',   55,0);
insert into all_pos values ('EVENT LOCATION'   , 'SDRO',  'SUPERVISING RETURNING OFFICER',  'SD-1',   36,0);
insert into all_pos values ('DISTRICT',            'RL',     'Revision Lead',                  'SD-2',     1,   0);
insert into all_pos values ('DISTRICT',            'SBHV',   'SBO - Home Visits',              'SD-2',     2,   6);
insert into all_pos values ('DISTRICT',            'SBHO',   'SBO - Hospital',                 'SD-2',     5,   4);
insert into all_pos values ('DISTRICT',            'SBO',    'Special B Officer',              'SD-2',     7,   0);
insert into all_pos values ('DISTRICT',            'TS',     'TECHNICAL SUPPORT',              'SD-2',     1,   0);
insert into all_pos values ('DISTRICT',            'TO',     'TRAINING OFFICER',               'SD-2',     3,   0);
insert into all_pos values ('DISTRICT',            'ALO',    'AB L. OFFICER',                       'SD-2',     1,   0);
insert into all_pos values ('DISTRICT',            'EC',     'EVENT CLERK',                    'SD-2',     0,   1);
insert into all_pos values ('DISTRICT',            'FO',     'Finance Officer',                'SD-2',     1,   0);
insert into all_pos values ('DISTRICT',            'APIA',   'Info. Asst - Adv OFFICEs',       'SD-2',    15,   1);
insert into all_pos values ('DISTRICT',            'OEO',    'Other EVENT Officer',            'SD-2',     3,   0);
insert into all_pos values ('DISTRICT',            'REC',    'RECRUITMENT OFFICER',            'SD-2',     1,   0);
insert into all_pos values ('DISTRICT',            'RES',    'RESOURCE STAFF',                 'SD-2',    41,   0);
insert into all_pos values ('DISTRICT',            'RO',     'RETURNING OFFICER',              'SD-2',     0,   1);
insert into all_pos values ('DISTRICT',            'RA',     'REVISING AGENT',                 'SD-2',    16,  62);
insert into all_pos values ('DISTRICT',            'RAS',    'REVISION ASSISTANT',             'SD-2',     1,   1);
insert into all_pos values ('DISTRICT',            'RC',     'Recruitment Clerk',              'SD-2',     0,   1);
insert into all_pos values ('OFFICE',           'APDRO',  'OFFICE RETURNING OFFICER',            'SD-2',    15,   1);
insert into all_pos values ('OFFICE',           'DRO',    'RETURNING OFFICER',              'SD-2',   161,   0);
insert into all_pos values ('OFFICE',           'SBDRO',  'RETURNING OFFICER ON STAND-BY',  'SD-2',    31,  22);
insert into all_pos values ('OFFICE',           'PC',     'OFFICE CLERK',                   'SD-2',   161,   0);
insert into all_pos values ('EVENT AREA',       'AM',     'AREA MANAGER',                   'SD-2',    22,   0);
insert into all_pos values ('EVENT LOCATION',   'IA',     'INFORMATION ASSISTANT',          'SD-2',    73,   0);
insert into all_pos values ('EVENT LOCATION',   'PDRA',   'OFFICEING DAY REVISION ASSISTANT','SD-2',   23,   0);
insert into all_pos values ('EVENT LOCATION',   'SDRO',   'SUPERVISING RETURNING OFFICER',  'SD-2',    16,   0);
insert into all_pos values ('EVENT LOCATION',   'TD',     'Tabulator-DRO',                  'SD-2',     4,   0);
insert into all_pos values ('EVENT LOCATION',   'TD-R',   'Tabulator-DRO-Replacement',      'SD-2',     4,   0);
insert into all_pos values ('OFFICE',           'APC',    'ADVANCE OFFICE CLERK',           'SD-2',    30,   2);
commit;So, we're trying to display the data like so:
We need to create a report that takes the POSITION_ABBREVIATION data displaying it in columns (horizontally), for all the SDs (1 to 100) something like the following:
SD      total_open  total_hired   ABO L. OFFICER   AREA MANAGER   OFFICE AREA MANAGER   OFFICE CLERK   OFFICE CLERK - REPLACEMENT   ...etc
SD-1           125            35              10              5                    10              10                          8 
SD-2           110            87              10             10                    25               3                          0Thanks
Edited by: rsar001 on Nov 4, 2011 8:52 AM

Similar Messages

  • Pl/sql  code  help required

    i have 3 string like below
    string1  varchar2(3000) := ' fonction code=''33'' and the limit for the subfunction is 300. it may have function_code=''100'' ) ) ) )';
    string2  varchar2(2000):='function_code=''100''';
    string3  varchar2(3000);requirement is
    if i found string2 in string1 preceded by four brackets ,example function_code=''100'' ) ) ) )' then
    i have replace to replace the 4th bracket with
    function code is null  )the string1 now will be
    ' fonction code=''33'' and the limit for the subfunction is 300. it may have function_code=''100'' ) ) ) function code is null  )Pls help
    NOte: bracket may or may not have spaces between them
    S

    SQL> declare
      2  string1  varchar2(3000) := 'AND NOT  (     (       (   FUNCTION_CODE = ''88''  )  OR  (   FUNCTION_CODE = ''21''  )  OR  (   FUNCTION_CODE = ''51'' )  OR  (   FUNCTION_CODE = ''85'' )  )  )  )' ;
      3  string2  varchar2(2000):='FUNCTION_CODE = ''85''';
      4  string3  varchar2(3000);
      5  begin
      6  string3 :=regexp_replace(string1,'^(.*)('||string2||')(([[:blank:]]?\)[[:blank:]]?){3})([[:blank:]]?\))(.*)$','\1\2\3function code is null\4\5');
      7  dbms_output.put_line(string3);
      8  end;
      9  /
    AND NOT  (  (  (   FUNCTION_CODE = '88'  )  OR  (   FUNCTION_CODE = '21'  )  OR  (   FUNCTION_CODE = '51' )  OR  (
    FUNCTION_CODE = '85' )  )  ) function code is null )  )
    PL/SQL procedure successfully completed.Best regards
    Maxim

  • SQL Code help... not functioning correctly

    Hi I have the following code
    Select * FROM ACTIONS a, CUSTOMER b
    WHERE b.ID = 74
    AND b.ID = a.CUST_ID
    AND a.DATE BETWEEN '01/APR/2007' AND '31/MAR/2008';
    This works as expected and returns 2 actions - again as expected (actions were both on 22 May 2007 for customer 74)
    Then I want to update certain customers with the following...
    UPDATE CUSTOMER a
    SET a.CUSTOMER_ACTION = '0000'
    WHERE a.id = 74
    AND exists (
    select 1 from ACTIONS b
    WHERE b.DATE NOT BETWEEN '01-APR-07' AND '30-JUN-07'
    AND b.DATE NOT BETWEEN '01-JUL-07' AND '30-SEP-07'
    AND b.DATE NOT BETWEEN '01-OCT-07' AND '31-DEC-07'
    AND b.DATE NOT BETWEEN '01-JAN-08' AND '31-MAR-08'
    AND b.CUST_ID = a.ID);
    This then updates Customer 74 (this id no. will be dynamically called in - testing at moment with '74') with '0000' in its CUSTOMER_ACTION - however - I dont want it to update this customer as the dates say 'NOT BETWEEN' - so it shouldnt be returning anything thus shouldnt be updating this customer...but it does!!! Why?
    Can anyone see what's wrong with the code?

    and 74 did have some dates outside of the criteria so
    ive added
    AND b.DATE > '01-APR-07'
    think this has helped
    SCOTT@soti_10> desc customer
    Name                                      Null?    Type
    ID                                                 NUMBER(38)
    CUSTOMER_ACTION                                    VARCHAR2(4)
    SCOTT@soti_10> select * from customer;
            ID CUST
            74 1234
    SCOTT@soti_10> desc actions
    Name                                      Null?    Type
    ID                                                 NUMBER(38)
    A_DATE                                             DATE
    SCOTT@soti_10> select * from actions;
            ID A_DATE
            74 22-may-07
            74 22-may-07
            74 22-may-05
    SCOTT@soti_10> Select * FROM ACTIONS a, CUSTOMER b
      2  WHERE b.ID = 74
      3    AND b.ID = a.ID
      4    AND a.a_DATE BETWEEN '01/APR/2007' AND '31/MAR/2008';
            ID A_DATE            ID CUST
            74 22-may-07         74 1234
            74 22-may-07         74 1234
    SCOTT@soti_10>
    SCOTT@soti_10> Select * FROM ACTIONS a, CUSTOMER b
      2  WHERE b.ID = 74
      3    AND b.ID = a.ID
      4    AND a.a_DATE NOT BETWEEN '01/APR/2007' AND '31/MAR/2008';
            ID A_DATE            ID CUST
            74 22-may-05         74 1234
    SCOTT@soti_10> select * from customer a
      2  WHERE a.id = 74
      3    AND exists (
      4      select 1 from ACTIONS b
      5      WHERE b.a_DATE NOT BETWEEN '01-APR-07' AND '30-JUN-07'
      6        AND b.a_DATE NOT BETWEEN '01-JUL-07' AND '30-SEP-07'
      7        AND b.a_DATE NOT BETWEEN '01-OCT-07' AND '31-DEC-07'
      8        AND b.a_DATE NOT BETWEEN '01-JAN-08' AND '31-MAR-08'
      9        AND b.ID = a.ID
    10    )
    11  ;
            ID CUST
            74 1234
    SCOTT@soti_10> select * from customer a
      2  WHERE a.id = 74
      3    AND exists (
      4      select 1 from ACTIONS b
      5      WHERE b.a_DATE NOT BETWEEN '01-APR-07' AND '30-JUN-07'
      6        AND b.a_DATE NOT BETWEEN '01-JUL-07' AND '30-SEP-07'
      7        AND b.a_DATE NOT BETWEEN '01-OCT-07' AND '31-DEC-07'
      8        AND b.a_DATE NOT BETWEEN '01-JAN-08' AND '31-MAR-08'
      9        AND b.a_DATE > '01-APR-07'
    10        AND b.ID = a.ID
    11    )
    12  ;
    no rows selected
    SCOTT@soti_10> UPDATE CUSTOMER a
      2    SET a.CUSTOMER_ACTION = '0000'
      3  WHERE a.id = 74
      4    AND exists (
      5      select 1 from ACTIONS b
      6      WHERE b.a_DATE NOT BETWEEN '01-APR-07' AND '30-JUN-07'
      7        AND b.a_DATE NOT BETWEEN '01-JUL-07' AND '30-SEP-07'
      8        AND b.a_DATE NOT BETWEEN '01-OCT-07' AND '31-DEC-07'
      9        AND b.a_DATE NOT BETWEEN '01-JAN-08' AND '31-MAR-08'
    10        AND b.ID = a.ID
    11    )
    12  ;
    1 row updated.
    SCOTT@soti_10> rollback;
    Rollback complete.
    SCOTT@soti_10> UPDATE CUSTOMER a
      2    SET a.CUSTOMER_ACTION = '0000'
      3  WHERE a.id = 74
      4    AND exists (
      5      select 1 from ACTIONS b
      6      WHERE b.a_DATE NOT BETWEEN '01-APR-07' AND '30-JUN-07'
      7        AND b.a_DATE NOT BETWEEN '01-JUL-07' AND '30-SEP-07'
      8        AND b.a_DATE NOT BETWEEN '01-OCT-07' AND '31-DEC-07'
      9        AND b.a_DATE NOT BETWEEN '01-JAN-08' AND '31-MAR-08'
    10        AND b.a_DATE > '01-APR-07'
    11        AND b.ID = a.ID
    12    )
    13  ;
    0 rows updated.
    SCOTT@soti_10> rollback;
    Rollback complete.Have I missed something?
    Regards,
    Dima

  • PL/SQL Code help

    please can anyone explain this code? I need to add some lines to include more dates...
    UPDATE donor_report_t
         SET CUMULATIVE_EXP = (select round(sum (nvl(PERIOD_ACTIVITY_A,0) + nvl(PERIOD_ACTIVITY_E,0) + nvl(PRDOPEN_A,0) + nvl(PRDOPEN_E,0) ),0)
         from PAYMAN.SNP_OP_DETAIL@OFA
    where segment3= p_cc
         and segment2 in (select gl_acct from DONOR_REPORT_ACCT_MAPPING_T
         where cc= p_cc and category = x.category and gl_acct is not null)
         and substr(period_name,-2) < substr(p_period_name,-2) and period_name like 'DEC_ADJ-%' and period_name <> p_period_name )
         where category = x.category and category <> 'Total Receipts';

    Hi,
    Start by formatting the code, so that you can easily see the separate sub-queries and their clauses:
    UPDATE  donor_report_t
    SET      cumulative_exp = (
                               SELECT  ROUND ( SUM ( NVL (period_activity_a, 0)
                                                + NVL (period_activity_e, 0)
                                   + NVL (prdopen_a,        0)
                                   + NVL (prdopen_e,        0)
                                 , 0
                        FROM    payman.snp_op_detail@ofa
                        WHERE   segment3     = p_cc
                        AND     segment2     IN (
                                                   SELECT  gl_acct
                                         FROM    donor_report_acct_mapping_t
                                         WHERE   cc     = p_cc
                                         AND     category = x.category
                                         AND     gl_acct     IS NOT NULL
                        AND     SUBSTR (period_name, -2) < SUBSTR (p_period_name, -2)
                        AND     period_name            LIKE 'DEC_ADJ-%'
                        AND     period_name            != p_period_name     -- I'm guessing this is what you meant
    WHERE    category = x.category
    AND      category != 'Total Receipts'     -- I'm guessing this is what you meant
    ; What exactly does it do? That depends on which columns are in which tables. You should qualify all columns with the table name or alias.
    Is this part of a PL/SQL routine, where x is defined and set before this statement is run? Post the complete routine, or a simplified version that works.

  • Help with SQL code

    Hi having a slight problem with some SQL code -
    We store a number of actions they get given a date_done, a Y if we Met_Customer, a Y if we had an Upsell_Apps , a Y if we Upsell_Other, a Y if there was a reference and a Y if there was an issue. The action must have a date, but can have none to any of the Y's
    We want SQL to report back the number of actions (so the count) broken down into the months of the date_done - so Aug 07, Sep 07 etc etc. And this again broken down for Met_customer, Upsell_apps, upsell_other, reference and issue.
    We want it to look something like this...
    Action Type-------------------- Oct06 | Nov06 | Dec06 | Jan07
    Met Customer--------------------12--------8-----------4----------2
    Upsell App-------------------------21--------0-----------1----------3
    Upsell Other-----------------------0---------1-----------3----------1
    Reference---------------------------2---------6----------7----------3
    Issue---------------------------------0----------0----------1----------0
    So if an action on 12-Oc-06 had a Y in Met_customer and Y in Upsell_app it would be counted twice in the above - whereas below it does not work like that...
    At the moment the code is producing something like the following...
    MET_CUST | USPELL_APP | UPSELL_OTHER | REFERENCE | ISSUE | Oct06 | Nov06
    ------Y------------------------------------------------------------------------------------------------------12--------2
    ------Y-------------------Y---------------------------------------------------------------------------------11--------0
    ---------------------------Y----------------------------------------------------------------------------------1---------3
    ------------------------------------------------------Y-------------------------------------------Y----------6---------0
    --------------------------------------------------------------------------------Y-----------------------------2---------1
    ---------------------------------------------------------------------------------------------------Y----------0----------1
    ---------------------------------------------------------------------------------------------------------------1---------1
    This is the code we're using
    SELECT
    ACTION_MET_CUSTOMER,
    ACTION_UPSELL_APPS,
    ACTION_UPSELL_OTHER,
    ACTION_REFERENCE,
    ACTION_ISSUE,
    SUM ( decode( substr(DATE_DONE,-3,1), '-', cnt, null ) ) TOTAL,
    SUM ( decode( substr(DATE_DONE,-6,6), 'OCT-06', cnt, null ) ) OCT06,
    SUM ( decode( substr(DATE_DONE,-6,6), 'NOV-06', cnt, null ) ) NOV06,
    SUM ( decode( substr(DATE_DONE,-6,6), 'DEC-06', cnt, null ) ) DEC06,
    SUM ( decode( substr(DATE_DONE,-6,6), 'JAN-07', cnt, null ) ) JAN07,
    SUM ( decode( substr(DATE_DONE,-6,6), 'FEB-07', cnt, null ) ) FEB07,
    SUM ( decode( substr(DATE_DONE,-6,6), 'MAR-07', cnt, null ) ) MAR07,
    SUM ( decode( substr(DATE_DONE,-6,6), 'APR-07', cnt, null ) ) APR07,
    SUM ( decode( substr(DATE_DONE,-6,6), 'MAY-07', cnt, null ) ) MAY07,
    SUM ( decode( substr(DATE_DONE,-6,6), 'JUN-07', cnt, null ) ) JUN07,
    SUM ( decode( substr(DATE_DONE,-6,6), 'JUL-07', cnt, null ) ) JUL07,
    SUM ( decode( substr(DATE_DONE,-6,6), 'AUG-07', cnt, null ) ) AUG07,
    SUM ( decode( substr(DATE_DONE,-6,6), 'SEP-07', cnt, null ) ) SEP07,
    SUM ( decode( substr(DATE_DONE,-6,6), 'OCT-07', cnt, null ) ) OCT07,
    SUM ( decode( substr(DATE_DONE,-6,6), 'NOV-07', cnt, null ) ) NOV07,
    SUM ( decode( substr(DATE_DONE,-6,6), 'DEC-07', cnt, null ) ) DEC07,
    SUM ( decode( substr(DATE_DONE,-6,6), 'JAN-08', cnt, null ) ) JAN08,
    SUM ( decode( substr(DATE_DONE,-6,6), 'FEB-08', cnt, null ) ) FEB08,
    SUM ( decode( substr(DATE_DONE,-6,6), 'MAR-08', cnt, null ) ) MAR08,
    SUM ( decode( substr(DATE_DONE,-6,6), 'APR-08', cnt, null ) ) APR08,
    SUM ( decode( substr(DATE_DONE,-6,6), 'MAY-08', cnt, null ) ) MAY08
    FROM
    (SELECT ACTION_MET_CUSTOMER, ACTION_UPSELL_APPS, ACTION_UPSELL_OTHER, ACTION_REFERENCE, ACTION_ISSUE, DATE_DONE, COUNT(*) CNT FROM ACTIONS, EMPLOYEE
    WHERE ACTION_OWNER = NAME
    GROUP BY ACTION_MET_CUSTOMER, ACTION_UPSELL_APPS, ACTION_UPSELL_OTHER, ACTION_REFERENCE, ACTION_ISSUE, DATE_DONE)
    GROUP BY
    ACTION_MET_CUSTOMER, ACTION_UPSELL_APPS, ACTION_UPSELL_OTHER, ACTION_REFERENCE, ACTION_ISSUE
    Any ideas to get it looking how id ideally like it?
    Cheers, would be a great help
    S

    select 'Met Customer' action_type,
    to_char(date_done,'MON-YY') date_done,
    action_owner,
    COUNT(1)
    from ff_actions
    where action_met_customer = 'Y'
    group by action_met_customer
    UNION
    select 'Upsell Apps' action_type,
    to_char(date_done,'MON-YY') date_done,
    action_owner,
    COUNT(1)
    from ff_actions
    where action_upsell_apps = 'Y'
    group by action_upsell_apps
    UNION
    select 'Upsell Other' action_type,
    to_char(date_done,'MON-YY') date_done,
    action_owner,
    COUNT(1)
    from ff_actions
    where action_upsell_other = 'Y'
    group by action_upsell_other
    UNION
    select 'Reference' action_type,
    to_char(date_done,'MON-YY') date_done,
    action_owner,
    COUNT(1)
    from ff_actions
    where action_reference = 'Y'
    group by action_reference
    UNION
    select 'Issue' action_type,
    to_char(date_done,'MON-YY') date_done,
    action_owner,
    COUNT(1)
    from ff_actions
    where action_issue = 'Y'
    group by action_issue
    now error...
    ORA-00979: not a GROUP BY expression

  • Sql query help

    hi guys
    i have sample data as mentioned below... need to find the duplicate rows where cd=cd and dt1=dt1 and tm1 difference should be less than or equal to 4 hrs..
    i can get the data with the query written below but my problem is that i am not allowed to use in-built sql server function... can you help me in writing the same without using in-built function...
    CREATE TABLE #t (id INT,dt1 datetime, tm1 datetime,cd varchar(10))
    INSERT INTO #t VALUES (101,'2013-04-24','1900-01-01 12:20:00.000','TC')
    INSERT INTO #t VALUES (101,'2013-04-24','1900-01-01 12:30:00.000','TC')
    INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 14:30:00.000','MN')
    INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 15:07:00.000','MN')
    INSERT INTO #t VALUES (101,'2013-07-06','1900-01-01 09:07:00.000','XY')
    INSERT INTO #t VALUES (101,'2013-11-27','1900-01-01 09:50:00.000','LM')
    INSERT INTO #t VALUES (101,'2013-07-06','1900-01-01 15:07:00.000','XY')
    select * From #t
    WITH MyCTE (rn,id, dt1, tm1, cd)
    AS(
    select row_number() over (partition by id ORDER BY dt1, tm1) rn,* from #t
    select case when ((dt1 = lead_start_Date) and (ct <='4.0') and (base_cd = lead_cd)) then 'Duplicate_Req' else '' end dt123,* from
    select abs(convert(decimal(5,1),datediff(MI,lead_Start_time,tm1)/60.00)) ct, * from
    SELECT base.rn b_rn,LEAd.rn l_rn,BASE.id
    ,BASE.dt1
    ,BASE.tm1
    ,base.cd base_cd
    ,LEAD.dt1 LEAD_START_DATE
    ,LEAD.tm1 LEAD_START_TIME
    ,lead.cd lead_cd
    --,DATEADD(dd,-1,LEAD.dt1) EXPECTED_END_DATE
    FROM MyCTE BASE
    LEFT JOIN MyCTE LEAD ON BASE.id = LEAD.id
    AND BASE.rn = LEAD.rn+1
    ) b
    )c

    if this code will not work for you then not sure if there are any other options
    Converted the CTE into an actual temp table.
    CTE and barebones T-SQL code are included in the script below.
    CREATE TABLE #t (id INT,dt1 datetime, tm1 datetime,cd varchar(10))
    INSERT INTO #t VALUES (101,'2013-04-24','1900-01-01 12:20:00.000','TC')
    INSERT INTO #t VALUES (101,'2013-04-24','1900-01-01 12:30:00.000','TC')
    INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 14:30:00.000','MN')
    INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 15:07:00.000','MN')
    INSERT INTO #t VALUES (101,'2013-07-06','1900-01-01 09:07:00.000','XY')
    INSERT INTO #t VALUES (101,'2013-11-27','1900-01-01 09:50:00.000','LM')
    INSERT INTO #t VALUES (101,'2013-07-06','1900-01-01 15:07:00.000','XY')
    INSERT INTO #t VALUES (101,'2013-08-02','1900-01-01 15:07:00.000','MN')
    select * From #t
    ;WITH MyCTE (rn,id, dt1, tm1, cd)
    AS(
    select row_number() over (partition by id ORDER BY dt1, tm1) rn,* from #t
    select case when ((dt1 = lead_start_Date) and (ct <='4.0') and (base_cd = lead_cd)) then 'Duplicate_Req' else '' end dt123,* from
    select abs(convert(decimal(5,1),datediff(MI,lead_Start_time,tm1)/60.00)) ct, * from
    SELECT base.rn b_rn,LEAd.rn l_rn,BASE.id
    ,BASE.dt1
    ,BASE.tm1
    ,base.cd base_cd
    ,LEAD.dt1 LEAD_START_DATE
    ,LEAD.tm1 LEAD_START_TIME
    ,lead.cd lead_cd
    --,DATEADD(dd,-1,LEAD.dt1) EXPECTED_END_DATE
    FROM MyCTE BASE
    LEFT JOIN MyCTE LEAD ON BASE.id = LEAD.id
    AND BASE.rn = LEAD.rn+1
    ) b
    )c
    select * into #copy From #t order by id, cd, dt1, tm1
    alter table #copy add seqno int identity(1,1)
    select distinct y.id,y.cd,y.dt1,y.tm1,y.seqno,case when z.cd is not null then 'Duplicate_Req' else '' end dt123
    from #copy y
    left outer join
    (select a.id,a.cd,a.dt1,a.tm1
    From #copy a
    left outer join #copy b
    on a.id = b.id
    and a.cd = b.cd
    and a.dt1 = b.dt1
    where a.seqno > b.seqno
    and abs(datediff(MINUTE,b.tm1,a.tm1)) <= 240) z
    on y.id = z.id
    and y.cd = z.cd
    and y.dt1 = z.dt1
    and y.tm1 = z.tm1
    order by y.dt1,y.tm1
    drop table #copy
    drop table #t

  • PL/SQL Code not working without debug statements

    Hi Guys,
    I have a pl/sql code in a procedure, logic iterates through almost 40K records, conditional delete and update.
    When I execute this code, I dont see the deletes and updates happening, though procedure executes for 8 minutes and exits wihtout any error, execption.
    In same procedure when I write some debug statements like dbms_output, then everything seems to be working fine.
    I know this scenario happens in Oracle Forms, wehre we use SYNCHRONIZE.
    But this is plain pl/sql procedure.
    any thoughts on this?
    Av.

    COMMIT ?
    Aside from that, no idea what your procedure looks like, what it does, what version of Oracle you are using, how you are determining "I dont see the deletes and updates happening". etc...
    You'd need to provide a slew of information for anyone to give you any meaningful help.
    I can only assure you that DBMS_OUTPUT doesn't do magic :)

  • Multiple SQL queries in additional PL/SQL code in Report

    Hello gurus,
    I have a form in my portal populated some searching parameters and these parameters inserted into some temporary tables such as name_temp, addr_temp. And then I have a report that run based on these parameters, I have added additional PL/SQL code in the report at the time after the header was displayed. The code is as follows:
    declare
    checkname varchar2(40);
    checkaddr varchar2(100);
    begin
    select emp.name into checkname from emp
    where name = (select name from name_temp);
    select personnel.addr into checkaddr from personnel
    where addr = (select address from addr_temp);
    end;
    The problem I have is always the first SQL statement was executed, but not the second one, nor the third one. Does PL/SQL only supports one SQL statement per call? Please help. Is there a better way to handle this case?
    Thanks.
    Vince

    Hello gurus,
    I have a form in my portal populated some searching parameters and these parameters inserted into some temporary tables such as name_temp, addr_temp. And then I have a report that run based on these parameters, I have added additional PL/SQL code in the report at the time after the header was displayed. The code is as follows:
    declare
    checkname varchar2(40);
    checkaddr varchar2(100);
    begin
    select emp.name into checkname from emp
    where name = (select name from name_temp);
    select personnel.addr into checkaddr from personnel
    where addr = (select address from addr_temp);
    end;
    The problem I have is always the first SQL statement was executed, but not the second one, nor the third one. Does PL/SQL only supports one SQL statement per call? Please help. Is there a better way to handle this case?
    Thanks.
    Vince

  • How can one  read a Excel File and Upload into Table using Pl/SQL Code.

    How can one read a Excel File and Upload into Table using Pl/SQL Code.
    1. Excel File is on My PC.
    2. And I want to write a Stored Procedure or Package to do that.
    3. DataBase is on Other Server. Client-Server Environment.
    4. I am Using Toad or PlSql developer tool.

    If you would like to create a package/procedure in order to solve this problem consider using the UTL_FILE in built package, here are a few steps to get you going:
    1. Get your DBA to create directory object in oracle using the following command:
    create directory TEST_DIR as ‘directory_path’;
    Note: This directory is on the server.
    2. Grant read,write on directory directory_object_name to username;
    You can find out the directory_object_name value from dba_directories view if you are using the system user account.
    3. Logon as the user as mentioned above.
    Sample code read plain text file code, you can modify this code to suit your need (i.e. read a csv file)
    function getData(p_filename in varchar2,
    p_filepath in varchar2
    ) RETURN VARCHAR2 is
    input_file utl_file.file_type;
    --declare a buffer to read text data
    input_buffer varchar2(4000);
    begin
    --using the UTL_FILE in built package
    input_file := utl_file.fopen(p_filepath, p_filename, 'R');
    utl_file.get_line(input_file, input_buffer);
    --debug
    --dbms_output.put_line(input_buffer);
    utl_file.fclose(input_file);
    --return data
    return input_buffer;
    end;
    Hope this helps.

  • Query SQL code gets deleted after export to Excel. "Query must have at least one destination field"

    Hi all,
    I'm getting really frustrated by this Access error. It happens when I export the result of a query through an Access macro to Excel, the first time it runs well but the next time, there is a chance that the query won't run and the error "Query
    must have at least one destination field" will be displayed. After that, I try to check the query SQL code and discover the code has vanished. I'm using simple Select query without joins, only "where", "group by" and "order by"
    statements.
    Thank you in advance for your help,
    Jesus 
    Edit:
    One of these queries are like the following (all of them are of this type):
    SELECT Field1, field2, field3, field4, field5, Sum(Field6) AS SumOfField6, Sum(Field7) AS SumOfField7
    FROM Table1
    WHERE Field6 is not null
    GROUP BY Field1, field2, field3, field4, field5
    Order By Sum(Field6) desc

    Hi Peter, 
    Thank you for your response, I updated the original question with one of the codes.
    Thanks,
    Jesus

  • Getting error while compiling this pl/sql code

    Hi,
    I am trying to execute the below block of pl/sql code and i encountering an error. i tried all possible combination of paranthesis and quotes. still giving error. can someone please help?
    IF inserting THEN
    pk_imdb_audit.p_ins_characteristic_a_t
    (in_'||rpad(column_name,35,' ')||'=> pk_imdb_audit.v_action_inserting,'
    WHEN max_col = column_id THEN
    in_'||rpad(column_name,35,' ')||'=> '||lower(in_col_value)||');'
    ELSE
    ' in_'||rpad(column_name,35,' ')||'=> '||lower(in_col_value)||','
    END text,
    table_name,
    column_id,
    2 disp_ord
    error snapshot:-
    ORA-06550: line 14, column 14:
    PLS-00103: Encountered the symbol "||rpad(column_name,35," when expecting one of the following:
    . ( ) , * @ % & | = - + < / > at in is mod remainder not
    range rem => .. <an exponent (**)> <> or != or ~= >= <= <>
    and or like LIKE2_ LIKE4_ LIKEC_ as between from using ||
    multiset member SUBMULTISET_
    The symbol "( was inserted before "||rpad(column_name,35," to continue.
    ORA-06550: line 15, column 13:
    PLS-00103: Encountered the symbol "WHEN" when expecting one of th

    Hi,
    here is a 'parseable' version of your query, but there is numerous ways to improve what you want to do (not sure even if the query is giving you what you're expecting from it):
    SELECT text
    FROM   (SELECT (CASE
                       WHEN min_col = max_col THEN    'CREATE OR REPLACE TRIGGER '
                                                   || SUBSTR(column_name,
                                                             1,
                                                             4
                                                   || 'aud
    AFTER INSERT
    OR UPDATE
    OF '
                                                   || column_name
                                                   || ',
    OR DELETE ON imdb.'
                                                   || table_name
                                                   || '
    FOR EACH ROW'
                       ELSE(CASE
                               WHEN min_col = column_id THEN    'CREATE OR REPLACE TRIGGER '
                                                             || SUBSTR(column_name,
                                                                       1,
                                                                       4
                                                             || 'aud
    AFTER INSERT
    OR UPDATE
    OF '
                                                             || column_name
                                                             || ','
                               ELSE(CASE
                                       WHEN max_col = column_id THEN    ' '
                                                                     || column_name
                                                                     || '
    OR DELETE ON imdb.'
                                                                     || table_name
                                                                     || '
    FOR EACH ROW'
                                       ELSE(CASE
                                               WHEN column_id IS NULL THEN    'CREATE OR REPLACE TRIGGER '
                                                                           || SUBSTR
                                                                                 (column_name,
                                                                                  1,
                                                                                  4
                                                                           || 'aud
    AFTER INSERT
    OR UPDATE
    OR DELETE ON imdb.'
                                                                           || table_name
                                               ELSE    ' '
                                                    || column_name
                                                    || ','
                                            END
                                    END
                            END
                    END
                   ) text,
                   table_name1 table_name,
                   column_id,
                   1 disp_ord
            FROM   (SELECT LOWER(REPLACE(column_name,
                                         'O_',
                                        )) column_name,                   /*changing O to O_*/
                           LOWER(REPLACE(t.table_name,
                                         '_A_',
                                        )) table_name,
                           LOWER(t.table_name) table_name1,
                           c.column_id,
                           MIN(column_id) OVER(PARTITION BY c.table_name) min_col,
                           MAX(column_id) OVER(PARTITION BY c.table_name) max_col
                    FROM   all_tab_columns c,
                           (SELECT object_name table_name
                            FROM   all_objects
                            WHERE  TRUNC(created) = TRUNC(SYSDATE)
                            AND    object_name = 'CHARACTERISTIC_A_T') t
    --AND object_name LIKE 'IMDB/_A/_%' ESCAPE '/') t /*commented this line for testing*/
                    WHERE  c.table_name(+) = t.table_name
                    AND    SUBSTR(column_name(+),
                                  1,
                                  2
                                 ) = 'O_'))
              /*changed the substring condition to match new changes*/
    UNION ALL
    SELECT (CASE
               WHEN min_col = column_id THEN    'DECLARE
    BEGIN
    IF inserting THEN
    pk_imdb_audit.p_ins_characteristic_a_t
    (in_'
                                             || RPAD(column_name,
                                                     35,
                                             || '=> pk_imdb_audit.v_action_inserting,'
               ELSE(CASE
                       WHEN max_col = column_id THEN    'in_'
                                                     || RPAD(column_name,
                                                             35,
                                                     || '=> '
                                                     || LOWER(in_col_value)
                                                     || ');'
                       ELSE    ' in_'
                            || RPAD(column_name,
                                    35,
                            || '=> '
                            || LOWER(in_col_value)
                            || ','
                    END
            END
           ) text /*,
           table_name,
           column_id,
           2 disp_ord*/
    FROM   (SELECT table_name,
                   column_name,
                   column_id,
                   min_col,
                   max_col,
                   in_col_value,
                   trg_header,
                      'in_'
                   || RPAD(column_name,
                           35,
                   || '=> '
                   || LOWER(in_col_value)
                   || ',' in_col
            FROM   (SELECT   LOWER(c.column_name) column_name,
                             LOWER(c.table_name) table_name,
                             c.column_id,
                             (CASE
                                 WHEN SUBSTR(column_name,
                                             1,
                                             2
                                            ) = 'N_' THEN
                                   /*changed the substring condition to match the new change*/
                                                            ':NEW.'
                                                         || REPLACE
                                                               (column_name,
                                                                'N_',
                                                                'N_'
                                            /*changed the condition to match new requirement*/
                                 WHEN SUBSTR(column_name,
                                             1,
                                             2
                                            ) = 'O_' THEN
                                   /*changed the substring condition to match the new change*/
                                                         'NULL'
                                 ELSE    ':NEW.'
                                      || REPLACE(column_name,
                                                 '_A_',
                              END
                             ) in_col_value,
                             LOWER(SUBSTR(column_name,
                                          1,
                                          3
                                         )) trg_header,
                             MIN(column_id) OVER(PARTITION BY c.table_name) min_col,
                             MAX(column_id) OVER(PARTITION BY c.table_name) max_col
                    FROM     all_tab_columns c
                    WHERE    c.table_name IN(
                                SELECT object_name
                                FROM   all_objects
                                WHERE  TRUNC(created) = TRUNC(SYSDATE)
                                AND    object_name = 'CHARACTERISTIC_A_T')
                    ORDER BY c.table_name,
                             c.column_id))

  • APEX,PDF's, BI Publisher and SQL Query returning SQL code..

    I don't know if I should be posting this in this Forum or the BI Publisher forum, so I am posting in BOTH forums..
    I love APEX, let me say that first.. And appreciate the support offered here by the group, but am running int a confusing issue when BI Publisher tries to build a report from the above type APEX report..
    Here is my dilemma:
    I have a number of reports that are part of a Oracle package. They return an SQL Query back to a reports region on a page. I am having to deal with the column names returned are col01, col02..
    The issue I have is, when building the Application Level query to download the XML sample from in building RTF layouts in Word, you can not use this code, you MUST use a standard SQL Select.
    I have taken the sql from the function returning sql, and copied into the application query, supplying the required data values for bind variables being used in the query.
    An XML file is produced, and I use this to build the RTF format file that I load back into APEX and try to use it for the PDF rendering of the report. I can view the output as a PDF in the Word add on, but when I try using it with the report, it is returning an empty PDF file.
    Can anyone tell me what error log files on the bi publisher side I can look at to see what error is happening?
    Thank you,
    Tony Miller
    UTMB/EHN
    Title adjusted to allow people to know what I am talking about...
    Message was edited by:
    Tony Miller

    Tony,
    You can find the log as follows:
    - go to http://[yourserver]:[yourport]/em
    - logon to OC4J EM: oc4jadmin/[yourpassword]
    - click on "logs" at the bottom of the page
    - in the hgrid/tree, expand OC4J->home->Application
    xmlpserver
    - click on view log icon
    You can also observe what's going on in BI Publisher
    by going to the command prompt from where you started
    it.
    Or, as a third option, you can locate the file on
    your file system, depending on your setup, the path
    would be something similar to this:
    \oracle\product\10.2.0\bip\j2ee\home\application-deplo
    yments\xmlpserver\application.log
    With that said though, I don't expect you'll find
    much in there that would help with your particular
    problem. I suspect you either get no rows in your XML
    at runtime, due to some session state issues, or your
    XML structure does in fact not match your RTF
    template.
    I'm not quite following your problem description,
    i.e. when did you do what and are you associating
    your report layout with a report query or report
    region. So just some general notes, your query needs
    to be parseable at design-time, when exporting the
    XML, so that you get the XML file with the proper
    column names derived from your query. If you want to
    use your RTF template with a standard report region,
    you must export the XML file first using the advanced
    XML structure option. And of course the column names
    in your report query need to match the column names
    in your report region.
    Perhaps this helps you further diagnose what's going
    on, if you have additional information that could
    help, let me know. And if you could stage this on
    apex.oracle.com, I'd be happy to take a look.
    Regards,
    MarcMarc,
    Thanks for looking at this issue. Below find my remarks to your questions..
    Re: your query needs
    to be parseable at design-time, when exporting the
    XML, so that you get the XML file with the proper
    column names derived from your query.At the start of this process, the query code was a function in a package. The function was returning an SQL select statement, for a report region on a page. I took the select statement, built an application query to build a sample of the xml for BI Publisher desktop (Add-on for Word). The code was producing the usual Col01, Col02.. since at design time that is were the column names.
    When I then took the xml from this and built the rtf for loading into my APEX application.
    When testing the Application Query with this RTF report layout, I am getting PDF's. When using it with the report region sending an xml feed to BI Publisher I am getting nothing back.
    I have since taken the sql code and moved it back into the report region, and set the region to have a type of straight SQL Query. I have even tried to hard-code the parameters I was getting from the page to limit data returned.
    Is it possible to see the xml being produced by the APEX page?
    Re: Stage this on apex.oracle.com.. I would love to, but we would have HIPPA issues if I posted the data on a public website.
    Can I send you the RTF file and the xml file that the application query is creating to see if there something weird about them?
    Thank you,
    Tony Miller
    UTMB/EHN

  • Can I create a file using pl/sql code in application server ?

    Hi
    I wanted to create a file(any kind of file .txt .csv .exe etc..) using pl/sql code in application server?
    Please help me with an example...in this regard
    Regards
    Sa

    864334 wrote:
    I wanted to create a file(any kind of file .txt .csv .exe etc..) using pl/sql code in application server?And how is this "file" to be delivered?
    Files can be created by PL/SQL code and stored in the Oracle database as CLOBs. This a fairly easy and robust process. It runs entirely in the database. It conforms to transaction processing. The "file" (as a CLOB) resides in the database and can thus be secured via database security, is part of database backups and so on.
    The basic issue is how to deliver the contents of the CLOB to the user. If via FTP, then the database can directly FTP the contents of the CLOB to the FTP server as a file. If via HTTP, the database can deliver the CLOB as a HTTP download directly to the web browser.
    If the client is Java or .Net, then the CLOB contents can be delivered via SQL or DBMS_LOB or a custom PL/SQL interface.
    In such cases, there is no need to step outside the secure and flexible database environment and create a physical o/s file in the wild (outside the controls of database security, data integrity and transaction processing). This is thus recommended and is the preference.

  • Need PL/SQL code for this

    Hi,
    I need a PL/SQL code for this one...
    Let me know if something is not clear...
    1) The table CLOB_CLOBJECT_CDA has the columns described below...
    Explaining only those fields which are important in this context
    -- CDA_STEP_ID : Basically a Sequence
    -- CLOBJECT_SOURCE1_ID : Every id has got a set of records
    -- CLOBJECT_SOURCE2_ID : Every id has got a set of records
    -- LVL : There are total 8 levels..
    This is the main aim :
    1) There are total 16 million rows..(limited to 10 rows here)
    2) We need to go through level by level (LVL column) & insert the intersection records (CLOBJECT_SOURCE1_ID intersect CLOBJECT_SOURCE2_ID)
    into another table...but this is how it goes..
    Level (LVL column) 3's basically have CLOBJECT_SOURCE1_ID as level (LVL column) 2 CDA_STEP_ID's..
    (consider the statement --** where CLOBJECT_SOURCE1_ID = 285 which is same as 1st insert statement step id)..
    The above process goes for next levels until 8..(so have to use loops)
    So for ex :
    We go through the first insert statement and insert the insertion records only when both CLOBJECT_SOURCE1_ID & CLOBJECT_SOURCE2_ID has got records ..
    If we don't find any records for both of them we should skip the corresponding step id when we go to the next levels...
    Let's go through the 1st insert statement...
    -- We have CDA_STEP_ID = 285 & two sources CLOBJECT_SOURCE1_ID as 19 & CLOBJECT_SOURCE2_ID as 74...
    -- We see the table CLOBJECT_COUNTS & check whether we have counts for both 19 & 74 ..(In fact we insert counts into this table only if they have records)
    -- If so, we insert the intersection records into CDA_MRN_RESULTS ( we do have counts for both of them..) with CDA_STEP_ID 285...
    -- Then we insert the step id which is 285 along with the count into CLOBJECT_COUNTS..
    Let's go through another insert statement...
    -- Consider CDA_STEP_ID = 288 which has two sources CLOBJECT_SOURCE1_ID as 19 & CLOBJECT_SOURCE2_ID as 92...
    -- We see the table CLOBJECT_COUNTS & check whether we have counts for both 19 & 92 ..(we have records for 19 but not for 92)
    -- So we should not proceed with this..& also skip all those records (future records with increasing levels..basically level 3's) which have got 288 as CLOBJECT_SOURCE1_ID..
    (As said earlier that the present CDA_STEP_ID will always be CLOBJECT_SOURCE1_ID in the next level)...
    I wrote the following code which is after the statement...
    Let me have the create & insert statements here..
    create table CLOB_CLOBJECT_CDA
        CDA_STEP_ID           NUMBER,
        CDA_ID                NUMBER,
        CDA_SEQ_NUMBER        NUMBER,
        CLOBJECT_SOURCE1_TYPE VARCHAR2(3000),
        CLOBJECT_SOURCE1_ID   NUMBER,
        CLOBJECT_OPERATOR     VARCHAR2(3000),
        CLOBJECT_SOURCE2_TYPE VARCHAR2(3000),
        CLOBJECT_SOURCE2_ID   NUMBER,
        LVL                   NUMBER
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (285, 285, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 74, 2);
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (286, 286, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 75, 2);
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (287, 287, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 91, 2);
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (288, 288, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 92, 2);
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (4869, 4869, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 91, 3);  -- **
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (4870, 4870, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 92, 3);
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (4871, 4871, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 93, 3);
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (4880, 4880, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 91, 3);
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (4881, 4881, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 92, 3);
    insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
    values (4882, 4882, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 93, 3);
    create table CDA_MRN_RESULTS
       CDA_STEP_ID      NUMBER,
      MRN              NUMBER,
      INSERT_DATE_TIME DATE
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (19, 1, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (19,  2, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (19,  3, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (74,  1, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (74,  2, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (74,  4, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (75,  1, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (75,  2, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (75,  6, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (91,  2, to_date('19-10-2011', 'dd-mm-yyyy'));
    insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
    values (91,  3, to_date('19-10-2011', 'dd-mm-yyyy'));
    create table CLOBJECT_COUNTS
      CDA_STEP_ID    NUMBER,
      CLOBJECT_COUNT NUMBER,
      DATE_TIME      DATE
    Insert into CLOBJECT_COUNTS values (19,3, to_date('19-10-2011', 'dd-mm-yyyy'));
    Insert into CLOBJECT_COUNTS values (74,3, to_date('19-10-2011', 'dd-mm-yyyy'));
    Insert into CLOBJECT_COUNTS values (75,3, to_date('19-10-2011', 'dd-mm-yyyy'));
    Insert into CLOBJECT_COUNTS values (91,2, to_date('19-10-2011', 'dd-mm-yyyy'));The output goes into two tables...
    CDA_MRN_RESULTS : O/p of intersection records between source1 & source2 id
    CLOBJECT_COUNTS : Step id with counts ...(useful for skipping next level step id's if either of source id has "0" counts)
    Any help is appreciated..
    Thanks..

    I tried to code this..but looping takes a lot of time..I want to skip certain rows where source1_step_id & source_2_step_id are not in clobject_counts table as we proceed to the next levels..Not sure how to skip the rows..
    declare
    cursor c1 (p_level varchar2 ) is
      Select * from clob_clobject_cda
        where lvl = p_level    ;
       TYPE V_TT IS TABLE OF C1%ROWTYPE INDEX BY PLS_INTEGER;
        L_TT V_TT;
        v1 number;
        v2 number;
        v_step_id number;
        v_operator varchar2(100) := '';
    begin
    for i in 2..8 loop
      open c1(i);
      LOOP
           FETCH C1 BULK COLLECT INTO L_TT LIMIT 500;
            FOR indx IN 1 .. L_TT.COUNT
             LOOP
               v1 := L_TT(indx).clobject_source1_id;
               v2 := L_TT(indx).clobject_source2_id;
               v_step_id := L_TT(indx).cda_step_id;
               v_operator := L_TT(indx).clobject_operator;
      Execute Immediate ('Insert into cda_mrn_results Select --+ parallel (cm 128)
                                                      distinct ' || v_step_id || ', mrn, trunc(sysdate) dt from cda_mrn_results  cm
                        where cda_step_id = ' || v1 || '
                        and   cda_step_id in (Select cda_step_id from clobject_counts) ' ||
         v_operator ||
                    '  Select --+ parallel (cm 128)
                                                      distinct ' || v_step_id || ', mrn, trunc(sysdate) dt from cda_mrn_results  cm
                        where cda_step_id = ' || v2 || '
                        and   cda_step_id in (Select cda_step_id from clobject_counts)  ' );
    Insert --+ Append
           into clobject_counts Select cda_step_id, count(distinct mrn),
                       insert_date_time dt from cda_mrn_results  where cda_step_id =  v_step_id   group by cda_step_id,insert_date_time;
       COMMIT;                    
             END LOOP;
           EXIT WHEN L_TT.COUNT = 0;
         END LOOP;
      CLOSE C1;
    End Loop;    
    Commit;
    End;

  • How to insert sql code in module (not form) other than API?

    I generated module as web pl/sql in Oracle Design Editor 6i. I have different user types with different privileges. I want to do some permission checking before a user can reach the tables. All the help are related to API and Form. Is there a way to execute sql code with out using API?

    Yes, you can add in your own user defined PL/SQL (and JavaScript)at module component and item level. Select the module component in the Design Editor and expand the node until you see "Application Logic" -> Events. Now add your logic. For help on this use the context sensitive help and you should find the PL/SQL help. (or try the topic "About user-defined application logic and Web PL/SQL Generator"
    (Is this the piece you wanted to avoid?) You can also add user defined PL/SQL to the Table API generated code. For this you need to use the Server Model tab. Navigate to the Table and expand the node for the desired table and find the Table TAPI/trigger Logic section. Again, make use of the context sensitive help here.
    Regards
    Sue

Maybe you are looking for

  • Windows 8 Quick Solutions

    Windows 8 was released on October 26th for all to enjoy! Check out the below Frequently Asked Questions for more information and quick troubleshooting. 1. I've just upgraded to Windows 8 but I'm having a few problems. What's going on? When upgrading

  • Google calendar sends e-mail reminders, iCal shall not trigger Mail

    I am using several Google calendars. I configured Google calendar to send reminders via e-mail. Unfortunately, iCal tries to do the same now. So for every entry in one of my Google calendars, Mail appears and wants to send a reminder e-mail ... Very

  • UCCX 8.0 database integration with SQL Server 2005 Express

    Dear Support Community, I need to set up a script to read SQL Server 2005 Express records. The SQL Server 2005 Express is compatible with the UCCX 8.0? Let me know if you need more information

  • How to watch home movies on Apple TV?

    I have home movies in IPhoto taken with my Canon Elph. Can I watch these on Apple TV? If so where do I find them?

  • KM Permissions based on MetaData

    Hello, I am wondering if there is any way to apply access permissions based on a metadata tag on a document. What I would like to do is see if there is a way to have a metadata property pre-defined which allows for a "level of access". For example, i