RERT by join partition

The rate of the Bank of

Jan 1 to 20 is 10

on 21 Jan to 31 jan is 5...

I want to generate this report through the join of the partition

create table t ( dt date, rate number);


insert into t values ( to_date('01-JAN-2012','DD-MON-YYYY'),10);




insert into t values ( to_date('21-JAN-2012','DD-MON-YYYY'),5);


insert into t values ( to_date('01-FEB-2012','DD-MON-YYYY'),50);




insert into t values ( to_date('15-JUNE-2012','DD-MON-YYYY'),1);

My query, but it does not work

with tt as (
select dt + level - 1 as rn from t
connect by level <= ( select max(dt) -  min(dt)  from t )


)






select a.rn ,b.rate


from tt a  left outer join t b partition by (b.rate)
on ( a.rn=b.dt)








Expected results

01 jan 10

02 jan 10

.

.

.

. Jan 21 5

.

.so on

Hello

Here's one way:

WITH date_range AS

(

SELECT MIN (dt) AS min_dt

MAX (dt) AS max_dt

T

)

all_dts AS

(

SELECT the LEVEL - 1 AS dt + min_dt

OF date_range

CONNECT BY LEVEL<= 1="" +="" max_dt="" -="">

)

SELECT a.dt

LAST_VALUE (t.rate IGNORE NULLS) over (ORDER BY a.dt) AS the rate

Of all_dts one

LEFT OUTER JOIN t ON t.dt = a.dt

ORDER BY a.dt

;

This means that all your SDRs have the same number of hours, minutes, and seconds, as they do in your sample data.  If this is not the case, use TRUNC (dt).

You don't need an outer join partitioned for this problem.  A partitioned outer join is useful when you have groups of rows and want a separate outer join within each group.  For example, if your rate table has several banks, and you wanted a story of separate (like the one above) rate for each bank, you can use a partitioned outer join.

Tags: Database

Similar Questions

  • Join partition

    The thjere oradoc this example I noticed with a score by no to the keyword... (near bottom of the doc copy pasted here)

    http://docs.Oracle.com/CD/B28359_01/server.111/b28286/statements_10002.htm

    SELECT times.time_id, product, an inventory of the quantity OF

    PARTITION BY (product)

    RIGHT OUTER JOIN time ON (times.time_id = inventory.time_id)

    WHERE the times.time_id BETWEEN TO_DATE ("4 January 01 ',' DD/MM/YY")

    AND TO_DATE (4 JUNE 01 ',' DD/MM/YY "")

    2.1 ORDER;

    I tried to make my own partition similar to this, but can't seem to get the correct logic...

    example:

    Select avg (salary) in the partition used by (department_id)

    I tried many variations of the foregoing.

    My basic question is, is there a way and a reason to use partition by without locking in an OVER clause?

    Could someone show me an example of partition by no more so I could practice some stuff on my own it please?

    Everything I looked up a partition by framed in the clause

    ex: select... Over (partition by department_id) salary of employees;

    I want to know how and why the works of script oradoc.

    The thjere oradoc this example I noticed with a score by no to the keyword... (near bottom of the doc copy pasted here)

    http://docs.Oracle.com/CD/B28359_01/server.111/b28286/statements_10002.htm

    SELECT times.time_id, product, an inventory of the quantity OF

    PARTITION BY (product)

    RIGHT OUTER JOIN time ON (times.time_id = inventory.time_id)

    WHERE the times.time_id BETWEEN TO_DATE ("4 January 01 ',' DD/MM/YY")

    AND TO_DATE (4 JUNE 01 ',' DD/MM/YY "")

    2.1 ORDER;

    Correct - as says the doc called a "partitioned outer join" and is used as a form of data densification.

    I tried to make my own partition similar to this, but can't seem to get the correct logic...

    example:

    Select avg (salary) in the partition used by (department_id)

    A join involves TWO or more sets of data/tables. You have only a (employees), in this example.

    I tried many variations of the foregoing.

    Any 'variations' who use that ONE set of data/table will not and cannot work. A 'join' must join. You can't have a join with a single entity

    Could someone show me an example of partition by no more so I could practice some stuff on my own it please?

    Huh? You, yourself, posted an example of ' using the partition by no more "."

    Have you looked at the results of this query in the doc? Here is the link for the example doc that refer you:

    http://docs.Oracle.com/CD/B28359_01/server.111/b28286/statements_10002.htm#i2177515

    Look at the results. See how the product (bottle, RCA, et al.) are listed for EACH LINE, even when there is no "amount?

    I.e. "densification of data" - as an outer join - it creates data even when it was not.

    I want to know how and why the works of script oradoc.

    The doc explains what is this query with the clause "partition by":

    Using partitioned outer joins: examples the following example shows how a partitioned outer join fills gaps in lines to facilitate the specification of the analytical calculation and reliable implementation report in shape.

    . . .

    The data is now more dense along the time dimension for each partition of the product dimension. However, each of the lines newly added in each partition is null in the quantity column.

    Delete the partition by clause and see how the result set is different.

    The outer join 'partition by (product)' told you want product in the game even if there is no data on one side of the join.

    The TIME table has data for 1, 2, 3, 4, 5 and 6 April. But the INVENTORY table has data for Apr 1 and 6. Again the result set produced 'bottle' to all THE SIX ROWS.

    If there is something specific on this example you should ask.

    A PARTITIONED ON the JOIN is a 'join' - see the "joins" the documentation section

    https://docs.Oracle.com/CD/B28359_01/server.111/b28286/queries006.htm

    You can use outer joins to fill the gaps in the scattered data. Such a join is called a partitioned outer join and is formed by the query_partition_clause of the join_clause syntax. Sparse data given that has no lines for all possible values of a dimension like time or the service. For example, sales data tables have not usually stored for products that had no sales at a given date. Gaps in data is useful in situations where the data density complicated analytical calculations or where some data could be missed if the scattered data is queried directly.

  • Tip to turn off the wise join partition

    Is there a way to disable the join partition (serial) 10 gr 2 wise? that is, through suspicion... The reason why I want to do is, to use the intra-partition for a very large partition parallelism. Re-partitioning or subpartitioning is not an option for now. SQL is scanning only one partition so sign up for P - W is not useful and it restricts intra-partition parallelism.

    DRM for your answers.

    user4529833 wrote:

    I was reading some of your answer on the other forum where you recommended pq_distribute tip to allow the P - W junction. Pq_distribute can be used to activate as well as deactivate P - W join?

    Fix - check the Performance Tuning Guide and a reference to http://tahiti.oracle.com for a complete list of the options available for this tip. There are a couple that are very specifically to control the effects of partitioning; some of them do so almost as side effects.

    Concerning
    Jonathan Lewis
    http://jonathanlewis.WordPress.com
    http://www.jlcomp.demon.co.UK

    "Science is more than a body of knowledge; It's a way of thinking"Carl Sagan

  • Partition outer join

    Hello

    I want a report that shows data for all combinations of dimensions, although in fact no data exists for them.

    http://download.Oracle.com/docs/CD/E11882_01/server.112/e10578/tdpdw_sql.htm#TDPDW0072
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    Here's my data model, inventory with a status as 'sold out' or 'available' and the designer of the element
    DROP TABLE inventory
    /
    DROP TABLE inv_status
    /
    DROP TABLE designer
    /
    CREATE TABLE inv_status(
         id          NUMBER  PRIMARY KEY
        ,description VARCHAR2(12)
        )
    /
    CREATE TABLE designer(
         id          NUMBER  PRIMARY KEY
        ,name        VARCHAR2(12)
        )
    /
    CREATE TABLE inventory(
         id          NUMBER  PRIMARY KEY
        ,fk_ist      NUMBER
            CONSTRAINT fk_inv_status
            REFERENCES inv_status (id)
        ,fk_des      NUMBER
            CONSTRAINT fk_designer
            REFERENCES designer (id)
        ,name        VARCHAR2(20)
        ,description VARCHAR2(12)
        )
    /
    and some examples of data
    INSERT INTO inv_status (id,description) VALUES (25,'sold out');
    INSERT INTO inv_status (id,description) VALUES (26,'available');
    INSERT INTO inv_status (id,description) VALUES (27,'comming soon');
    INSERT INTO inv_status (id,description) VALUES (28,'not in use');
    
    INSERT INTO designer (id,name) VALUES (111,'Marco');
    INSERT INTO designer (id,name) VALUES (112,'Tommy');
    INSERT INTO designer (id,name) VALUES (113,'Daisy');
    INSERT INTO designer (id,name) VALUES (114,'Laura');
    
    INSERT INTO inventory (id,fk_ist,fk_des,name,description) VALUES (1,25,112,'moon boot','k');
    INSERT INTO inventory (id,fk_ist,fk_des,name,description) VALUES (2,25,113,'high heel','r');
    INSERT INTO inventory (id,fk_ist,fk_des,name,description) VALUES (3,26,114,'sandal','f');
    INSERT INTO inventory (id,fk_ist,fk_des,name,description) VALUES (4,26,113,'flip-flop','u');
    INSERT INTO inventory (id,fk_ist,fk_des,name,description) VALUES (5,27,112,'horseshoe','j');
    INSERT INTO inventory (id,fk_ist,fk_des,name,description) VALUES (6,27,114,'magic pair of boots','o');
    INSERT INTO inventory (id,fk_ist,fk_des,name,description) VALUES (7,27,113,'runner','r');
    INSERT INTO inventory (id,fk_ist,fk_des,name,description) VALUES (8,27,112,'loafer',NULL);
    INSERT INTO inventory (id,fk_ist,fk_des,name,description) VALUES (9,27,113,'climbing spur',NULL);
    COMMIT;
    I need a simple outer join to find each status as well as the objects (if available)
    SELECT  ist.id ist
           ,inv.id
           ,inv.name
           ,ist.description
    FROM    inv_status ist
            LEFT JOIN inventory inv
              ON (ist.id = inv.fk_ist)
    ORDER BY ist.id, inv.id;
    /*
    IST ID  NAME                 DESCRIPTION
    --- --- -------------------- ------------
    25  1   moon boot            sold out
    25  2   high heel            sold out
    26  3   sandal               available
    26  4   flip-flop            available
    27  5   horseshoe            comming soon
    27  6   magic pair of boots  comming soon
    27  7   runner               comming soon
    27  8   loafer               comming soon
    27  9   climbing spur        comming soon
    28                           not in use
    
    10 rows selected
    */
    The same I get with a left join partition
    SELECT  ist.id ist
           ,inv.id
           ,inv.name
           ,ist.description
    FROM    inv_status ist
            PARTITION BY (ist.id)
            LEFT JOIN inventory inv
              ON (ist.id = inv.fk_ist)
    ORDER BY ist.id, inv.id;
    /*
    IST ID  NAME                 DESCRIPTION
    --- --- -------------------- ------------
    25  1   moon boot            sold out
    25  2   high heel            sold out
    26  3   sandal               available
    26  4   flip-flop            available
    27  5   horseshoe            comming soon
    27  6   magic pair of boots  comming soon
    27  7   runner               comming soon
    27  8   loafer               comming soon
    27  9   climbing spur        comming soon
    28                           not in use
    
    10 rows selected
    */
    But what is the right partition join? Why do I have multiple lines for each State where no items exist? Or in other words: someone can tell me what I asked of the DB and it makes sense to ask him: -?
    SELECT  ist.id ist
           ,inv.id
           ,inv.name
           ,ist.description
    FROM    inventory inv
            PARTITION BY (inv.fk_ist)
            RIGHT JOIN inv_status ist
              ON (ist.id = inv.fk_ist)
    ORDER BY ist.id, inv.id;
    /*
    IST ID  NAME                 DESCRIPTION
    --- --- -------------------- ------------
    25  1   moon boot            sold out
    25  2   high heel            sold out
    25                           sold out
    25                           sold out
    26  3   sandal               available
    26  4   flip-flop            available
    26                           available
    26                           available
    27  5   horseshoe            comming soon
    27  6   magic pair of boots  comming soon
    27  7   runner               comming soon
    27  8   loafer               comming soon
    27  9   climbing spur        comming soon
    27                           comming soon
    27                           comming soon
    28                           not in use
    28                           not in use
    28                           not in use
    
    18 rows selected
    */
    For any combination of x as well as objects Designer item (if available) again a simple Cartesian product is easy to do.
    SELECT  ist.id ist
           ,des.id des
           ,inv.id
           ,inv.name
           ,ist.description
           ,des.name designer
    FROM    inv_status ist
            CROSS JOIN designer des
            LEFT JOIN inventory inv
              ON (ist.id = inv.fk_ist
                 AND des.id = inv.fk_des
                 )
    ORDER BY ist.id,des.id,inv.id;
    /*
    IST DES ID  NAME                 DESCRIPTION  DESIGNER
    --- --- --- -------------------- ------------ ------------
    25  111                          sold out     Marco
    25  112 1   moon boot            sold out     Tommy
    25  113 2   high heel            sold out     Daisy
    25  114                          sold out     Laura
    26  111                          available    Marco
    26  112                          available    Tommy
    26  113 4   flip-flop            available    Daisy
    26  114 3   sandal               available    Laura
    27  111                          comming soon Marco
    27  112 5   horseshoe            comming soon Tommy
    27  112 8   loafer               comming soon Tommy
    27  113 7   runner               comming soon Daisy
    27  113 9   climbing spur        comming soon Daisy
    27  114 6   magic pair of boots  comming soon Laura
    28  111                          not in use   Marco
    28  112                          not in use   Tommy
    28  113                          not in use   Daisy
    28  114                          not in use   Laura
    
    18 rows selected
    */
    But I just can't get with the join of LEFT or RIGHT partition
    SELECT  inv_ist.ist
           ,des.id des
           ,inv_ist.id
           ,inv_ist.name
           ,inv_ist.description
           ,des.name designer
    FROM    designer des
            PARTITION BY (des.id)
            LEFT JOIN (
                SELECT  ist.id ist
                       ,inv.fk_des
                       ,inv.id
                       ,inv.name
                       ,ist.description
                FROM    inv_status ist
                        PARTITION BY (ist.id)
                        LEFT JOIN inventory inv
                          ON (ist.id = inv.fk_ist)
                ) inv_ist
            ON (des.id = inv_ist.fk_des
               OR inv_ist.fk_des IS NULL)
    ORDER BY inv_ist.ist,des.id,inv_ist.id;
    /*
    IST DES ID  NAME                 DESCRIPTION  DESIGNER
    --- --- --- -------------------- ------------ ------------
    25  112 1   moon boot            sold out     Tommy
    25  113 2   high heel            sold out     Daisy
    26  113 4   flip-flop            available    Daisy
    26  114 3   sandal               available    Laura
    27  112 5   horseshoe            comming soon Tommy
    27  112 8   loafer               comming soon Tommy
    27  113 7   runner               comming soon Daisy
    27  113 9   climbing spur        comming soon Daisy
    27  114 6   magic pair of boots  comming soon Laura
    28  111                          not in use   Marco
    28  112                          not in use   Tommy
    28  113                          not in use   Daisy
    28  114                          not in use   Laura
    
    13 rows selected
    */
    SELECT  inv_ist.ist
           ,des.id des
           ,inv_ist.id
           ,inv_ist.name
           ,inv_ist.description
           ,des.name designer
    FROM    (
            SELECT  ist.id ist
                   ,inv.fk_des
                   ,inv.id
                   ,inv.name
                   ,ist.description
            FROM    inventory inv
                    PARTITION BY (inv.fk_ist)
                    RIGHT JOIN inv_status ist
                      ON (ist.id = inv.fk_ist)
            ) inv_ist
            PARTITION BY (inv_ist.fk_des)
            RIGHT JOIN designer des
              ON (des.id = inv_ist.fk_des)
    ORDER BY inv_ist.ist,des.id,inv_ist.id;
    /*
    IST DES ID  NAME                 DESCRIPTION  DESIGNER
    --- --- --- -------------------- ------------ ------------
    25  112 1   moon boot            sold out     Tommy
    25  113 2   high heel            sold out     Daisy
    26  113 4   flip-flop            available    Daisy
    26  114 3   sandal               available    Laura
    27  112 5   horseshoe            comming soon Tommy
    27  112 8   loafer               comming soon Tommy
    27  113 7   runner               comming soon Daisy
    27  113 9   climbing spur        comming soon Daisy
    27  114 6   magic pair of boots  comming soon Laura
        111                                       Marco
        111                                       Marco
        111                                       Marco
        111                                       Marco
        112                                       Tommy
        112                                       Tommy
        112                                       Tommy
        113                                       Daisy
        113                                       Daisy
        113                                       Daisy
        114                                       Laura
        114                                       Laura
        114                                       Laura
    
    22 rows selected
    */
    Does anyone know a simple description, something like 'Partition of outer join for Dummies

    Concerning
    Marcus

    Edited by: Marwim the 28.12.2010 09:11
    Typo

    Hey, Marcus,

    Marwim wrote:
    And that's exactly my problem: what kind of problems can I solve with outer joins partitioned?

    Programming would be much easier (and therefore less interesting and less well-paid) if it has nice, short answers to these questions.

    According to my experience, cross joins are the best when you dimension tables and partitioned outer joins are good when you don't.
    Cionsider the following partitioned outer join, which shows all the possible combinations of the job and the Department:

    SELECT       d.dname
    ,       e.deptno
    ,       e.job
    ,       e.ename
    FROM          scott.dept     d
    LEFT OUTER JOIN     scott.emp     e     PARTITION BY (e.job)
              ON     d.deptno     = e.deptno
    ORDER BY  d.deptno
    ,       e.job
    ;
    

    Output:

    DNAME              DEPTNO JOB       ENAME
    -------------- ---------- --------- ---------
    ACCOUNTING                ANALYST
    ACCOUNTING             10 CLERK     MILLER
    ACCOUNTING             10 MANAGER   CLARK
    ACCOUNTING             10 PRESIDENT KING
    ACCOUNTING                SALESMAN
    ...
    OPERATIONS                ANALYST
    OPERATIONS                CLERK
    OPERATIONS                MANAGER
    OPERATIONS                PRESIDENT
    OPERATIONS                SALESMAN
    

    It's a great use of a partitioned outer join, because there is no dimension table for employment (that is, there is no table with one line per job, which may be the target of a key foregin reference). You can use a join Cross (more an external koin) to get the same results, but it would be a subquery such as

    WITH  all_jobs  AS
    (
        SELECT DISTINCT  job
        FROM           scott.emp
    ) ...
    

    to create a table dimesnion to the fly.

    There may be exceptions. For example, if you don't have a table, but there are some jobs that actually occur in the emp table, and you want the output to include only the jobs that exist in the emp table, then the easiest thing is just to ignore the jobs table and do the partitioned outer join illustrated above.

  • Expected for a junction of partition-wise?

    I have two tables that are partitioned by hash chains same VARCHAR2 (16). When I do a query similar to

    Select * from table1 a join table2 b
    On b.partition_Column = a.partition_Column

    I get the following in section 'Operation' for an explanation of the developer Oracle running Oracle 11 GR 1 material:

    HASH (ALL) PARTITION
    HASH JOIN
    Schema of the ACCESS TABLE (FULL). Table1:
    Schema of the ACCESS TABLE (FULL). Table2

    Is this a hashed partition-wise join sign?

    pstart/pstop fact give partition information, but the key to whether it is a join 'partition-wise', is that the operation of the score is above the join operation.

    With the help of tables of David above, example of join partition-wise serial:

    ------------------------------------------------------------------------------------------------------
    | Id  | Operation           | Name   | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
    ------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT    |        |  2500M|  4670G|       |   111K (61)| 00:09:17 |       |       |
    |   1 |  PARTITION HASH ALL |        |  2500M|  4670G|       |   111K (61)| 00:09:17 |     1 |     8 |
    |*  2 |   HASH JOIN         |        |  2500M|  4670G|    12M|   111K (61)| 00:09:17 |       |       |
    |   3 |    TABLE ACCESS FULL| TABLE1 |   100K|    95M|       |  5891   (1)| 00:00:30 |     1 |     8 |
    |   4 |    TABLE ACCESS FULL| TABLE2 |   200K|   191M|       | 11808   (1)| 00:01:00 |     1 |     8 |
    ------------------------------------------------------------------------------------------------------
    

    Example NTC series no:

    ------------------------------------------------------------------------------------------------------
    | Id  | Operation           | Name   | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
    ------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT    |        |  2500M|  4670G|       |   111K (61)| 00:09:17 |       |       |
    |*  1 |  HASH JOIN          |        |  2500M|  4670G|    96M|   111K (61)| 00:09:17 |       |       |
    |   2 |   PARTITION HASH ALL|        |   100K|    95M|       |  5891   (1)| 00:00:30 |     1 |     8 |
    |   3 |    TABLE ACCESS FULL| TABLE1 |   100K|    95M|       |  5891   (1)| 00:00:30 |     1 |     8 |
    |   4 |   PARTITION HASH ALL|        |   200K|   191M|       | 11808   (1)| 00:01:00 |     1 |     8 |
    |   5 |    TABLE ACCESS FULL| TABLE2 |   200K|   191M|       | 11808   (1)| 00:01:00 |     1 |     8 |
    ------------------------------------------------------------------------------------------------------
    

    Parallel example of NTC:

    ---------------------------------------------------------------------------------------------------------------------------------
    | Id  | Operation               | Name     | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |    TQ  |IN-OUT| PQ Distrib |
    ---------------------------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT        |          |  2500M|  4670G| 23536  (80)| 00:01:58 |       |       |        |      |            |
    |   1 |  PX COORDINATOR         |          |       |       |            |          |       |       |        |      |            |
    |   2 |   PX SEND QC (RANDOM)   | :TQ10000 |  2500M|  4670G| 23536  (80)| 00:01:58 |       |       |  Q1,00 | P->S | QC (RAND)  |
    |   3 |    PX PARTITION HASH ALL|          |  2500M|  4670G| 23536  (80)| 00:01:58 |     1 |     8 |  Q1,00 | PCWC |            |
    |*  4 |     HASH JOIN           |          |  2500M|  4670G| 23536  (80)| 00:01:58 |       |       |  Q1,00 | PCWP |            |
    |   5 |      TABLE ACCESS FULL  | TABLE1   |   100K|    95M|  1628   (1)| 00:00:09 |     1 |     8 |  Q1,00 | PCWP |            |
    |   6 |      TABLE ACCESS FULL  | TABLE2   |   200K|   191M|  3263   (1)| 00:00:17 |     1 |     8 |  Q1,00 | PCWP |            |
    ---------------------------------------------------------------------------------------------------------------------------------
    

    For example no parallel NTC:

    ------------------------------------------------------------------------------------------------------------------------------------
    | Id  | Operation                  | Name     | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |    TQ  |IN-OUT| PQ Distrib |
    ------------------------------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT           |          |  2500M|  4670G| 23536  (80)| 00:01:58 |       |       |        |      |            |
    |   1 |  PX COORDINATOR            |          |       |       |            |          |       |       |        |      |            |
    |   2 |   PX SEND QC (RANDOM)      | :TQ10001 |  2500M|  4670G| 23536  (80)| 00:01:58 |       |       |  Q1,01 | P->S | QC (RAND)  |
    |*  3 |    HASH JOIN               |          |  2500M|  4670G| 23536  (80)| 00:01:58 |       |       |  Q1,01 | PCWP |            |
    |   4 |     PART JOIN FILTER CREATE| :BF0000  |   100K|    95M|  1628   (1)| 00:00:09 |       |       |  Q1,01 | PCWP |            |
    |   5 |      PX RECEIVE            |          |   100K|    95M|  1628   (1)| 00:00:09 |       |       |  Q1,01 | PCWP |            |
    |   6 |       PX SEND BROADCAST    | :TQ10000 |   100K|    95M|  1628   (1)| 00:00:09 |       |       |  Q1,00 | P->P | BROADCAST  |
    |   7 |        PX BLOCK ITERATOR   |          |   100K|    95M|  1628   (1)| 00:00:09 |     1 |     8 |  Q1,00 | PCWC |            |
    |   8 |         TABLE ACCESS FULL  | TABLE1   |   100K|    95M|  1628   (1)| 00:00:09 |     1 |     8 |  Q1,00 | PCWP |            |
    |   9 |     PX BLOCK ITERATOR      |          |   200K|   191M|  3263   (1)| 00:00:17 |:BF0000|:BF0000|  Q1,01 | PCWC |            |
    |  10 |      TABLE ACCESS FULL     | TABLE2   |   200K|   191M|  3263   (1)| 00:00:17 |:BF0000|:BF0000|  Q1,01 | PCWP |            |
    ------------------------------------------------------------------------------------------------------------------------------------
    

    Published by: Dom Brooks July 8, 2011 11:32
    Added vs parallel series

  • Request to Join.

    I have two tables...
    in the 1st table lets say emp_sal I have used salary date wise.


    for example:

    100 20 APRIL 1, 2010
    102 15 APRIL 1, 2010
    100 30 APRIL 2, 2010

    I need a query where I give the date settings and to_date it should return all emplyees sal and missing wage should return 0


    For example... If is give 1st April 10 date and 2 April 10 as date, it should return

    100 20 APRIL 1, 2010
    102 15 APRIL 1, 2010
    100 30 APRIL 2, 2010
    102 0 2 APRIL 2010


    Pls help

    Outer join partitioned would be perfect here:

    with emp_sal as (select 100 empno, 20 salary, to_date('01/04/2010', 'dd/mm/yyyy') dt from dual union all
                     select 102 empno, 15 salary, to_date('01/04/2010', 'dd/mm/yyyy') dt from dual union all
                     select 100 empno, 30 salary, to_date('02/04/2010', 'dd/mm/yyyy') dt from dual),
    -- end of mimicking your data in a subquery called emp_sal. Hurrah for subquery factoring!
           dates as (select to_date('01/04/2010', 'dd/mm/yyyy') + level -1 dt  -- replace the dates with your from_date/to_date parameters
                     from   dual
                     connect by level <= to_date('02/04/2010', 'dd/mm/yyyy') - to_date('01/04/2010', 'dd/mm/yyyy') + 1)
    select es.empno, nvl(es.salary, 0) salary, dates.dt
    from   dates
           left outer join emp_sal es partition by (es.empno) on (dates.dt = es.dt);
    
         EMPNO     SALARY DT
    ---------- ---------- ----------
           100         20 01/04/2010
           100         30 02/04/2010
           102         15 01/04/2010
           102          0 02/04/2010
    
  • Insert a default line where there is no data

    Hi using Oracle 10 g, I stuck a simple simulation below... I would like to insert a default value of "42" to the province of "AB", is a set of records for all products that do not exist in all provinces, would therefore create a line with the corresponding province to the right join.  Hope this makes sense...


    CREATE TABLE TBL_TEST1

    (PROD_ID VARCHAR2 (10), VARCHAR2 (2) OF THE PROVINCE, THE NUMBER OF PRIZES);

    INSERT ALL

    IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', "BC", 178)

    IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'MT', 178)

    IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'NB', 178)

    IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', "NF", 178)

    IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'NS', 178)

    IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'ON', 178)

    IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'PI', 178)

    IN TBL_TEST1 (PROD_ID, PROVINCE, PRICE) VALUES ('42', 'SK', 178)

    SELECT * FROM DUAL;

    -SELECT * FROM TBL_TEST1

    CREATE TABLE TBL_PROV

    (PROV. VARCHAR2 (2));

    INSERT ALL

    IN TBL_PROV (PROV) VALUES ("AB")

    IN TBL_PROV (PROV) VALUES ("BC")

    IN TBL_PROV (PROV) VALUES ("MT")

    IN TBL_PROV (PROV) VALUES ('NB')

    IN TBL_PROV (PROV) VALUES ('NC')

    IN TBL_PROV (PROV) VALUES ('NS')

    IN TBL_PROV (PROV) VALUES ('ON')

    IN TBL_PROV (PROV) VALUES ("PI")

    IN TBL_PROV (PROV) VALUES ('SK')

    SELECT * FROM DUAL;

    -SELECT * FROM TBL_PROV;

    SELECT

    A.PROD_ID

    COALESCE(A.PROVINCE, B.PROV)

    NVL(A.PRICE,0)

    Of

    TBL_TEST1 HAS

    RIGHT OUTER JOIN

    TBL_PROV B

    WE A.PROVINCE = B.PROV;

    3031421 wrote:

    Hi Frank,.

    So I want the select to return all the lines by product ID.  Not all ID's products are available in all provinces.  So, using the Province TBL_PROV list table as a reference, I want to show a line for each province Product_ID in the TBL_PROV table.  The select statement, I posted does not list the product ID for the "AB" province, so even if there are 8 rows in the product table, yes I would show 9 lines with the overall product id...

    42 BRITISH COLUMBIA 178
    42 MT 178
    42 NB. 178
    42 NF 178
    42 NS 178
    42 WE 178
    42 PI 178
    42 SK 178
    42 AB 0

    Good, then you don't want to INSERT new data into a table. you just want to a new row in the result set.

    It would be helpful if you posted some examples of data for tbl_test1 who had a couple of prod_ids different and different prices.

    You want all prod_id in tbl_test1 combined with all the provinces of the tbl_prov?

    If so, you can use an outer join partitioned, like this:

    SELECT t.prod_id

    p.prov

    , COALESCE (t.price, 0) IN the price

    OF tbl_prov p

    LEFT OUTER JOIN tbl_test1 t PARTITION BY (t.prod_id)

    ON t.province = p.prov

    ORDER BY prod_id

    Prov.

    ;

    Why did you use COALESCE to the provinces, but prices NVL?  If you like COALESCE, as it would be infinitely faster, wouldn't it faster in both places?  If you like NVL because it is easier to code, it will be easier to code in both places?

    In this case, you have no need either for the province, assuming that tbl_prov is never NULL (and even if this is the case, it will never reach the join condition).

    Almost no one is never using RIGHT OUTER JOIN, because the same results are always possible with LEFT OUTER JOIN.  Partitioned outer joins operate in the same way that you use the LEFT or RIGHT.  It's as if you did a separate outer join for each value of the partitioning column, and and made a UNION ALL operation to combine all separate them the results.

  • Ask the lines that correspond fully to another column

    Hi all

    Take into consideration the following 11 g:

    CREATE TABLE X_A (COL1 NUMBER, COL2 NUMBER);
    create table x_b (col1 number);
    
    INSERT INTO X_A VALUES (1,2);
    insert into x_a values (1,3);
    INSERT INTO X_A VALUES (2,2);
    INSERT INTO X_B VALUES (2);
    insert into x_b values (3);
    

    I want to interview table X_A only these col1 that match all records in X_B (i.e. value equal to '1').

    If I join the 2 tables by x_a.col2 - x_b.col1 I have two values 1 and 2 col1. But I want only 1 to appear because it contains 2.3 in x_b.col2

    Any ideas?

    Kind regards

    Stoyanov

    Join partition using

    select col1, col2
      from (
            select a.col1, a.col2, count(a.col2) over(partition by a.col1) cnt1, count(b.col1) over(partition by a.col1) cnt2
              from x_b b
              left join x_a a partition by (a.col1)
                on a.col2 = b.col1
           )
     where cnt1 = cnt2
    
  • ROLLUP null values in union

    Hello I have a data set such as

    Col1 Col2 col3 col4
    A     B     1   D
    A     B     2   E
    A     B     3    G
                4   
                5
    

    And I would get something like

    Col1 Col2 col3 col4
    A     B     1   D
    A     B     2   E
    A     B     3    G
    A     B     4    
    A     B     5
    

    Col1 and col2 values can have other values (for example C D for different scenario)


    My SQL looks like

    Select col1 , col2,col3,col4 FRom table1 where <Some conditions >
    Union
    Select null,null,col3 null from table2 where <some conditions >
    
    

    Help, please.

    Hello

    I think I see what you want now!  You want the result set to contain all the values of table_a.col1 and col2 associated with each value of table_b.col3.  If this combination is actually in the table_a, then include the tabel_a.col4 value, but if she is not, in any display case, with NULL col4.  Is this fair?

    This looks like a job for an outer join partitioned.  Here's a way to do it:

    SELECT a.col1

    a.col2

    b.col3

    a.col4

    OF table_b b

    LEFT OUTER JOIN table_a a PARTITION BY (a.col1, a.col2)

    ON a.col3 = b.col3

    ;

    The result I get is:

    COL1 COL2 COL3 COL4

    ---- ---- ---- ----

    A AND B 1 D

    A AND B 2

    A AND B 3 X

    A AND B 4

    A AND B 5

    C D D 1

    C D 2

    C D 3

    C D 4

    C D 5 D

    A plain old outer join could guarantee that each table_b.col3 value appears somewhere or other in the result set.

    This partitioned outer join guarantees that each table_b.col3 value appears with all the combinations of (col1, col2) from table_a.  "PARTITION BY (a.col1, a.col2)" behaves as if there were a separate table for each combination of (col1, col2), and did the same kind of outer join on each table separately, then all results were clauses together.

  • need to sum all the sal

    My dear

    This query, I know sal sum in dept by job is

    I have to add new coumn in sum to give query for all dept

    and new line give sum for each Department

    as a matrix report

    WITH pivot_data AS (SELECT deptno, job, sal FROM emp)

    SELECT "JOB."

    "10."

    "20."

    '30 ',.

    "40".

    OF pivot_data PIVOT (SUM (sal)

    FOR deptno

    (10, 20, 30, 40)

    )

    Hello

    So, besides the total sal for each combination of deptno and job, you want also totals for each jdeptno (regardless of the job) and work (regardless of deptno) and a total general (no matter the deptno and employment).  This sounds like a job for the CUBE.  The following soLution uses the CUBE to calculate amounts and then uses the PIVOT just to combine lines.

    WITH all_jobs AS

    (

    SELECT DISTINCT job

    FROM scott.emp

    )

    data_to_pivot AS

    (

    SELECT deptno NVL (d.deptno, - 1)

    , NVL (j.job, 'ALL') AS job

    , NVL (SUM (e.sal), 0) AS sal

    GROUPING (j.job) AS job_agg

    OF scott.dept d

    CROSS JOIN all_jobs j

    LEFT OUTER JOIN scott.emp e ON e.deptno = d.deptno

    AND e.job = j.job

    GROUP BY CUBE (d.deptno, j.job)

    )

    Simply SELECT employment, '10', all_depts '20', '30', '40', - or everything *, if you don't mind saw job_agg

    OF data_to_pivot

    PIVOT (MIN (sal)

    TO deptno IN (10, 20, 30, 40

    All_depts AS-1

    )

    )

    ORDER BY job_agg

    work

    ;

    Output:

    ALL_DEPTS 10 20 30 40 JOB

    --------- ----- ----- ----- ----- ---------

    0 6000 0 0 6000 ANALYST

    1300 1900 950 0 4150 CLERK

    MANAGER OF 2450 2975 2850 0 8275

    THE PRESIDENT 5000 0 0 0 5000

    0 0 5600 0 5600 SELLER

    ALL THE 8750 10875 9400 0 29025

    Instead of deriving a "table" of all possible jobs, you should be able to use a partitioned outer join, something like this:

    WITH pivot_data AS

    (

    SELECT deptno NVL (d.deptno, - 1)

    , NVL (e.job, 'ALL') AS job

    , NVL (SUM (e.sal), 0) AS sal

    GROUPING (employment) AS job_agg

    OF scott.dept d

    LEFT OUTER JOIN scott.emp e PARTITION BY (e.job)

    ON e.deptno = d.deptno

    GROUP BY CUBE (e.job, d.deptno)

    )

    SELECT *.

    OF pivot_data

    PIVOT (MIN (sal)

    TO deptno IN (10, 20, 30, 40

    All_depts AS-1

    )

    )

    ORDER BY job_agg, job

    ;

    But the only effect of the outer join partitioned seems to cause CUBE to abandon some Super aggregates.  I do something ridiculous in this second request, or there is a bug in my version (11.2.0.2.0 Express).

    (Almost always, when people say "there must be a bug", they're just doing something stupid.)  There is no reason to think that I am an exception.  I don't have another version of Oracle at hand right now)

  • Setting the SQL SQL Developer

    Hello all: I have a small question:

    What exactly is the SQL tuning advisor advising me to do?  Usually he will specify to create an index or something similar, but I'll have trouble deciphering the underside of deliberation.

    Thanks for your help and have a great day!

    Aqua

    Profile search SQL (see explain the plans below)

    --------------------------------------------------------

    A potentially better execution plan found for this statement.

    Recommendation (estimated delivery < = 10%)

    ---------------------------------------

    -Consider accepting the recommended SQL profile.

    run dbms_sqltune.accept_sql_profile (task_name = > 'staName20789',)

    replace = > TRUE);

    ------------------------------------------------------------------------------

    EXPLAIN SECTION PLANES

    -------------------------------------------------------------------------------

    1 original

    -----------

    Hash value of plan: 2311080268

    ------------------------------------------------------------------------------------------------------------
    | Id  | Operation                       | Name             | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    ------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                |                  |  1052 |    99K|       |   730   (3)| 00:00:09 |
    |   1 |  HASH GROUP BY                  |                  |  1052 |    99K|       |   730   (3)| 00:00:09 |
    |*  2 |   HASH JOIN OUTER               |                  |  1052 |    99K|       |   729   (2)| 00:00:09 |
    |*  3 |    FILTER                       |                  |       |       |       |            |          |
    |*  4 |     HASH JOIN OUTER             |                  |   572 | 40040 |       |   275   (3)| 00:00:04 |
    |*  5 |      HASH JOIN RIGHT ANTI       |                  |   362 | 20634 |       |   223   (4)| 00:00:03 |
    |   6 |       VIEW                      | MEDICAL_LEAVE    |   125 |   625 |       |   103   (4)| 00:00:02 |
    |   7 |        VIEW                     |                  |   125 |  6625 |       |   103   (4)| 00:00:02 |
    |*  8 |         FILTER                  |                  |       |       |       |            |          |
    |*  9 |          HASH JOIN OUTER        |                  |   125 |  8750 |       |   103   (4)| 00:00:02 |
    |  10 |           VIEW                  |                  |    94 |  5358 |       |    69   (3)| 00:00:01 |
    |* 11 |            FILTER               |                  |       |       |       |            |          |
    |* 12 |             HASH JOIN OUTER     |                  |    94 |  2632 |       |    69   (3)| 00:00:01 |
    |* 13 |              TABLE ACCESS FULL  | EMP_LEAVE        |    60 |   900 |       |    17   (6)| 00:00:01 |
    |  14 |              TABLE ACCESS FULL  | EMP_CONTRACT     | 11156 |   141K|       |    52   (2)| 00:00:01 |
    |  15 |           TABLE ACCESS FULL     | POSITION_OFFERED |  9420 |   119K|       |    33   (4)| 00:00:01 |
    |* 16 |       HASH JOIN                 |                  |   376 | 19552 |       |   119   (2)| 00:00:02 |
    |* 17 |        TABLE ACCESS FULL        | POSITION_OFFERED |   376 |  6392 |       |    33   (4)| 00:00:01 |
    |* 18 |        TABLE ACCESS FULL        | AMPEMP           |  2579 | 90265 |       |    86   (2)| 00:00:02 |
    |  19 |      TABLE ACCESS FULL          | EMP_CONTRACT     | 11156 |   141K|       |    52   (2)| 00:00:01 |
    |  20 |    VIEW                         |                  |  4572 |   120K|       |   453   (2)| 00:00:06 |
    |  21 |     HASH GROUP BY               |                  |  4572 |   825K|  1992K|   453   (2)| 00:00:06 |
    |  22 |      VIEW                       |                  |  4572 |   825K|       |   265   (2)| 00:00:04 |
    |  23 |       MERGE JOIN PARTITION OUTER|                  |  4572 |   263K|       |   265   (2)| 00:00:04 |
    |  24 |        SORT JOIN                |                  |    18 |   774 |       |     4  (25)| 00:00:01 |
    |  25 |         TABLE ACCESS FULL       | LU_MED_IMMUNO    |    18 |   774 |       |     3   (0)| 00:00:01 |
    |* 26 |        SORT PARTITION JOIN      |                  |  2731 | 43696 |       |     6  (17)| 00:00:01 |
    |  27 |         TABLE ACCESS FULL       | MED_IMMUNO       |  2731 | 43696 |       |     5   (0)| 00:00:01 |
    ------------------------------------------------------------------------------------------------------------
    

    Name of the query block / Alias object (identified by the operation identity card):

    -------------------------------------------------------------

    1 SALT$ DD824119

    6 SALT$ 12 / ML@SEL$7

    7 - SALT$ CCA5E655 / from$_subquery$_020@SEL$12

    8 SALT$ CCA5E655

    10 - SALT$ A0D20652 / from$_subquery$_018@SEL$11

    11 SALT$ A0D20652

    13 SALT$ A0D20652 / EL@SEL$9

    14 SALT$ A0D20652 / EC@SEL$8

    15 SALT$ CCA5E655 / PO@SEL$10

    17 SALT$ DD824119 / PO@SEL$3

    18 SALT$ DD824119 / AE@SEL$4

    19 SALT$ DD824119 / EC@SEL$5

    20 SALT$ 16 / BT@SEL$1

    21 SALT$ 16

    22 - SALT$ 15 / from$_subquery$_003@SEL$16

    23 SALT $15

    25 SALT$ 15 / LMI@SEL$15

    27 SALT$ 15 / MI@SEL$15

    Information of predicates (identified by the operation identity card):

    ---------------------------------------------------

    2 - access("AE".") EMP_ID '=' BT '. "EMP_ID" (+)) "

    3 - filter("EC".") (ACTUAL_END"IS NULL)

    4 - access("AE".") EMP_ID '=' EC '. "EMP_ID" (+)) "

    5 - access("AE".") EMP_ID '=' ML '. ("' EMP_ID ')

    8 - filter("PO".") (ACTUAL_END"IS NULL)

    9 - access("PO".") EMP_ID' (+) = 'EL '. ("' EMP_ID ')

    11 - filter("EC".") (ACTUAL_END"IS NULL)

    12 - access("EC".") EMP_ID' (+) = 'EL '. ("' EMP_ID ')

    13 - filter("EL".") LEAVE_END' IS NULL AND 'EL '. "LEAVE_TYPE"= 6)

    16 - access("AE".") EMP_ID '=' PO '. ("' EMP_ID ')

    17 - filter("PO".") ACTUAL_END' IS NULL AND 'PO '. ("' HOUSED <>' 30)

    18 - filter("AE".") (CITIZENSHIP", <>1)

    26 - access("LMI".") WITH THE ID '=' MI '. ("' IMM_REC")

    filter ("LMI". "WITH THE '=' MI' ID '." " IMM_REC')

    Projection of the column information (identified by the operation identity card):

    -----------------------------------------------------------

    1 (#keys = 3) "AE". "CLOCK_NUMBER" [VARCHAR2, 11], "Æ" "." " LAST_NAME ' [VARCHAR2, 45],

    "AE". "FIRST NAME" [VARCHAR2, 35], MAX (DECODE (TO_CHAR ("BT" "."))) " ID'), '1', TO_CHAR (INTERNAL_FUNCTION ("BT". "MY

    ((XDATE'), 'DD-MON-YYYY'), NULL)) [11], MAX (DECODE (TO_CHAR ("BT". "' ' 'ID'), '2', TO_CHAR (INTERNAL_FUNCTION ("BT"." ""

    (('MAXDATE'), 'DD-MON-YYYY'), NULL)) [11], MAX (DECODE (TO_CHAR ("BT". "ID"), "3", TO_CHAR (INTERNAL_FUNCTION ("B

    « « « T ». » ((MAXDATE'), 'DD-MON-YYYY'), NULL)) [11], MAX (DECODE (TO_CHAR ("BT". "' ' 'ID'), '5', TO_CHAR (INTERNAL_FUNCTION" ""

    ('BT'. (((("' MAXDATE '), 'DD-MON-YYYY'), NULL)) [11], MAX (DECODE (TO_CHAR ("BT". "ID"), "6", TO_CHAR (INTERNAL_FUNCT

    ION ("BT". "MAXDATE'), 'DD-MON-YYYY')(, NULL)) [11], MAX (DECODE (TO_CHAR ("BT"." ID"),"8", TO_CHAR (INTERNAL_FU

    FUNCTION ("BT". "MAXDATE'), 'DD-MON-YYYY')(, NULL)) [11],"

    MAX (DECODE (TO_CHAR ("BT". "ID"), "9", TO_CHAR (INTERNAL_FUNCTION ("BT"." ((MAXDATE'), 'DD-MON-YYYY'), NULL)) [11

    ], MAX (DECODE (TO_CHAR ("BT". "' ' 'ID'), '10', TO_CHAR (INTERNAL_FUNCTION ("BT"." "" (MAXDATE'), 'DD-MON-YYYY'), NULL)

    ) [11].

    2. (#keys = 1) "AE". "LAST_NAME" [VARCHAR2, 45], "Æ" "." " FIRST NAME ' [VARCHAR2, 35],

    "AE". "CLOCK_NUMBER" [VARCHAR2, 11], 'BT' "." " MAXDATE "[DATE, 7], 'BT'". "" ID '[NUMBER, 22].

    3. "AE". "EMP_ID" [NO.22], "Æ" "." " LAST_NAME "[VARCHAR2, 45],"Æ"". "" FIRST NAME ' [VARCHAR2, 35],

    "AE". "CLOCK_NUMBER" [VARCHAR2, 11].

    4. (#keys = 1) "AE". "EMP_ID" [NO.22], "Æ" "." " LAST_NAME ' [VARCHAR2, 45],

    "AE". "FIRST NAME" [VARCHAR2, 35], "Æ" "." " CLOCK_NUMBER "[VARCHAR2, 11], 'CBS'". "" ACTUAL_END "[DATE, 7].

    5 (#keys = 1) "AE". "EMP_ID" [NO.22], "Æ" "." " FIRST NAME ' [VARCHAR2, 35],

    "AE". "CLOCK_NUMBER" [VARCHAR2, 11], "Æ" "." " LAST_NAME ' [VARCHAR2, 45].

    6 ' ML '. ' EMP_ID '[NUMBER, 22].

    7. "EL". ' EMP_ID '[NUMBER, 22].

    8. "EL". ' EMP_ID '[NUMBER, 22].

    9. (#keys = 1) 'EL '. "EMP_ID" [NO.22], "PO" "." " ACTUAL_END "[DATE, 7].

    10. "EL". ' EMP_ID '[NUMBER, 22].

    11. "EL". ' EMP_ID '[NUMBER, 22].

    12. (#keys = 1) 'EL '. "EMP_ID" [NO.22], 'CBS' "." " ACTUAL_END "[DATE, 7].

    13. "EL". ' EMP_ID '[NUMBER, 22].

    14. 'EC '. "EMP_ID" [NO.22], 'CBS' "." " ACTUAL_END "[DATE, 7].

    15. "PO." "EMP_ID" [NO.22], "PO" "." " ACTUAL_END "[DATE, 7].

    16. (#keys = 1) "AE". "EMP_ID" [NO.22], "Æ" "." " CLOCK_NUMBER ' [VARCHAR2, 11],

    "AE". "LAST_NAME" [VARCHAR2, 45], "Æ" "." " FIRST NAME ' [VARCHAR2, 35].

    17 "IN." ' EMP_ID '[NUMBER, 22].

    18. "AE". "EMP_ID" [NO.22], "Æ" "." " CLOCK_NUMBER "[VARCHAR2, 11],"Æ"". "" LAST_NAME ' [VARCHAR2, 45],

    "AE". "FIRST NAME" [VARCHAR2, 35].

    19. "EC". "EMP_ID" [NO.22], 'CBS' "." " ACTUAL_END "[DATE, 7].

    20. "BT". "EMP_ID" [NO.22], 'BT' "." " ID "[NO.22], 'BT'". "" MAXDATE '[DATE, 7].

    21. (#keys = 6) "MI". "EMP_ID" [NO.22], "LMI" "." " ID "[NO.22],"LMI"". "" IMM_DESC ' [VARCHAR2, 55],

    "LMI". "DRUG" [VARCHAR2, 55], "LMI" "." " SERIES "[VARCHAR2, 55],"LMI"". "" DSB "[NO.22], MAX ("IMM_DATE") [7]"

    22. "MI". "EMP_ID" [NO.22], "LMI" "." " ID "[NO.22],"LMI"". "" IMM_DESC ' [VARCHAR2, 55],

    "LMI". "DSB" [NO.22], "LMI" "." " DRUG "[VARCHAR2, 55],"LMI"". "" SERIES "[VARCHAR2, 55],"IMM_DATE "[DATE, 7]"

    23. (#keys = 0) "LMI". "ID" [NO.22], 'MI' "." " EMP_ID "[NO.22],"LMI"". "" SERIES "[VARCHAR2, 55],

    "LMI". "IMM_DESC" [VARCHAR2, 55], "LMI" "." " DSB "[NO.22],"LMI"". "" DRUG "[VARCHAR2, 55],

    "MI". "IMM_DATE"[DATE, 7].

    24. (#keys = 1) "LMI". "ID" [NO.22], "LMI" "." " SERIES "[VARCHAR2, 55],"LMI"". "" IMM_DESC ' [VARCHAR2, 55],

    "LMI". "DSB" [NO.22], "LMI" "." " DRUG "[VARCHAR2, 55].

    25. "DIA." "ID" [NO.22], "LMI" "." " IMM_DESC "[VARCHAR2, 55],"LMI"". "" DSB '[NUMBER, 22],

    "LMI". "DRUG" [VARCHAR2, 55], "LMI" "." " SERIES "[VARCHAR2, 55].

    26. (#keys = 1) "MI". "EMP_ID" [NO.22], 'MI' "." " IMM_REC "[NO.22], 'MI'". "" IMM_DATE "[DATE, 7].

    27. "MI". "EMP_ID" [NO.22], 'MI' "." " IMM_REC "[NO.22], 'MI'". "" IMM_DATE "[DATE, 7].

    2 original with adjusted

    ------------------------------

    Hash value of plan: 2311080268

    ------------------------------------------------------------------------------------------------------------
    | Id  | Operation                       | Name             | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    ------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                |                  |   151 | 14647 |       |   730   (3)| 00:00:09 |
    |   1 |  HASH GROUP BY                  |                  |   151 | 14647 |       |   730   (3)| 00:00:09 |
    |*  2 |   HASH JOIN OUTER               |                  |   151 | 14647 |       |   729   (2)| 00:00:09 |
    |*  3 |    FILTER                       |                  |       |       |       |            |          |
    |*  4 |     HASH JOIN OUTER             |                  |    14 |   980 |       |   275   (3)| 00:00:04 |
    |*  5 |      HASH JOIN RIGHT ANTI       |                  |     9 |   513 |       |   223   (4)| 00:00:03 |
    |   6 |       VIEW                      | MEDICAL_LEAVE    |    21 |   105 |       |   103   (4)| 00:00:02 |
    |   7 |        VIEW                     |                  |    21 |  1113 |       |   103   (4)| 00:00:02 |
    |*  8 |         FILTER                  |                  |       |       |       |            |          |
    |*  9 |          HASH JOIN OUTER        |                  |    21 |  1470 |       |   103   (4)| 00:00:02 |
    |  10 |           VIEW                  |                  |   332 | 18924 |       |    69   (3)| 00:00:01 |
    |* 11 |            FILTER               |                  |       |       |       |            |          |
    |* 12 |             HASH JOIN OUTER     |                  |   332 |  9296 |       |    69   (3)| 00:00:01 |
    |* 13 |              TABLE ACCESS FULL  | EMP_LEAVE        |   210 |  3150 |       |    17   (6)| 00:00:01 |
    |  14 |              TABLE ACCESS FULL  | EMP_CONTRACT     | 11156 |   141K|       |    52   (2)| 00:00:01 |
    |  15 |           TABLE ACCESS FULL     | POSITION_OFFERED |  9420 |   119K|       |    33   (4)| 00:00:01 |
    |* 16 |       HASH JOIN                 |                  |   376 | 19552 |       |   119   (2)| 00:00:02 |
    |* 17 |        TABLE ACCESS FULL        | POSITION_OFFERED |   376 |  6392 |       |    33   (4)| 00:00:01 |
    |* 18 |        TABLE ACCESS FULL        | AMPEMP           |  2579 | 90265 |       |    86   (2)| 00:00:02 |
    |  19 |      TABLE ACCESS FULL          | EMP_CONTRACT     | 11156 |   141K|       |    52   (2)| 00:00:01 |
    |  20 |    VIEW                         |                  |  4572 |   120K|       |   453   (2)| 00:00:06 |
    |  21 |     HASH GROUP BY               |                  |  4572 |   825K|  1992K|   453   (2)| 00:00:06 |
    |  22 |      VIEW                       |                  |  4572 |   825K|       |   265   (2)| 00:00:04 |
    |  23 |       MERGE JOIN PARTITION OUTER|                  |  4572 |   263K|       |   265   (2)| 00:00:04 |
    |  24 |        SORT JOIN                |                  |    18 |   774 |       |     4  (25)| 00:00:01 |
    |  25 |         TABLE ACCESS FULL       | LU_MED_IMMUNO    |    18 |   774 |       |     3   (0)| 00:00:01 |
    |* 26 |        SORT PARTITION JOIN      |                  |  2731 | 43696 |       |     6  (17)| 00:00:01 |
    |  27 |         TABLE ACCESS FULL       | MED_IMMUNO       |  2731 | 43696 |       |     5   (0)| 00:00:01 |
    ------------------------------------------------------------------------------------------------------------
    

    Name of the query block / Alias object (identified by the operation identity card):

    -------------------------------------------------------------

    1 SALT$ DD824119

    6 SALT$ 12 / ML@SEL$7

    7 - SALT$ CCA5E655 / from$_subquery$_020@SEL$12

    8 SALT$ CCA5E655

    10 - SALT$ A0D20652 / from$_subquery$_018@SEL$11

    11 SALT$ A0D20652

    13 SALT$ A0D20652 / EL@SEL$9

    14 SALT$ A0D20652 / EC@SEL$8

    15 SALT$ CCA5E655 / PO@SEL$10

    17 SALT$ DD824119 / PO@SEL$3

    18 SALT$ DD824119 / AE@SEL$4

    19 SALT$ DD824119 / EC@SEL$5

    20 SALT$ 16 / BT@SEL$1

    21 SALT$ 16

    22 - SALT$ 15 / from$_subquery$_003@SEL$16

    23 SALT $15

    25 SALT$ 15 / LMI@SEL$15

    27 SALT$ 15 / MI@SEL$15

    Information of predicates (identified by the operation identity card):

    ---------------------------------------------------

    2 - access("AE".") EMP_ID '=' BT '. "EMP_ID" (+)) "

    3 - filter("EC".") (ACTUAL_END"IS NULL)

    4 - access("AE".") EMP_ID '=' EC '. "EMP_ID" (+)) "

    5 - access("AE".") EMP_ID '=' ML '. ("' EMP_ID ')

    8 - filter("PO".") (ACTUAL_END"IS NULL)

    9 - access("PO".") EMP_ID' (+) = 'EL '. ("' EMP_ID ')

    11 - filter("EC".") (ACTUAL_END"IS NULL)

    12 - access("EC".") EMP_ID' (+) = 'EL '. ("' EMP_ID ')

    13 - filter("EL".") LEAVE_END' IS NULL AND 'EL '. "LEAVE_TYPE"= 6)

    16 - access("AE".") EMP_ID '=' PO '. ("' EMP_ID ')

    17 - filter("PO".") ACTUAL_END' IS NULL AND 'PO '. ("' HOUSED <>' 30)

    18 - filter("AE".") (CITIZENSHIP", <>1)

    26 - access("LMI".") WITH THE ID '=' MI '. ("' IMM_REC")

    filter ("LMI". "WITH THE '=' MI' ID '." " IMM_REC')

    Projection of the column information (identified by the operation identity card):

    -----------------------------------------------------------

    1 (#keys = 3) "AE". "CLOCK_NUMBER" [VARCHAR2, 11], "Æ" "." " LAST_NAME ' [VARCHAR2, 45],

    "AE". "FIRST NAME" [VARCHAR2, 35], MAX (DECODE (TO_CHAR ("BT" "."))) " ID'), '1', TO_CHAR (INTERNAL_FUNCTION ("BT". "MY

    ((XDATE'), 'DD-MON-YYYY'), NULL)) [11], MAX (DECODE (TO_CHAR ("BT". "' ' 'ID'), '2', TO_CHAR (INTERNAL_FUNCTION ("BT"." ""

    (('MAXDATE'), 'DD-MON-YYYY'), NULL)) [11], MAX (DECODE (TO_CHAR ("BT". "ID"), "3", TO_CHAR (INTERNAL_FUNCTION ("B

    « « « T ». » ((MAXDATE'), 'DD-MON-YYYY'), NULL)) [11], MAX (DECODE (TO_CHAR ("BT". "' ' 'ID'), '5', TO_CHAR (INTERNAL_FUNCTION" ""

    ('BT'. (((("' MAXDATE '), 'DD-MON-YYYY'), NULL)) [11], MAX (DECODE (TO_CHAR ("BT". "ID"), "6", TO_CHAR (INTERNAL_FUNCT

    ION ("BT". "MAXDATE'), 'DD-MON-YYYY')(, NULL)) [11], MAX (DECODE (TO_CHAR ("BT"." ID"),"8", TO_CHAR (INTERNAL_FU

    FUNCTION ("BT". "MAXDATE'), 'DD-MON-YYYY')(, NULL)) [11],"

    MAX (DECODE (TO_CHAR ("BT". "ID"), "9", TO_CHAR (INTERNAL_FUNCTION ("BT"." ((MAXDATE'), 'DD-MON-YYYY'), NULL)) [11

    ], MAX (DECODE (TO_CHAR ("BT". "' ' 'ID'), '10', TO_CHAR (INTERNAL_FUNCTION ("BT"." "" (MAXDATE'), 'DD-MON-YYYY'), NULL)

    ) [11].

    2. (#keys = 1) "AE". "LAST_NAME" [VARCHAR2, 45], "Æ" "." " FIRST NAME ' [VARCHAR2, 35],

    "AE". "CLOCK_NUMBER" [VARCHAR2, 11], 'BT' "." " MAXDATE "[DATE, 7], 'BT'". "" ID '[NUMBER, 22].

    3. "AE". "EMP_ID" [NO.22], "Æ" "." " LAST_NAME "[VARCHAR2, 45],"Æ"". "" FIRST NAME ' [VARCHAR2, 35],

    "AE". "CLOCK_NUMBER" [VARCHAR2, 11].

    4. (#keys = 1) "AE". "EMP_ID" [NO.22], "Æ" "." " LAST_NAME ' [VARCHAR2, 45],

    "AE". "FIRST NAME" [VARCHAR2, 35], "Æ" "." " CLOCK_NUMBER "[VARCHAR2, 11], 'CBS'". "" ACTUAL_END "[DATE, 7].

    5 (#keys = 1) "AE". "EMP_ID" [NO.22], "Æ" "." " FIRST NAME ' [VARCHAR2, 35],

    "AE". "CLOCK_NUMBER" [VARCHAR2, 11], "Æ" "." " LAST_NAME ' [VARCHAR2, 45].

    6 ' ML '. ' EMP_ID '[NUMBER, 22].

    7. "EL". ' EMP_ID '[NUMBER, 22].

    8. "EL". ' EMP_ID '[NUMBER, 22].

    9. (#keys = 1) 'EL '. "EMP_ID" [NO.22], "PO" "." " ACTUAL_END "[DATE, 7].

    10. "EL". ' EMP_ID '[NUMBER, 22].

    11. "EL". ' EMP_ID '[NUMBER, 22].

    12. (#keys = 1) 'EL '. "EMP_ID" [NO.22], 'CBS' "." " ACTUAL_END "[DATE, 7].

    13. "EL". ' EMP_ID '[NUMBER, 22].

    14. 'EC '. "EMP_ID" [NO.22], 'CBS' "." " ACTUAL_END "[DATE, 7].

    15. "PO." "EMP_ID" [NO.22], "PO" "." " ACTUAL_END "[DATE, 7].

    16. (#keys = 1) "AE". "EMP_ID" [NO.22], "Æ" "." " CLOCK_NUMBER ' [VARCHAR2, 11],

    "AE". "LAST_NAME" [VARCHAR2, 45], "Æ" "." " FIRST NAME ' [VARCHAR2, 35].

    17 "IN." ' EMP_ID '[NUMBER, 22].

    18. "AE". "EMP_ID" [NO.22], "Æ" "." " CLOCK_NUMBER "[VARCHAR2, 11],"Æ"". "" LAST_NAME ' [VARCHAR2, 45],

    "AE". "FIRST NAME" [VARCHAR2, 35].

    19. "EC". "EMP_ID" [NO.22], 'CBS' "." " ACTUAL_END "[DATE, 7].

    20. "BT". "EMP_ID" [NO.22], 'BT' "." " ID "[NO.22], 'BT'". "" MAXDATE '[DATE, 7].

    21. (#keys = 6) "MI". "EMP_ID" [NO.22], "LMI" "." " ID "[NO.22],"LMI"". "" IMM_DESC ' [VARCHAR2, 55],

    "LMI". "DRUG" [VARCHAR2, 55], "LMI" "." " SERIES "[VARCHAR2, 55],"LMI"". "" DSB "[NO.22], MAX ("IMM_DATE") [7]"

    22. "MI". "EMP_ID" [NO.22], "LMI" "." " ID "[NO.22],"LMI"". "" IMM_DESC ' [VARCHAR2, 55],

    "LMI". "DSB" [NO.22], "LMI" "." " DRUG "[VARCHAR2, 55],"LMI"". "" SERIES "[VARCHAR2, 55],"IMM_DATE "[DATE, 7]"

    23. (#keys = 0) "LMI". "ID" [NO.22], 'MI' "." " EMP_ID "[NO.22],"LMI"". "" SERIES "[VARCHAR2, 55],

    "LMI". "IMM_DESC" [VARCHAR2, 55], "LMI" "." " DSB "[NO.22],"LMI"". "" DRUG "[VARCHAR2, 55],

    "MI". "IMM_DATE"[DATE, 7].

    24. (#keys = 1) "LMI". "ID" [NO.22], "LMI" "." " SERIES "[VARCHAR2, 55],"LMI"". "" IMM_DESC ' [VARCHAR2, 55],

    "LMI". "DSB" [NO.22], "LMI" "." " DRUG "[VARCHAR2, 55].

    25. "DIA." "ID" [NO.22], "LMI" "." " IMM_DESC "[VARCHAR2, 55],"LMI"". "" DSB '[NUMBER, 22],

    "LMI". "DRUG" [VARCHAR2, 55], "LMI" "." " SERIES "[VARCHAR2, 55].

    26. (#keys = 1) "MI". "EMP_ID" [NO.22], 'MI' "." " IMM_REC "[NO.22], 'MI'". "" IMM_DATE "[DATE, 7].

    27. "MI". "EMP_ID" [NO.22], 'MI' "." " IMM_REC "[NO.22], 'MI'". "" IMM_DATE "[DATE, 7].

    3. using SQL profile

    --------------------

    Hash value of plan: 1010297951

    ------------------------------------------------------------------------------------------------------------
    | Id  | Operation                       | Name             | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    ------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                |                  |   151 | 14647 |       |   704   (2)| 00:00:09 |
    |   1 |  HASH GROUP BY                  |                  |   151 | 14647 |       |   704   (2)| 00:00:09 |
    |*  2 |   HASH JOIN OUTER               |                  |   151 | 14647 |       |   703   (2)| 00:00:09 |
    |*  3 |    FILTER                       |                  |       |       |       |            |          |
    |   4 |     NESTED LOOPS OUTER          |                  |    14 |   980 |       |   250   (3)| 00:00:03 |
    |*  5 |      HASH JOIN RIGHT ANTI       |                  |     9 |   513 |       |   223   (4)| 00:00:03 |
    |   6 |       VIEW                      | MEDICAL_LEAVE    |    21 |   105 |       |   103   (4)| 00:00:02 |
    |   7 |        VIEW                     |                  |    21 |  1113 |       |   103   (4)| 00:00:02 |
    |*  8 |         FILTER                  |                  |       |       |       |            |          |
    |*  9 |          HASH JOIN OUTER        |                  |    21 |  1470 |       |   103   (4)| 00:00:02 |
    |  10 |           VIEW                  |                  |   332 | 18924 |       |    69   (3)| 00:00:01 |
    |* 11 |            FILTER               |                  |       |       |       |            |          |
    |* 12 |             HASH JOIN OUTER     |                  |   332 |  9296 |       |    69   (3)| 00:00:01 |
    |* 13 |              TABLE ACCESS FULL  | EMP_LEAVE        |   210 |  3150 |       |    17   (6)| 00:00:01 |
    |  14 |              TABLE ACCESS FULL  | EMP_CONTRACT     | 11156 |   141K|       |    52   (2)| 00:00:01 |
    |  15 |           TABLE ACCESS FULL     | POSITION_OFFERED |  9420 |   119K|       |    33   (4)| 00:00:01 |
    |* 16 |       HASH JOIN                 |                  |   376 | 19552 |       |   119   (2)| 00:00:02 |
    |* 17 |        TABLE ACCESS FULL        | POSITION_OFFERED |   376 |  6392 |       |    33   (4)| 00:00:01 |
    |* 18 |        TABLE ACCESS FULL        | AMPEMP           |  2579 | 90265 |       |    86   (2)| 00:00:02 |
    |  19 |      TABLE ACCESS BY INDEX ROWID| EMP_CONTRACT     |     2 |    26 |       |     3   (0)| 00:00:01 |
    |* 20 |       INDEX RANGE SCAN          | EC_INDEX1        |     2 |       |       |     1   (0)| 00:00:01 |
    |  21 |    VIEW                         |                  |  4572 |   120K|       |   453   (2)| 00:00:06 |
    |  22 |     HASH GROUP BY               |                  |  4572 |   825K|  1992K|   453   (2)| 00:00:06 |
    |  23 |      VIEW                       |                  |  4572 |   825K|       |   265   (2)| 00:00:04 |
    |  24 |       MERGE JOIN PARTITION OUTER|                  |  4572 |   263K|       |   265   (2)| 00:00:04 |
    |  25 |        SORT JOIN                |                  |    18 |   774 |       |     4  (25)| 00:00:01 |
    |  26 |         TABLE ACCESS FULL       | LU_MED_IMMUNO    |    18 |   774 |       |     3   (0)| 00:00:01 |
    |* 27 |        SORT PARTITION JOIN      |                  |  2731 | 43696 |       |     6  (17)| 00:00:01 |
    |  28 |         TABLE ACCESS FULL       | MED_IMMUNO       |  2731 | 43696 |       |     5   (0)| 00:00:01 |
    ------------------------------------------------------------------------------------------------------------
    

    Name of the query block / Alias object (identified by the operation identity card):

    -------------------------------------------------------------

    1 SALT$ DD824119

    6 SALT$ 12 / ML@SEL$7

    7 - SALT$ CCA5E655 / from$_subquery$_020@SEL$12

    8 SALT$ CCA5E655

    10 - SALT$ A0D20652 / from$_subquery$_018@SEL$11

    11 SALT$ A0D20652

    13 SALT$ A0D20652 / EL@SEL$9

    14 SALT$ A0D20652 / EC@SEL$8

    15 SALT$ CCA5E655 / PO@SEL$10

    17 SALT$ DD824119 / PO@SEL$3

    18 SALT$ DD824119 / AE@SEL$4

    19 SALT$ DD824119 / EC@SEL$5

    20 SALT$ DD824119 / EC@SEL$5

    21 SALT$ 16 / BT@SEL$1

    22 SALT$ 16

    23 - SALT$ 15 / from$_subquery$_003@SEL$16

    24 SALT $15

    26 SALT$ 15 / LMI@SEL$15

    28. THE SALT $15 / MI@SEL$15

    Information of predicates (identified by the operation identity card):

    ---------------------------------------------------

    2 - access("AE".") EMP_ID '=' BT '. "EMP_ID" (+)) "

    3 - filter("EC".") (ACTUAL_END"IS NULL)

    5 - access("AE".") EMP_ID '=' ML '. ("' EMP_ID ')

    8 - filter("PO".") (ACTUAL_END"IS NULL)

    9 - access("PO".") EMP_ID' (+) = 'EL '. ("' EMP_ID ')

    11 - filter("EC".") (ACTUAL_END"IS NULL)

    12 - access("EC".") EMP_ID' (+) = 'EL '. ("' EMP_ID ')

    13 - filter("EL".") LEAVE_END' IS NULL AND 'EL '. "LEAVE_TYPE"= 6)

    16 - access("AE".") EMP_ID '=' PO '. ("' EMP_ID ')

    17 - filter("PO".") ACTUAL_END' IS NULL AND 'PO '. ("' HOUSED <>' 30)

    18 - filter("AE".") (CITIZENSHIP", <>1)

    20 - access("AE".") EMP_ID '=' EC '. "EMP_ID" (+)) "

    27 - access("LMI".") WITH THE ID '=' MI '. ("' IMM_REC")

    filter ("LMI". "WITH THE '=' MI' ID '." " IMM_REC')

    Projection of the column information (identified by the operation identity card):

    -----------------------------------------------------------

    1 (#keys = 3) "AE". "CLOCK_NUMBER" [VARCHAR2, 11], "Æ" "." " LAST_NAME ' [VARCHAR2, 45],

    "AE". "FIRST NAME" [VARCHAR2, 35], MAX (DECODE (TO_CHAR ("BT" "."))) " ID'), '1', TO_CHAR (INTERNAL_FUNCTION ("BT". "MY

    ((XDATE'), 'DD-MON-YYYY'), NULL)) [11], MAX (DECODE (TO_CHAR ("BT". "' ' 'ID'), '2', TO_CHAR (INTERNAL_FUNCTION ("BT"." ""

    (('MAXDATE'), 'DD-MON-YYYY'), NULL)) [11], MAX (DECODE (TO_CHAR ("BT". "ID"), "3", TO_CHAR (INTERNAL_FUNCTION ("B

    « « « T ». » ((MAXDATE'), 'DD-MON-YYYY'), NULL)) [11], MAX (DECODE (TO_CHAR ("BT". "' ' 'ID'), '5', TO_CHAR (INTERNAL_FUNCTION" ""

    ('BT'. (((("' MAXDATE '), 'DD-MON-YYYY'), NULL)) [11], MAX (DECODE (TO_CHAR ("BT". "ID"), "6", TO_CHAR (INTERNAL_FUNCT

    ION ("BT". "MAXDATE'), 'DD-MON-YYYY')(, NULL)) [11], MAX (DECODE (TO_CHAR ("BT"." ID"),"8", TO_CHAR (INTERNAL_FU

    FUNCTION ("BT". "MAXDATE'), 'DD-MON-YYYY')(, NULL)) [11],"

    MAX (DECODE (TO_CHAR ("BT". "ID"), "9", TO_CHAR (INTERNAL_FUNCTION ("BT"." ((MAXDATE'), 'DD-MON-YYYY'), NULL)) [11

    ], MAX (DECODE (TO_CHAR ("BT". "' ' 'ID'), '10', TO_CHAR (INTERNAL_FUNCTION ("BT"." "" (MAXDATE'), 'DD-MON-YYYY'), NULL)

    ) [11].

    2. (#keys = 1) "AE". "FIRST NAME" [VARCHAR2, 35], "Æ" "." " CLOCK_NUMBER ' [VARCHAR2, 11],

    "AE". "LAST_NAME" [VARCHAR2, 45], 'BT' "." " MAXDATE "[DATE, 7], 'BT'". "" ID '[NUMBER, 22].

    3. "AE". "EMP_ID" [NO.22], "Æ" "." " FIRST NAME "[VARCHAR2, 35],"Æ"". "" CLOCK_NUMBER ' [VARCHAR2, 11],

    "AE". "LAST_NAME" [VARCHAR2, 45].

    4. (#keys = 0) 'AE '. "EMP_ID" [NO.22], "Æ" "." " FIRST NAME ' [VARCHAR2, 35],

    "AE". "CLOCK_NUMBER" [VARCHAR2, 11], "Æ" "." " LAST_NAME "[VARCHAR2, 45], 'CBS'". "" ACTUAL_END "[DATE, 7].

    5 (#keys = 1) "AE". "EMP_ID" [NO.22], "Æ" "." " FIRST NAME ' [VARCHAR2, 35],

    "AE". "CLOCK_NUMBER" [VARCHAR2, 11], "Æ" "." " LAST_NAME ' [VARCHAR2, 45].

    6 ' ML '. ' EMP_ID '[NUMBER, 22].

    7. "EL". ' EMP_ID '[NUMBER, 22].

    8. "EL". ' EMP_ID '[NUMBER, 22].

    9. (#keys = 1) 'EL '. "EMP_ID" [NO.22], "PO" "." " ACTUAL_END "[DATE, 7].

    10. "EL". ' EMP_ID '[NUMBER, 22].

    11. "EL". ' EMP_ID '[NUMBER, 22].

    12. (#keys = 1) 'EL '. "EMP_ID" [NO.22], 'CBS' "." " ACTUAL_END "[DATE, 7].

    13. "EL". ' EMP_ID '[NUMBER, 22].

    14. 'EC '. "EMP_ID" [NO.22], 'CBS' "." " ACTUAL_END "[DATE, 7].

    15. "PO." "EMP_ID" [NO.22], "PO" "." " ACTUAL_END "[DATE, 7].

    16. (#keys = 1) "AE". "EMP_ID" [NO.22], "Æ" "." " CLOCK_NUMBER ' [VARCHAR2, 11],

    "AE". "LAST_NAME" [VARCHAR2, 45], "Æ" "." " FIRST NAME ' [VARCHAR2, 35].

    17 "IN." ' EMP_ID '[NUMBER, 22].

    18. "AE". "EMP_ID" [NO.22], "Æ" "." " CLOCK_NUMBER "[VARCHAR2, 11],"Æ"". "" LAST_NAME ' [VARCHAR2, 45],

    "AE". "FIRST NAME" [VARCHAR2, 35].

    19. "EC". "ACTUAL_END"[DATE, 7].

    20. "EC". ROWID [ROWID, 10]

    21. "BT". "EMP_ID" [NO.22], 'BT' "." " ID "[NO.22], 'BT'". "" MAXDATE '[DATE, 7].

    22. (#keys = 6) "MI". "EMP_ID" [NO.22], "LMI" "." " ID "[NO.22],"LMI"". "" IMM_DESC ' [VARCHAR2, 55],

    "LMI". "DRUG" [VARCHAR2, 55], "LMI" "." " SERIES "[VARCHAR2, 55],"LMI"". "" DSB "[NO.22], MAX ("IMM_DATE") [7]"

    23. "MI". "EMP_ID" [NO.22], "LMI" "." " ID "[NO.22],"LMI"". "" IMM_DESC ' [VARCHAR2, 55],

    "LMI". "DSB" [NO.22], "LMI" "." " DRUG "[VARCHAR2, 55],"LMI"". "" SERIES "[VARCHAR2, 55],"IMM_DATE "[DATE, 7]"

    24. (#keys = 0) "LMI". "ID" [NO.22], 'MI' "." " EMP_ID "[NO.22],"LMI"". "" SERIES "[VARCHAR2, 55],

    "LMI". "IMM_DESC" [VARCHAR2, 55], "LMI" "." " DSB "[NO.22],"LMI"". "" DRUG "[VARCHAR2, 55],

    "MI". "IMM_DATE"[DATE, 7].

    25. (#keys = 1) "LMI". "ID" [NO.22], "LMI" "." " SERIES "[VARCHAR2, 55],"LMI"". "" IMM_DESC ' [VARCHAR2, 55],

    "LMI". "DSB" [NO.22], "LMI" "." " DRUG "[VARCHAR2, 55].

    26 "DIA." "ID" [NO.22], "LMI" "." " IMM_DESC "[VARCHAR2, 55],"LMI"". "" DSB '[NUMBER, 22],

    "LMI". "DRUG" [VARCHAR2, 55], "LMI" "." " SERIES "[VARCHAR2, 55].

    27. (#keys = 1) "MI". "EMP_ID" [NO.22], 'MI' "." " IMM_REC "[NO.22], 'MI'". "" IMM_DATE "[DATE, 7].

    28. "MI". "EMP_ID" [NO.22], 'MI' "." " IMM_REC "[NO.22], 'MI'". "" IMM_DATE "[DATE, 7].

    -------------------------------------------------------------------------------

    The SQL Profiler are actually implementation plans.  Sometimes the tuning Advisor will find a best execution plan when the problem sql statement.  If so, then it will tell you what you have posted above.    If you accept the profile sql recommended for the tuned sql statement, it will always use this same by the profile of sql execution plan agreed.

    Several times, including peoplesoft, plans of execution applications change all the time depending on the amount of data gets added/updated / deleted on a weekly or monthly basis, etc...   For this reason a sql statement can perform very well at the beginning, but a month or 2 later, it is a poor performance due to the optimizer oracle modifying execution plan.

    If the sql statement has a sql profile agreed to do this, it will always use the same execution plan.   Note however that over time, the profile sql may not have the optimal execution plan more, they do not work forever, unless your database is not change and/or development...

    The pl/sql tuning advisor came back with in your original post is what you need to perform to implement sql profile.  I never implement if the improvement by setting Advisor is 90% or more (I noticed yours was)<= 10,="" which="" is="" pretty="">

    I also always force_match-online set to true when you implement a sql profile, it's so if there are values of variables of different data values/identification, profile sql will always be used for iterations of the same sql statement.

    Here is the syntax (I added the force below the end of your original)

    run dbms_sqltune.accept_sql_profile (task_name-online 'staName20789', replace-online TRUE, force_match-online true);

  • Help on the game of query results

    Hi gurus,

    Have this survey for my requirement of dataset sql.

    Sample, it's that I have to pick up the nonfunctional currency transactions.

    Lets say for a given month, data that are present are for CurrencyA and CurrencyB for a particular account.

    Account1 has a transaction does not work CurrencyA and CurrenyB then Account2 has only transaction to CurrencyB.

    My current query result is that the 3 first lines, what I need is the 4th should also appear and be included.

    CurrencyA - amount - account1

    CurrencyB - amount - account1

    CurrencyB - amount - Account2

    CurrencyA - < '0' / or null >-Account2

    I think that my request is based on the currency < x > I have, so it should be for each account, he has all the lines for each currency.

    If please notify and let me know your thoughts.

    Kind regards

    Hello

    It looks like you want an outer join partitioned.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • Transform data in rows in column

    I don't know if the subject of this discussion justifies the question here! My question is:

    The result of my query looks like this:

    class_id total_employees identifiant_composant

    12                    1                  670

    12                    2                  1104

    11                    1                  131

    11                    2                  316

    13                    2                  5

    15                    1                  10

    The following query on the result above should make the output looks like this:

    id_comp total_employees_in_class_id_1 total_employees_in_class_id_2

    12                 670                                                 1104

    11                 131                                                 316

    13                 0                                                     5

    15                 10                                                   0

    I tried using lead and lag, but I can't get identifiant_composant where either missing class_id 1 or 2 as identifiant_composant = 13 or 15.

    Hello

    Here's one way:

    SELECT id_comp

    , NVL (total_1, 0) AS total_employees_in_class_id_1

    , NVL (total_2, 0) AS total_employees_in_class_id_2

    FROM MyTable

    PIVOT)

    SUM (total_employees)

    FOR class_id (1 AS total_1

    2 UNDER total_2

    )

    )

    ORDER BY id_comp

    ;

    You could do this with ADVANCE or a DELAY.  You could do an outer join partitioned on a table (or subquery) with 2 lines, to ensure that the results (before calling ADVANCE or a DELAY) always had 2 lines by identifiant_composant, but I can't see any advantage to doing it this way,

  • get the max value date in plsql

    My data in the table are like that

    Date Col1, Col2
    01/01/2012 A01 100
    01/01/2012 B01 200
    01/01/2012 C01 200

    01/02/2012 C01 100

    01/03/2012 B01 100


    I want to show the result of the query with carry on data like this

    01/01/2012 A01 100
    01/01/2012 B01 200
    01/01/2012 C01 200

    01/02/2012 A01 100
    01/02/2012 B01 200
    01/02/2012 C01 100

    01/03/2012 A01 200
    01/03/2012 B01 100
    01/03/2012 C01 100

    Please help me.

    Hello

    Welcome to the forum!

    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).
    See the FAQ forum {message identifier: = 9360002}

    I think you want an outer join partitioned (to make sure that all dates are represented for all values in col1) and the analytical LAST_VALUE function, like this:

    WITH     all_dates     AS
    (
         SELECT DISTINCT  dt     -- DATE is not a good column name
         FROM              table_x
    )
    SELECT       a.dt
    ,       x.col1
    ,       LAST_VALUE (col2 IGNORE NULLS) OVER ( PARTITION BY  x.col1
                                                    ORDER BY      a.dt
                                   )           AS col2_shown
    FROM             all_dates  a
    LEFT OUTER JOIN      table_x    x  PARTITION BY  (x.col1)
                                   ON  x.dt = a.dt
    ;
    

    If you would care to post CREATE TABLE and INSERT statements for your sample data, and then I could test this.

  • Help of the SQL query.

    Hello

    It's my first table REPORT

    report as)
    Select 'vendor_1' vendor, to_date('1/1/2012','DD/MM/YYYY') supply_date, "customer_1" as a customer, "item_1" like item1, 110 as cost of double union all
    Select 'vendor_1' vendor, to_date('1/3/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" like item1, 120 as cost of double union all
    Select 'vendor_1' vendor, to_date('1/3/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" like item1, 130 as cost of double union all
    Select 'vendor_1' vendor, to_date('1/4/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" like item1, 140 as cost of double union all
    Select 'vendor_1' vendor, to_date('1/10/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" element, 200as cost of double union all
    Select 'vendor_1' vendor, to_date('1/23/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" as point 0 as the cost of dual union all
    Select 'vendor_1' vendor, to_date('1/6/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 160 as cost of double union all
    Select 'vendor_1' vendor, to_date('1/7/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 170 as cost of double union all
    Select 'vendor_1' vendor, to_date('1/8/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 180 as cost of double union all
    Select 'vendor_1' vendor, to_date('1/9/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 190 as cost of double union all
    Select 'vendor_1' vendor, to_date('1/20/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 300 as cost of double)






    IT'S MY SECOND TABLE: TEMP_WEEK

    WITH temp_week (s)
    SELECT January 1, 2012 to 07/01/2012 ' AS the week of all the double union
    SELECT August 1, 2012 to 14/01/2012 ' AS the week of all the double union
    January 15, 2012 to 21/01/2012 ' AS the week of all the double union
    SELECT January 22, 2012 to 28/01/2012 ' AS the week of all the double union
    (SELECT 29 January 2012 to 31/01/2012 ' WEEK of double)


    To find weekly sales that I wrote query below:

    SELECT week, supplier, customer, SUM (cost)
    (SELECT week, supplier, customer, TOTAL costs (cost)
    FROM (SELECT BOX
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 1 AND 7 MAY
    January 1, 2012 to 07/01/2012 '
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 8 AND 14 MAY
    14/01/2012, 1 August 2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 15 AND 21 THEN
    January 15, 2012 to 21/01/2012 '
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 22 AND 28 and THEN
    January 22, 2012 to 28/01/2012 '
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 29 AND 31 MAY
    29 January 2012 to 31/01/2012 '
    END
    week, supplier, customer, cost
    REPORT)
    GROUP BY week, supplier, customer
    UNION ALL
    SELECT tw.week, vendor, customer or 0
    (SELECT week, supplier, customer, TOTAL costs (cost)
    FROM (SELECT BOX
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 1 AND 7 MAY
    January 1, 2012 to 07/01/2012 '
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 8 AND 14 MAY
    14/01/2012, 1 August 2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 15 AND 21 THEN
    January 15, 2012 to 21/01/2012 '
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 22 AND 28 and THEN
    January 22, 2012 to 28/01/2012 '
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 29 AND 31 MAY
    29 January 2012 to 31/01/2012 '
    END
    week, supplier, customer, cost
    REPORT)
    GROUP BY week, supplier, customer), temp_week tw)
    GROUP BY week, supplier, customer
    ORDER BY supplier, customer, week;


    with above query I get below output:


    with output voltage)
    Select January 1, 2012 to 07/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 500 as cost of double union all
    Select August 1, 2012, to 14/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 200 as cost of double union all
    Select January 15, 2012 to 21/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 0 as the cost of dual union all
    Select January 22, 2012 to 28/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 0 as the cost of dual union all
    Select the 29 January 2012 to 31/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 0 as the cost of dual union all
    Select January 1, 2012 to 07/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, 330 as costs of double union all
    Select August 1, 2012, to 14/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, 370 as cost of double union all
    Select January 15, 2012 to 21/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, 300 as cost of double union all
    Select January 22, 2012 to 28/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, 0 as the cost of dual union all
    Select the 29 January 2012 to 31/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, double cost of 0)

    Clearly, I used cross join. But I want to get the same result with another way. I don't want to use cross join and Union

    Please help me in this.

    What you desire can be accomplished using the outer join partitioned.
    The documentation shows an example of [url http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10002.htm#i2177515] this way to fill the gaps in the data.

    Here's how you can use it in your case:

    SQL> with report as (
      2     select 'vendor_1' as vendor,to_date('1/1/2012','DD/MM/YYYY') supply_date, 'customer_1'as customer,'item_1' as item1, 110 as
    cost from dual union all
      3     select 'vendor_1' as vendor,to_date('1/3/2012','MM/DD/YYYY') supply_date,'customer_1'as customer, 'item_1' as item1,120 as c
    ost from dual union all
      4     select 'vendor_1' as vendor,to_date('1/3/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item1,130 as
    cost from dual union all
      5     select 'vendor_1' as vendor,to_date('1/4/2012','MM/DD/YYYY') supply_date,'customer_1'as customer, 'item_1' as item1,140 as c
    ost from dual union all
      6     select 'vendor_1' as vendor,to_date('1/10/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item ,200as
    cost from dual union all
      7     select 'vendor_1' as vendor,to_date('1/23/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item,0 as co
    st from dual union all
      8     select 'vendor_1' as vendor,to_date('1/6/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,160 as c
    ost from dual union all
      9     select 'vendor_1' as vendor,to_date('1/7/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,170 as c
    ost from dual union all
     10     select 'vendor_1' as vendor,to_date('1/8/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,180 as c
    ost from dual union all
     11     select 'vendor_1' as vendor,to_date('1/9/2012','MM/DD/YYYY') supply_date,'customer_2'as customer,'item_1' as item1,190 as co
    st from dual union all
     12     select 'vendor_1' as vendor,to_date('1/20/2012','MM/DD/YYYY') supply_date,'customer_2'as customer,'item_1' as item1,300 as c
    ost from dual
     13  ), weeks as (
     14     select to_date('1/1/2012','DD/MM/YYYY') + (level-1)*7 week_start
     15          , to_date('1/1/2012','DD/MM/YYYY') + (level-1)*7 + 6 week_end
     16          , level week_pseudo_id
     17       from dual
     18     connect by level <= 5 /* substitute desired number of weeks */
     19  )
     20  --
     21  -- end-of-test-data
     22  --
     23  select to_char(max(weeks.week_start),'DD/MM/YYYY')
     24         || ' to ' ||
     25         to_char(max(weeks.week_end),'DD/MM/YYYY') week
     26       , vendor
     27       , customer
     28       , nvl(sum(cost),0) cost
     29    from report
     30   partition by (vendor, customer)
     31   right outer join weeks
     32         on weeks.week_start <= report.supply_date
     33         and weeks.week_end >= report.supply_date
     34   group by
     35         vendor
     36       , customer
     37       , week_pseudo_id
     38   order by
     39         vendor
     40       , customer
     41       , week_pseudo_id
     42  /
    
    WEEK                     VENDOR   CUSTOMER         COST
    ------------------------ -------- ---------- ----------
    01/01/2012 to 07/01/2012 vendor_1 customer_1        500
    08/01/2012 to 14/01/2012 vendor_1 customer_1        200
    15/01/2012 to 21/01/2012 vendor_1 customer_1          0
    22/01/2012 to 28/01/2012 vendor_1 customer_1          0
    29/01/2012 to 04/02/2012 vendor_1 customer_1          0
    01/01/2012 to 07/01/2012 vendor_1 customer_2        330
    08/01/2012 to 14/01/2012 vendor_1 customer_2        370
    15/01/2012 to 21/01/2012 vendor_1 customer_2        300
    22/01/2012 to 28/01/2012 vendor_1 customer_2          0
    29/01/2012 to 04/02/2012 vendor_1 customer_2          0
    
    10 rows selected.
    

    I have redesigned weeks of date columns for the join which will probably perform better and can possibly use indexes.
    I assume that you have no time portion in your supply_date data? If you do, then week_end will need to be modified.

Maybe you are looking for