Union of crazy on 3 tables

Hi all, I hope I have explained this madness of...

I have 3 tables (a, b, c) which have same pk (called product_serial). The same product_serial can exist in one or all three tables. No one table is the primary table (although tables a and b are preferable to the c). In 2 tables (a, b) there is also a unique key (known as popcon). The product_serial, popcon combination can be duplicated through these 2 tables, once more, neither is the master. If data exist in the table a or b, then we don't really need to worry on c, but of course, if the data does not exist in a or b, then we have need c data.

I would like to create a view in any of these 3 tables so that the data are merged so that I can create a virtual master so that I can then join to other tables. The view must contain a unique set of product_serials and popcons.

For a product_serial which is duplicated between a and b tables, a union works as expected and I pick up a single line.
Select * from abc_view where product_serial = 'psa1.
returns...
product_serial, popcon
psa1, pca1

But when there is a record in c, a or b, then the union returns duplicates.
Select * from abc_view where product_serial = 'psb1.
returns...
product_serial, popcon
pSB1, pcb1
pSB1, null

In the latter case, since a record found in a or b, which should take peference, and we don't need to worry about the c.

So I guess that 2 possible solutions come to mind,
1. is there a way to filter the record that has a popcon null when there are no records with a non-null value for this product_serial?
2. is there a way to union and b, but only if there are no results then question c (that is, if the union of b returns the result, then it is all we need)?

IM open to other solutions as well. Of course, the obvious solution is to go the difficulty of the model of data, but for some reason any of this is not possible atm :).

Here is my test data...


drop table;
drop table b;
drop table c;
create table a (product_serial VARCHAR2 (255) primary key, popcon VARCHAR2 (255) unique, name VARCHAR2 (255));
create table b (primary key of the product_serial VARCHAR2 (255), popcon VARCHAR2 (255) unique, name VARCHAR2 (255));
create table c (product_serial VARCHAR2 (255) primary key, name VARCHAR2 (255));
insert into a values ('psa1', 'pca1', 'namea1');
insert into a values ('psa2', 'pca2', 'namea2');
insert into b values ('psb1', 'pcb1', 'nameb1');
insert into b values ('psb2', 'pcb2', 'nameb2');
insert into b values ('psa1', 'pca1', 'namea1'); -double in one
insert into c values ('psc1', 'namec1');
insert into c values ('psc2', 'namec2');
insert into c values ('psb1', 'nameb1'); -duplicated in b
commit;

Drop view abc_view;
Create view abc_view as
Select product_serial, popcon of
(
(select product_serial, popcon since one
Union
Select product_serial, b popcon)
Union
Select product_serial, null of c
);


Thanks in advance.

Published by: user523756 on May 24, 2011 07:55
create or replace
  view abc_view
    as
      select  product_serial,
              popcon
        from  (
               select  product_serial,
                       popcon,
                       row_number() over(partition by product_serial oder by popcorn nulls last) rn
                 from  (
                         select  product_serial,
                                 popcon
                           from  a
                        union all
                         select  product_serial,
                                 popcon
                           from  b
                        union all
                         select  product_serial,
                                 null popcon
                           from  c
                       )
              )
  where rn = 1
/

SY.

Tags: Database

Similar Questions

  • With the help of SCORE on top of view with UNION

    Hi guys,.

    I explain what I'm trying to do it quickly:

    2 tables: table1 and table2 with the same structure and have both a multi_column_datastore ctxsys.context.

    1 view: View1

    Select * from table1

    Union

    Select * from table2

    If I run:

    Select * from View1 WHERE contains (view1. Column1, '% textext %', 1) > 0;

    It works fine, I get the correct result.

    If I try to use the PARTITION function, I got an error:

    Select * from View1 WHERE contains (view1. Column1, '% textext %', 1) > 0 ORDER by SCORE (1);

    ORA-29921: auxiliary operator not supported with query to configure block

    I understand the problem is in the UNION inside the view, is it possible to keep work, filtering the VIEW?

    Thanks in advance

    There is no score in the view, so you cannot reference the score when you query the view.  In order to put the note in the view, you need a contains the clause, which requires a value.  A method to do this is to use sys_context.  Please see the reproduction of the problem and solution below.

    Scott@orcl12c >-reproduction of the problem:

    Scott@orcl12c > create the table1 table:

    2 (column1 varchar2 (30))

    3.

    Table created.

    Scott@orcl12c > insert into table1 values ('textext")

    2.

    1 line of creation.

    Scott@orcl12c > create table table2

    2 (column1 varchar2 (30))

    3.

    Table created.

    Scott@orcl12c > insert into table2 values ('textext")

    2.

    1 line of creation.

    Scott@orcl12c > start

    2 ctx_ddl.create_preference ('test_ds', 'multi_column_datastore');

    3 ctx_ddl.set_attribute ('test_ds', 'columns', "column1");

    4 end;

    5.

    PL/SQL procedure successfully completed.

    Scott@orcl12c > create index table1_idx on table1 (column1)

    2 indextype is ctxsys.context

    3 parameters ("test_ds of the data store")

    4.

    The index is created.

    Scott@orcl12c > create index table2_idx on the table2 (column1)

    2 indextype is ctxsys.context

    3 parameters ("test_ds of the data store")

    4.

    The index is created.

    Scott@orcl12c > create or replace view View1

    2 as

    3 select * from table1

    4 union

    5 select * from table2

    6.

    Created view.

    Scott@orcl12c > select * from View1 where contains (view1.column1, '% textext %', 1) > 0

    2.

    COLUMN1

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

    textext

    1 selected line.

    Scott@orcl12c > select * from View1 where contains > 0 (view1.column1,'%textext%',1) order by score (1)

    2.

    Select * from View1 where contains > 0 (view1.column1,'%textext%',1) order by score (1)

    *

    ERROR on line 1:

    ORA-29921: auxiliary operator not supported with query to configure block

    Scott@orcl12c >-solution:

    Scott@orcl12c > create or replace view View1

    2 as

    3. Select the partition (1) score, table1.* from table1

    4 where contains (table1. Column1, sys_context ('text_query', 'query_value'), 1) > 0

    5 union

    6 select score partition (1), table2.* from table2

    7 where contains (table2.column1, sys_context ('text_query', 'query_value'), 1) > 0

    8.

    Created view.

    Scott@orcl12c > create or replace context text_query using text_proc

    2.

    Context that is created.

    Scott@orcl12c > create or replace procedure text_proc

    2 (p_val in varchar2)

    3 as

    4 start

    5 dbms_session.set_context ('text_query', "query_value", p_val);

    6 end text_proc;

    7.

    Created procedure.

    Scott@orcl12c > text_proc exec ('% textext %')

    PL/SQL procedure successfully completed.

    Scott@orcl12c > set autotrace on explain

    Scott@orcl12c > select * from View1 by score

    2.

    MARK THE COLUMN1

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

    3 textext

    1 selected line.

    Execution plan

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

    Hash value of plan: 4090246122

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

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |

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

    |   0 | SELECT STATEMENT |            |     2.    60.     8 (0) | 00:00:01 |

    |   1.  SORT ORDER BY |            |     2.    60.     8 (0) | 00:00:01 |

    |   2.   VIEW                          | VIEW1.     2.    60.     8 (0) | 00:00:01 |

    |   3.    UNIQUE FATE |            |     2.    58.     8 (50) | 00:00:01 |

    |   4.     UNION-ALL |            |       |       |            |          |

    |   5.      TABLE ACCESS BY INDEX ROWID | TABLE1.     1.    29.     4 (0) | 00:00:01 |

    |*  6 |       DOMAIN INDEX | TABLE1_IDX |       |       |     4 (0) | 00:00:01 |

    |   7.      TABLE ACCESS BY INDEX ROWID | TABLE2.     1.    29.     4 (0) | 00:00:01 |

    |*  8 |       DOMAIN INDEX | TABLE2_IDX |       |       |     4 (0) | 00:00:01 |

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

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

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

    6 - access("CTXSYS".") CONTAINS "(" TABLE1".»)" Column1', SYS_CONTEXT ('text_query ',' query_v)

    Alou '), 1) > 0)

    8 - access("CTXSYS".") CONTAINS "(" TABLE2".»)" Column1', SYS_CONTEXT ('text_query ',' query_v)

    Alou '), 1) > 0)

    Note

    -----

    -the dynamic statistics used: dynamic sampling (level = 2)

    Scott@orcl12c >

  • SQL INTO union-clause

    SQL help

    If any of the queries Union returns a value, I would like to mark as closed status. How can I put the INTO clause in this case because of two queries. Thank you

    BEGIN

    SELECT 1

    FROM TableA your
    WHERE tA.col1 = 13
    AND tA.col2 = '100'
    UNION
    SELECT 1
    TB from TableA
    WHERE tb.col2 = 'y '.
    AND tb.col3 = - 123
    AND tb.col4 IS NOT NULL;

    status_cd: = 'closed ';

    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    status_cd: = 'Unknown ';

    END;

    Hello

    Here's one way:

    BEGIN

    SELECT 'closed '.

    IN status_cd

    FROM tablea

    WHERE ((col1 = 13

    AND col2 = '100'

    )

    OR (col2 = 'y')

    AND col3 = - 123

    AND col4 IS NOT NULL

    )

    )

    AND ROWNUM = 1;

    EXCEPTION

    WHEN NO_DATA_FOUND

    THEN

    status_cd: = 'Unknown ';

    END;

  • create table physical use of select in the repository

    Hi gurus,

    We can create physical table in OBIEE 11.1.1.6 repository with stored procedure and select?
    How is the right syntax?

    Thank you very much

    JOE

    Hello

    Yes. just select and put it under layers of physics
    for example,.
    Select field1, field2. field_n
    tables
    UNION
    Select field1, field2. field_n
    tables;

    http://gerardnico.com/wiki/dat/OBIEE/opaque_view
    http://www.clearpeaks.com/blog/Oracle-BI-EE-11gusing-select_physical-in-OBIEE-11g
    http://allaboutobiee.blogspot.com/2012/05/OBIEE-11g-deployundeploy-view-in.html

    Thank you
    Deva

  • Several flat_files through the external table with only the common columns of loading

    Hi, I have 50 flat files and each of them have some columns (fields) common and I need to load only the fields that are common to an external Table. Is any chance to do it with education unique external table. Or I need to load all flat_files at separate tables and then with the ETG and UNION load them only one table.

    If the page size for all the files are different, I think that your only option would be to define different external tables and create a view that joins all the.

    HTH
    Srini

  • Alternative and improvement of the union query?

    Hello

    I have 2 sets of similar data together with a union query.

    Simplified example
    *Table A*
    Name Dept
    Ben    1
    Amy   3
    Ken    3
    
    *Table B*
    Name Dept
    Jim    1
    John  2
    Sue   3
    
    select Name, Dept
    from table A
    UNION
    select Name, Dept
    from table B
    I want to do is to ONLY include data from the second part of the union query, where it is associated with the first part of the union query data.

    For example
    select Name, Dept
    from table A
    UNION
    select Name, Dept
    from table B
    where Dept in (select distinct Dept from A)
    That's why John, who works in the Dept 2 would not be included in the results.

    Is there a better or more effective way to achieve that my example using the subquery in the where clause?

    Thank you very much
    Hazel

    Hi, Hazel,

    What you posted is as good as you can get without changing tables.

    Do not say SEPARATE in the IN-under-query:

    ...
    where   Dept in (  select  Dept
                       from    A
                    )
    

    will get the same results, maybe a little faster.

  • Summary of the Union query

    Hi all
    I'm trying yo build a union query, in the simple table view for the sum, I get the following error

    Error codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 42038] A REPORT of a total amount of function must be in a worksheet query block. (HY000)

    can someone give the solution for this

    Thanks in advance.

    Hello

    A check the option based on the Total (if any) report for the totals or subtotals, you applied.

    This option is available after you click the sigma button

  • Join the nearest date "not used".

    I need to join the following tables by the next date "not previously signed" the nearest:

    start_table:

    st_id start_dt
    start031-dec-2014
    Start1

    January 3, 2015

    Start2January 5, 2015
    start3January 7, 2015
    Debut48 January 2015
    Debut5January 14, 2015

    end_table:

    end_id end_dt
    end0January 1, 2015
    End1January 2, 2015
    End2January 13, 2015
    End3January 15, 2015
    bout4January 17, 2015
    end519 January 2015
    end6January 20, 2015

    Result:

    st_id end_id
    start0end0
    Start1End2
    Start2End3
    start3bout4
    Debut4end5
    Debut5end6

    start0 joined end0, because the closer to the date of the next 31-dec-2014 is 1 January 2015

    Start1 joined end2, because the closer to the date of the next January 3, 2015 is January 13, 2015.

    Start2 joined end3, because as well as the date of the next more close January 5, 2015 is 13 January 2015, this is already accompanied Start1, so she joined next January 15, 2015.

    start3 joined bout4, because the date of the next although most close January 7, 2015 is 13 January 2015, this one is already joined by Start1, earliest date is January 15, 2015, but is also already joined by start2, then he joined the next available date January 17, 2015.

    Database: 11g

    Thanks in advance

    [UPDATE: changed line 37 to add "or cnt > = 0".] [This covers cases where there are more departures that ends at first.]

    Jiri.Machotka - Oracle wrote:

    I found a non recursive algorithm for this problem...

    I came up with something similar: no recursion, no joins, each table read only once.

    1. UNION ALL marked times 1 tables, with lines of departure and end marked lines - 1
    2. Order by date (first lines) and get a combination of 1's and - 1's.
      so when there are too many lines to end, the sum is negative.
    3. Get the previous cumulative minimum! Then take that end with a sum running lines, at less than the previous minimum.
    4. The remaining lines will have an end of line for each line of departure. Now number lines starting from 1 to N and the lines at the end of 1 to N, then match lines start and end in pairs. I use PIVOT to do this.
    WITH end_table (end_id, end_dt) AS (
      select 'end0',to_date('01-jan-2015','dd-mon-yyyy') from dual union all
      select 'end1',to_date('02-jan-2015','dd-mon-yyyy') from dual union all
      select 'end2',to_date('13-jan-2015','dd-mon-yyyy') from dual union all
      SELECT 'end3',to_date('15-jan-2015','dd-mon-yyyy') FROM dual UNION ALL
      select 'end4',to_date('17-jan-2015','dd-mon-yyyy') from dual union all
      SELECT 'end5',to_date('19-jan-2015','dd-mon-yyyy') FROM dual UNION ALL
      SELECT 'end6',to_date('20-jan-2015','dd-mon-yyyy') FROM dual
    )
    ,start_table (start_id, start_dt) AS (
      select 'start0',to_date('31-dec-2014','dd-mon-yyyy') from dual union all
      select 'start1',to_date('03-jan-2015','dd-mon-yyyy') from dual union all
      select 'start2',to_date('05-jan-2015','dd-mon-yyyy') from dual union all
      select 'start3',to_date('07-jan-2015','dd-mon-yyyy') from dual union all
      select 'start4',to_date('08-jan-2015','dd-mon-yyyy') from dual union all
      SELECT 'start5',to_date('14-jan-2015','dd-mon-yyyy') FROM dual
    )
    , start_and_end as (
      select -1 rowtype, end_id id, end_dt dt from end_table
      union all
      select 1, s.* from start_table s
    )
    , running_count as (
      select se.*,
        sum(rowtype) over(order by dt, rowtype desc) cnt
      from start_and_end se
    )
    , filtered_ends as (
      select rowtype, id, dt from (
        select rc.*,
          min(decode(rowtype,-1,cnt)) over(
            order by dt, rowtype desc
            rows between unbounded preceding and 1 preceding
          ) mincnt
        from running_count rc
      )
      where cnt >= nvl(mincnt,0) or cnt >= 0
    )
    select * from (
      select rowtype, id,
      row_number() over(partition by rowtype order by dt) rn
      from filtered_ends
    )
    pivot(max(id) for rowtype in(1 st_id, -1 end_id))
    order by rn;
    

    ST_ID END_ID RN

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

    1 start0 end0

    2 Start1 end2

    3 Start2 end3

    4 start3 bout4

    5 debut4 end5

    Debut5 6 end6

  • Question of the Clause

    Hello
    I have a query like the following.
    ------------------------------------------------
    with base as
    (
    Select date, cust_id, amount
    several tables
    Union of all the
    Select date, cust_id, amount
    several tables
    )

    Select * Basic
    where snapshot_date = July 31, 2014"
    -------------------------------------------------
    This query is too long. If I throw ' where snapshot_date = July 31, 2014 ' ' for both selects in the "-with clause", it's really fast. This is because all the tables in the db have indices on the field of snapshot_date.
    It seems that the with clause creates a view with all stereotypes, rather than just July 31, 2014. Y at - there a way to force the "-with clause" to retrieve data for only snapshot_date = July 31, 2014 ' as specified in the main query above without using where clause within the "with clause"?

    Thanks a lot to all the...

    As Gaff has suggested, I begin to believe that the WITH Clause is actually a temporary display based only on what is covered by the clause.

    Maybe it did and maybe it isn't. There is NO value to speculate unless you use this speculation to actually test your assumptions.

    In my case, there are 30 years of history.

    So why do you need to do a UNION ALL operation to get the results? Why can't simply run both queries separately?

    The optimizer does not resemble what data are used.

    More speculation on your part. I can create a simple example of the SCOTT schema on 11.2.0.1.0 vanilla that uses the index.

    create the table emp_copy1 in select * from emp;

    create the table emp_copy2 in select * from emp;

    create index emp_copy1_ndx on emp_copy1 (deptno);

    create index emp_copy2_ndx on emp_copy2 (deptno);

    explain plan for
    with base as
    (
    Select ename, empno and deptno from emp_copy1
    Union of all the
    Select ename, empno and deptno from emp_copy2
    )
    Select * base where deptno = 20;

    Select * from table (dbms_xplan.display_cursor ())

    PLAN_TABLE_OUTPUT

    SQL_ID, 77q19ypwbjkvq, number of children 0

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

    with base (select empno, ename, deptno emp_copy1 Union all the)

    Select empno, ename, deptno emp_copy2) select * base where

    DEPTNO = 20

    Hash value of plan: 2111487496

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

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |

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

    |   0 | SELECT STATEMENT |               |       |       |     4 (100) |          |

    |   1.  VIEW                         |               |    10.   330.     4 (0) | 00:00:01 |

    |   2.   UNION-ALL |               |       |       |            |          |

    |   3.    TABLE ACCESS BY INDEX ROWID | EMP_COPY1 |     5.   165.     2 (0) | 00:00:01 |

    |*  4 |     INDEX RANGE SCAN | EMP_COPY1_NDX |     5.       |     1 (0) | 00:00:01 |

    |   5.    TABLE ACCESS BY INDEX ROWID | EMP_COPY2 |     5.   165.     2 (0) | 00:00:01 |

    |*  6 |     INDEX RANGE SCAN | EMP_COPY2_NDX |     5.       |     1 (0) | 00:00:01 |

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

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

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

    4 - access ("DEPTNO" = 20)

    6 - access ("DEPTNO" = 20)

    Note

    -----

    -dynamic sample used for this survey (level = 2)

    Which show the index range scan is done for both tables. These statistics are current since Oracle collected his stats when the indexes have been built

    I think that there is no solution to this problem

    . No, unless indicate you at least a way for us to reproduce the problem.

  • Query to find data conneting that intersect each other.

    Hello

    I have a table like road_point_ids (script is below). Basically, this table have road_id with its start and its end point.

    I'm looking for a query that actually will connect each ID path beginning or end points.

    create the table road_point_ids

    (

    road_id number (10),

    start_point number (10),

    Number of end_point (10)

    );

    insert into road_point_ids

    values (1001, 10, 20);

    insert into road_point_ids

    values (1002, 20, 30);

    insert into road_point_ids

    values (1003, 30, 40);

    insert into road_point_ids

    values (1004, 40, 50);

    insert into road_point_ids

    values (1005, 50, 10);

    insert into road_point_ids

    values (1006, 70, 75);

    insert into road_point_ids

    values (1007, 30, 50);

    insert into road_point_ids

    values (1008, 10, 40);

    insert into road_point_ids

    values (1009, 80, 70);

    insert into road_point_ids

    values (1010, 90, 95);

    insert into road_point_ids

    values (1011, 50, 60);


    commit;

    SQL > select * from road_point_ids by 2;

    ROAD_ID START_POINT END_POINT

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

    1001               10                    20

    1008               10                    40

    1002               20                    30

    1007               30                    50

    1003               30                    40

    1004               40                    50

    1011               50                    60

    1005               50                    10

    1006               70                    75

    1009               80                    70

    1010               90                    95

    11 selected lines

    In the example above only seven road_ids intersect at TWO points corresponding to start or end point.

    Output desired must be as...

    ROAD_IDSTART_POINTEND_POINT
    10011020
    10022030
    10033040
    10044050
    10055010
    10073050
    10081040

    7 selected lines

    I tried to use a lot of operator AND with the OR operator but sent to an incorrect result. Could someone provide me please help.

    Thanks in advance

    Saaz

    Hi, Saaz,

    How is this problem differs from your original problem?

    If it's just that the data is now contained in 2 tables (a few lines in a table, a few lines in the other) instead of a table, you can change my original solution by using a UNION to combine the two tables into one:

    WITH road_point_ids AS

    (

    SELECT road_id, start_point, end_point OF road_point_ids_1 UNION ALL

    SELECT road_id, start_point, end_point FROM road_point_ids_2

    )

    SELECT DISTINCT road_id, start_point, end_point

    OF road_point_ids

    WHERE CONNECT_BY_ISCYCLE = 1

    CONNECT BY NOCYCLE start_point = PRIOR end_point

    ;

    The WITH clause is new; the main request is that I posted earlier.

  • Manual partitioning - with a check for pruning constraint

    I have a client who won't pay partitioning for real, but only Monster table on a data warehouse that must be broken into pieces for performance applications.

    What I want to do is manually partition table, create a union all join view which is located on top, then have oracle prune query plans for me to hit only the tables that I need to fill the result set.


    -Create table
    create the table a_tbl
    (
    col1 varchar2 (20).
    col2 varchar2 (20).
    COL3 varchar2 (20).
    COL4 varchar2 (20)
    )
    tablespace AAA_DATA;

    -Create/recreate check constraints
    ALTER table a_tbl
    Add constraint a_tbl_restrict
    check (col1 = 'aaa');

    create the table b_tbl
    (
    col1 varchar2 (20).
    col2 varchar2 (20).
    COL3 varchar2 (20).
    COL4 varchar2 (20)
    )
    tablespace AAA_DATA;

    -Create/recreate check constraints
    ALTER table b_tbl
    Add constraint b_tbl_restrict
    check (col1 = 'bbb');

    create the table c_tbl
    (
    col1 varchar2 (20).
    col2 varchar2 (20).
    COL3 varchar2 (20).
    COL4 varchar2 (20)
    )
    tablespace AAA_DATA;

    -Create/recreate check constraints
    ALTER table c_tbl
    Add constraint c_tbl_restrict
    check (col1 = 'ccc');

    ALTER table A_TBL
    Add primary key constraint a_tbl_pk (COL1, COL2)
    using index
    tablespace AAA_INDEX;

    ALTER table B_TBL
    Add primary key constraint b_tbl_pk (COL1, COL2)
    using index
    tablespace AAA_INDEX;

    ALTER table C_TBL
    Add primary key constraint c_tbl_pk (COL1, COL2)
    using index
    tablespace AAA_INDEX;

    Create view abc_v as
    Select * from a_tbl
    Union of all the
    Select * from b_tbl
    Union of all the
    Select * from c_tbl;

    When I run a query against the view that would eliminate two of the tables, I don't see the size that passes.

    Select * from abc_v

    where col1 = 'aaa' and col2 < '100'

    order by col2

    SELECT STATEMENT, GOAL = 3 1 48 ALL_ROWS

    SORT ORDER BY 3 1 48

    DISCOVERED A LOT OF 2-1-48 ABC_V

    UNION-ALL

    TABLE ACCESS BY INDEX ROWID BUNCH 4 2 96 A_TBL

    INDEX RANGE SCAN BUNCH 3 2 A_TBL_PK

    FILTER

    TABLE ACCESS BY INDEX ROWID HEAP 2 1 48 B_TBL

    INDEX RANGE SCAN HEAP 2 1 B_TBL_PK

    FILTER

    TABLE ACCESS BY INDEX ROWID HEAP 2 1 48 C_TBL

    INDEX RANGE SCAN HEAP 2 1 C_TBL_PK

    I do something that is not possible without partitioning "true"?  Or I put in place without a certain way?

    Thank you!

    Cory Aston

    Cory,

    the concept of the partition views is very old - among the best results in google, I get a link for the setting to version 7.3.3 guide: view of Partition Management - I didn't know that these pages still exist. 7.3 was released in 1996.

    Since then, Oracle has frequently said that views of partition are desupported - but they seem to work yet. If I use your example I get the following execution plan:

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

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |

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

    |   0 | SELECT STATEMENT |          |     1.    48.     1 (100) | 00:00:01 |

    |   1.  SORT ORDER BY |          |     1.    48.     1 (100) | 00:00:01 |

    |   2.   VIEW                          | ABC_V |     1.    48.     0 (0) | 00:00:01 |

    |   3.    UNION-ALL |          |       |       |            |          |

    |   4.     TABLE ACCESS BY INDEX ROWID | A_TBL |     1.    48.     1 (0) | 00:00:01 |

    |*  5 |      INDEX RANGE SCAN | A_TBL_PK |     1.       |     1 (0) | 00:00:01 |

    |*  6 |     FILTER |          |       |       |            |          |

    |   7.      TABLE ACCESS BY INDEX ROWID | B_TBL |     1.    48.     1 (0) | 00:00:01 |

    |*  8 |       INDEX RANGE SCAN | B_TBL_PK |     1.       |     1 (0) | 00:00:01 |

    |*  9 |     FILTER |          |       |       |            |          |

    |  10.      TABLE ACCESS BY INDEX ROWID | C_TBL |     1.    48.     1 (0) | 00:00:01 |

    | * 11 |       INDEX RANGE SCAN | C_TBL_PK |     1.       |     1 (0) | 00:00:01 |

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

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

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

    5 - access ("COL1" = 'aaa' AND "COL2"<>

    6 - filter (NULL IS NOT NULL)

    8 - access ("COL1" = 'aaa' AND "COL2"<>

    9 - filter (NULL IS NOT NULL)

    11 - access ("COL1" = 'aaa' AND "COL2"<>

    The most important part is (once again) the section predicate containing filter NULL IS NOT NULL predicates that should always evaluate to false. So I would say: works as advertised (once upon a time...)

    Concerning

    Martin

  • Digital signage using SYS_CONTEXT

    Version 11.2.0.3

    I'm trying to create a view that refers to two identical paintings. The results will be presented only ever among the tables based on a variable SYS_CONTEXT.

    The issue I see is however that the implementation plan is different when I use literals as opposed to a variable SYS_CONTEXT. The plan with literals is what I expect to see when I use SYS_CONTEXT as well. The difference between the 2 plans, is that the filter filter (NULL IS NOT NULL) appears for the SELECT that does not run. The following illustrates the problem:

    create table tbl1 (id number, date_created date);

    create table tbl2 (id number, date_created date);

    insert into tbl1 values (1, to_date('20140114','yyyymmdd'));

    insert into tbl2 values (2, to_date('20140115','yyyymmdd'));

    insert into tbl2 values (2, to_date('20140115','yyyymmdd'));

    COMMIT;

    create or replace context tbl_switch using set_tbl_context;

    create or replace procedure Set_Tbl_Context (p_Tbl_No in varchar2) as
    Start
    DBMS_SESSION.set_Context ('TBL_SWITCH', 'SWITCH_VALUE', p_Tbl_No);
    end Set_Tbl_Context;
    /

    SQL > exec set_tbl_context ('2');

    PL/SQL procedure successfully completed.

    SQL > select sys_context ('TBL_SWITCH', 'SWITCH_VALUE') FROM DUAL;

    SYS_CONTEXT ('TBL_SWITCH', 'SWITCH_VALUE')
    ----------------------------------------
    2

    SQL > set autotrace on
    SQL > select * from tbl1 where 1 = 2
    2 Union all the
    3 select * from tbl2 where 2 = 2
    4.

    ID DATE_CREA
    ---------- ---------
    2 15 JANUARY 14
    2 15 JANUARY 14


    Execution plan
    --------------
    Hash value of plan: 6123662

    ----------------------------------------------------------------------------
    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
    ----------------------------------------------------------------------------
    |   0 | SELECT STATEMENT |      |     3.    66.     3 (100) | 00:00:01 |
    |   1.  UNION-ALL |      |       |       |            |          |
    |*  2 |   FILTER |      |       |       |            |          |
    |   3.    TABLE ACCESS FULL | TBL1 |     1.    22.     3 (0) | 00:00:01 |
    |   4.   TABLE ACCESS FULL | TBL2 |     2.    44.     3 (0) | 00:00:01 |
    ----------------------------------------------------------------------------

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

    2 - filter (NULL IS NOT NULL)

    Note
    -----
    -dynamic sample used for this survey (level = 2)


    Statistics
    ----------
    16 recursive calls
    0 db block Gets
    Gets 36 compatible
    0 physical reads
    0 redo size
    436 bytes sent via SQL * Net to client
    364 bytes received via SQL * Net from client
    2 SQL * Net back and forth to and from the client
    0 sorts (memory)
    0 sorts (disk)
    2 rows processed

    SQL > select * from tbl1
    where the 2 ' 1'= sys_context('TBL_SWITCH','SWITCH_VALUE')
    3 Union all the
    4 Select * from tbl2
    where the 5 ' 2'= sys_context('TBL_SWITCH','SWITCH_VALUE')
    6.

    ID DATE_CREA
    ---------- ---------
    2 15 JANUARY 14
    2 15 JANUARY 14


    Execution plan
    --------------
    Hash value of plan: 687287648

    ----------------------------------------------------------------------------
    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
    ----------------------------------------------------------------------------
    |   0 | SELECT STATEMENT |      |     5:    66.     6 (50) | 00:00:01 |
    |   1.  UNION-ALL |      |       |       |            |          |
    |*  2 |   FILTER |      |       |       |            |          |
    |   5:    TABLE ACCESS FULL | TBL1 |     1.    22.     3 (0) | 00:00:01 |
    |*  4 |   FILTER |      |       |       |            |          |
    |   3:    TABLE ACCESS FULL | TBL2 |     2.    44.     3 (0) | 00:00:01 |
    ----------------------------------------------------------------------------

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

    2 - filter (SYS_CONTEXT ('TBL_SWITCH', 'SWITCH_VALUE') = '1')
    4 - filter (SYS_CONTEXT ('TBL_SWITCH', 'SWITCH_VALUE') = '2')

    Note
    -----
    -dynamic sample used for this survey (level = 2)


    Statistics
    ----------
    7 recursive calls
    0 db block Gets
    Gets 24 consistent
    0 physical reads
    0 redo size
    436 bytes sent via SQL * Net to client
    364 bytes received via SQL * Net from client
    2 SQL * Net back and forth to and from the client
    0 sorts (memory)
    0 sorts (disk)
    2 rows processed

    Can anyone suggest why this is? In addition, the query with the variable SYS_CONTEXT does not two SELECT?

    Thank you

    That's exactly the plan that you want to see (although I must say I don't like the strategy that you are adopting).

    If the sys_context value is 1 then line 2 will call line 3 to run, but line 4 will be short circuit and do not call the line 5

    If the sys_content value is 2, then line 1 will be short-circuit and not dial 3, but call line 4 line 5

    Update: your method is similar to an example I talked some time ago:conditional SQL & #8211; 3. Notebook of the Oracle and something similar is generated internally by the particularly specific optimizer transformation: conditional SQL | Notebook of the Oracle

    It would not have been too difficult to set up a small test to see if this was true.

    Concerning

    Jonathan Lewis

  • How to improve the performance of queries

    Hello everyone, this is the first time that I am responsible for investigating the performance of the queries.

    I have no permission to market the autotrace, so I just used the Plan to explain on the table on the development site.

    Here can someone tell me if there are obvious problems with the query below?

    This query is the basis for a single report. The amount of data on the Production site is about 25 times amount of data on the development site.

    User says that they must wait about 10 minutes for the report to load.

    Thank you very much in advance.

    Databases:

    Oracle 11 GR 1 matter (CARS)

    Application running the report is Apex Oracle version 4.0.2

    explain plan for

    Select vw. NPP, vw. PROFILE_NAME, vw. ADDRESS, vw. COMPETENCE, vw. ASSIGNED_CPO_ID,

    VW. STATUS_NAME, vw. DOMICILE_ID, vw. DOMICILE_NAME, vw. OVERPAYMENT_GROUP_ID, vw. CPO_NAME, vw. OCCURRENCES, Act. STATUS_CHANGE_DATE,

    (select name from opay_status where id = ACTION_ID) action_name,.

    ACTIONED_DATE, "CLOSED_BY,.

    (select name from OPAY_PAYMENT_SOURCE_TYPES where id = PAY_TYPE_ID) Payment_Source,

    VW. REVIEW_DATE

    ftrx.opay_overpayments_summary_vw vw, OPAY_OVERPAYMENT_ACTIONS Act

    where vw. OVERPAYMENT_GROUP_ID = Act.ID (+) and upper (Volkswagen. <>STATUS_NAME) "TRANSFORMED."

    and OPAY_PROCESSED_OVERPAYMENT (vw. OVERPAYMENT_GROUP_ID) = 'N'

    Union of all the

    Select RPC. NPP, CPP. PROFILE_NAME, CPP. ADDRESS, RPC. COMPETENCE, CPP. ASSIGNED_CPO_ID,

    CPP. STATUS_NAME, CPP. DOMICILE_ID, CPP. DOMICILE_NAME, CPP. OVERPAYMENT_GROUP_ID, CPP. ASSIGNED_CPO_NAME CPO_NAME, cpp.cycle_count OCCURRENCES, CPP. STATUS_CHANGE_DATE,

    CPP.action_name,

    CPP. ACTIONED_DATE, (select name of CPO where id = CPO_ID) CLOSED_BY,.

    CPP. Payment_Source,

    CPP. STATUS_CHANGE_DATE DUMMY_DATE

    the CPP OPAY_CPO_PROFILE_PROCESSED;

    /

    Select * from table (dbms_xplan.display);

    Hash value of plan: 3275359346

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

    | ID | Operation | Name                         | Lines | Bytes | TempSpc | Cost (% CPU). Time |

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

    |   0 | SELECT STATEMENT |                              |   260K |    65 M |       | 44949 (4) | 00:09:00 |

    |   1.  UNION-ALL |                              |       |       |       |            |          |

    |   2.   TABLE ACCESS BY INDEX ROWID | OPAY_STATUS |     1.    16.       |     1 (0) | 00:00:01 |

    |*  3 |    INDEX UNIQUE SCAN | OPAY_PK_STATUS |     1.       |       |     0 (0) | 00:00:01 |

    |   4.   TABLE ACCESS BY INDEX ROWID | OPAY_PAYMENT_SOURCE_TYPES |     1.    12.       |     1 (0) | 00:00:01 |

    |*  5 |    INDEX UNIQUE SCAN | OPAY_PK_SOURCE_TYPES |     1.       |       |     0 (0) | 00:00:01 |

    |*  6 |   EXTERNAL RIGHT HASH JOIN |                              |   197K |    86.       | 43459 (1) | 00:08:42 |

    |   7.    TABLE ACCESS FULL | OPAY_OVERPAYMENT_ACTIONS |  1224 | 29376 |       |   209 (0) | 00:00:03 |

    |   8.    VIEW                                | OPAY_OVERPAYMENTS_SUMMARY_VW |   197K |    51 M |       | 43249 (1) | 00:08:39 |

    |   9.     UNION-ALL |                              |       |       |       |            |          |

    | * 10 |      HASH JOIN |                              |     2.   570 |       | 17032 (1) | 00:03:25 |

    | * 11 |       VIEW                             |                              |     2.   560.       |  7456 (1) | 00:01:30 |

    |  12.        KIND OF WINDOW.                              |     2.   278.       |  7456 (1) | 00:01:30 |

    |  13.         NESTED EXTERNAL LOOPS |                              |     2.   278.       |  7455 (1) | 00:01:30 |

    |  14.          NESTED LOOPS |                              |     2.   242.       |  7453 (1) | 00:01:30 |

    | * 15 |           OUTER HASH JOIN |                              |     2.   214.       |  7451 (1) | 00:01:30 |

    |  16.            NESTED EXTERNAL LOOPS |                              |     2.   194.       |  7448 (1) | 00:01:30 |

    | * 17.             TABLE ACCESS FULL | OPAY_OVERPAYMENTS |     2.   168.       |  7447 (1) | 00:01:30 |

    |  18.             TABLE ACCESS BY INDEX ROWID | OPAY_OVERPAYMENT_ACTIONS |     1.    13.       |     1 (0) | 00:00:01 |

    | * 19.              INDEX UNIQUE SCAN | OPAY_PK_OVERPAY_ACTIONS |     1.       |       |     0 (0) | 00:00:01 |

    |  20.            TABLE ACCESS FULL | STATUS                       |     3.    30.       |     3 (0) | 00:00:01 |

    |  21.           TABLE ACCESS BY INDEX ROWID | HOME |     1.    14.       |     1 (0) | 00:00:01 |

    | * 22.            INDEX UNIQUE SCAN | PK_DOMICILE |     1.       |       |     0 (0) | 00:00:01 |

    |  23.          TABLE ACCESS BY INDEX ROWID | CPO                          |     1.    18.       |     1 (0) | 00:00:01 |

    | * 24.           INDEX UNIQUE SCAN | PK_CPO                       |     1.       |       |     0 (0) | 00:00:01 |

    |  25.       VIEW                             |                              |   197K |   963K |       |  9574 (1) | 00:01:55 |

    |  26.        HASH GROUP BY.                              |   197K |  7127K |  8544K |  9574 (1) | 00:01:55 |

    | * 27.         EXTERNAL RIGHT HASH JOIN |                              |   197K |  7127K |       |  7664 (1) | 00:01:32 |

    |  28.          TABLE ACCESS FULL | STATUS                       |     3.     9.       |     3 (0) | 00:00:01 |

    | * 29.          EXTERNAL RIGHT HASH JOIN |                              |   197K |  6549K |       |  7660 (1) | 00:01:32 |

    |  30.           TABLE ACCESS FULL | OPAY_OVERPAYMENT_ACTIONS |  1224 | 11016.       |   209 (0) | 00:00:03 |

    | * 31.           HASH JOIN |                              |   197K |  4816K |       |  7449 (1) | 00:01:30 |

    |  32.            INDEX SCAN FULL | PK_DOMICILE |    73.   292.       |     1 (0) | 00:00:01 |

    |  33.            TABLE ACCESS FULL | OPAY_OVERPAYMENTS |   197K |  4045K |       |  7446 (1) | 00:01:30 |

    | * 34 |      HASH JOIN |                              |   197K |    53 M |  3280K | 26217 (1) | 00:05:15 |

    |  35.       VIEW                             |                              |   197K |   963K |       |  9574 (1) | 00:01:55 |

    |  36.        HASH GROUP BY.                              |   197K |  7127K |  8544K |  9574 (1) | 00:01:55 |

    | * 37 |         EXTERNAL RIGHT HASH JOIN |                              |   197K |  7127K |       |  7664 (1) | 00:01:32 |

    |  38.          TABLE ACCESS FULL | STATUS                       |     3.     9.       |     3 (0) | 00:00:01 |

    | * 39 |          EXTERNAL RIGHT HASH JOIN |                              |   197K |  6549K |       |  7660 (1) | 00:01:32 |

    |  40.           TABLE ACCESS FULL | OPAY_OVERPAYMENT_ACTIONS |  1224 | 11016.       |   209 (0) | 00:00:03 |

    | * 41.           HASH JOIN |                              |   197K |  4816K |       |  7449 (1) | 00:01:30 |

    |  42.            INDEX SCAN FULL | PK_DOMICILE |    73.   292.       |     1 (0) | 00:00:01 |

    |  43.            TABLE ACCESS FULL | OPAY_OVERPAYMENTS |   197K |  4045K |       |  7446 (1) | 00:01:30 |

    | * 44 |       VIEW                             |                              |   197K |    52 M |       | 13757 (1) | 00:02:46 |

    |  45.        KIND OF WINDOW.                              |   197K |    26 M |    28 M | 13757 (1) | 00:02:46 |

    | * 46 |         EXTERNAL RIGHT HASH JOIN |                              |   197K |    26 M |       |  7673 (1) | 00:01:33 |

    |  47.          TABLE ACCESS FULL | CPO                          |    91.  1638.       |     4 (0) | 00:00:01 |

    | * 48 |          EXTERNAL RIGHT HASH JOIN |                              |   197K |    22 M |       |  7667 (1) | 00:01:33 |

    |  49.           TABLE ACCESS FULL | STATUS                       |     3.    30.       |     3 (0) | 00:00:01 |

    | * 50 |           EXTERNAL RIGHT HASH JOIN |                              |   197K |    20 M |       |  7663 (1) | 00:01:32 |

    |  51.            TABLE ACCESS FULL | OPAY_OVERPAYMENT_ACTIONS |  1224 | 15912 |       |   209 (0) | 00:00:03 |

    | * 52 |            HASH JOIN |                              |   197K |    18 M |       |  7452 (1) | 00:01:30 |

    |  53.             TABLE ACCESS FULL | HOME |    73.  1022 |       |     3 (0) | 00:00:01 |

    | * 54 |             TABLE ACCESS FULL | OPAY_OVERPAYMENTS |   197K |    15 M |       |  7448 (1) | 00:01:30 |

    |  55.   TABLE ACCESS BY INDEX ROWID | CPO                          |     1.    18.       |     1 (0) | 00:00:01 |

    | * 56 |    INDEX UNIQUE SCAN | PK_CPO                       |     1.       |       |     0 (0) | 00:00:01 |

    |  57.   TABLE ACCESS FULL | OPAY_CPO_PROFILE_PROCESSED | 63108 |  9429K |       |  1490 (1) | 00:00:18 |

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

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

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

    3 - access("ID"=:B1)

    5 - access("ID"=:B1)

    6 - access("VW".") OVERPAYMENT_GROUP_ID "=" LAW ". "ID" (+)) "

    10 - access("A".") WITH THE ID '=' B '. (' ' ID ')

    11 filter (SUPERIOR ("a.") "<>STATUS_NAME"), "TRANSFORMED" AND "OPAY_PROCESSED_OVERPAYMENT"("A"."" OVERPAYMENT_GROUP_ID') = 'N')

    15 - access("STS".") ID "(+) = TO_NUMBER ("ACT"". ")" STATUS'))

    17 - filter("OPAY".") (OVERPAYMENT_GROUP_ID"IS NULL)

    19 - access("OPAY".") OVERPAYMENT_GROUP_ID "=" LAW ". "ID" (+)) "

    22 - access("OPAY".") DOMICILE_ID "=" DOM ". (' ' ID ')

    24 - access("ACT".") ASSIGNED_CPO_ID "=" DPC ". "ID" (+)) "

    27 - access("STS".") ID "(+) = TO_NUMBER ("ACT"". ")" STATUS'))

    29 - access("OPAY".") OVERPAYMENT_GROUP_ID "=" LAW ". "ID" (+)) "

    31 - access("OPAY".") DOMICILE_ID "=" DOM ". (' ' ID ')

    34 - access("A".") WITH THE ID '=' B '. (' ' ID ')

    37 - access("STS".") ID "(+) = TO_NUMBER ("ACT"". ")" STATUS'))

    39 - access("OPAY".") OVERPAYMENT_GROUP_ID "=" LAW ". "ID" (+)) "

    41 - access("OPAY".") DOMICILE_ID "=" DOM ". (' ' ID ')

    44 filter (SUPERIOR ("a.") "<>STATUS_NAME"), "TRANSFORMED" AND "OPAY_PROCESSED_OVERPAYMENT"("A"."" OVERPAYMENT_GROUP_ID') = 'N')

    46 - access("ACT".") ASSIGNED_CPO_ID "=" DPC ". "ID" (+)) "

    48 - access("STS".") ID "(+) = TO_NUMBER ("ACT"". ")" STATUS'))

    50 - access("OPAY".") OVERPAYMENT_GROUP_ID "=" LAW ". "ID" (+)) "

    52 - access("OPAY".") DOMICILE_ID "=" DOM ". (' ' ID ')

    54 - filter("OPAY".") OVERPAYMENT_GROUP_ID' IS NOT NULL)

    56 - access("ID"=:B1)

    - And this is the content of the function used in the query

    create or replace

    FUNCTION "opay_PROCESSED_OVERPAYMENT" (NUMBER p_opay_group_id) RETURN varchar AS

    fake number;

    result varchar (1);

    BEGIN

    If p_opay_group_id is null returns 'n';

    on the other

    SELECT count (distinct is_processed_yn) in a model of opay_overpayments where overpayment_group_id = p_opay_group_id;

    If dummy <>1 then back 'n';

    On the other

    Select distinct is_processed_yn as a result of opay_overpayments where overpayment_group_id = p_opay_group_id;

    return the result;

    end if;

    end if;

    END;

    - And here are the details of the view.

    CREATE OR REPLACE VIEW 'OPAY_OVERPAYMENTS_SUMMARY_VW '.

    As

    Select one. «' REVIEW_DATE ', a. "ID", a. "NPP", a. "PROFILE_NAME «, a» ADDRESS", a. "COMPETENCE", a"ASSIGNED_CPO_ID", a. "STATUS_NAME", a. "DOMICILE_ID", a. "DOMICILE_NAME", a. "OVERPAYMENT_GROUP_ID", a. "CPO_NAME", a. "OCCURRENCES»

    (select review_date, id, NPP, profile_name, address

    domicile_name, status_name, assigned_cpo_id, competence

    overpayment_group_id, cpo_name

    , count (NPP) over (PARTITION BY ppn) AS OCCURRENCES

    (SELECT review_date, id, NPP, profile_name, address, assigned_cpo_id

    status_name, domicile_id, domicile_name

    overpayment_group_id, cpo_name

    OF ftrx.opay_overpayments_vw

    where overpayment_group_id is null)) a

    Join (select max (id) id, overpayment_group_id, NPP group opay_overpayments_vw by overpayment_group_id, ppn) b

    on all the a.id = b.id union

    Select one. "' REVIEW_DATE ', a." ID ", a." NPP ", a." PROFILE_NAME «, a» ADDRESS ", a." COMPETENCE ", a" ASSIGNED_CPO_ID ", a." STATUS_NAME ", a." DOMICILE_ID ", a." DOMICILE_NAME ", a." OVERPAYMENT_GROUP_ID ", a." CPO_NAME ", a." OCCURRENCES "(select review_date, id, NPP

    profile_name

    address

    skill

    assigned_cpo_id

    status_name

    domicile_id

    domicile_name

    overpayment_group_id

    cpo_name

    , count (overpayment_group_id) over (PARTITION BY overpayment_group_id) AS OCCURRENCES

    (SELECT review_date, id, NPP

    profile_name

    address

    skill

    assigned_cpo_id

    status_name

    domicile_id

    domicile_name

    overpayment_group_id

    cpo_name

    OF ftrx.opay_overpayments_vw

    where overpayment_group_id is not null)) a

    Join (select max (id) id, overpayment_group_id, NPP group opay_overpayments_vw by overpayment_group_id, ppn) b

    on a.id = b.id

    Let me know if my explanation is not clear enough.

    Thanks for reading.

    I thought that the function can be part of the problem. He called lots and made several requests by rank. Calls to PL/SQL in SQL a) require a context switch in the execution of the query (from SQL, PL/SQL) and (b) are completely opaque to the optimizer - it can not re - write to be faster than the procedure one call at a time. Instead of trying to re - write that it is faster, try to write it out of the query completely by turning it into a piece of SQL in the container view.

    Assuming that opay_overpayments.is_processed_yn is OPAY_PROCESSED_OVERPAYMENT(vw., changement ou «N», «Y» OVERPAYMENT_GROUP_ID) = 'N'

    in

    AND (vw. OVERPAYMENT_GROUP_ID or vw. OVERPAYMENT_GROUP_ID in

    (select OVERPAYMENT_GROUP_ID in the opay_overpayments where is_processed_yn = ' n and OVERPAYMENT_GROUP_ID is not null)

    )

    Having done this, you can probably also turn the query into an outer join between vw, the OPAY_OVERPAYMENT_ACTIONS Act ftrx.opay_overpayments_summary_vw and (select OVERPAYMENT_GROUP_ID in the opay_overpayments where is_processed_yn = ' only and OVERPAYMENT_GROUP_ID is not null) if the optimizer which has not already done so. That would minimize the amount of querying.

  • NOT IN and ANTI JOIN

    Hello guys,.

    with the example I want to insert the new translation into a table of conversion below, but
    the NOT IN clause does not work. I also tried an ANTI-JOINTURE after reading some
    why NOT IN may not work but the ANTI-JOINTURE did not work either.
    The result of the query above is 0 rows inserted. There are about 1000 lines that already exist and I want to avoid
    insertion of those, once again. Note that the text is not even the ID or the SOURCE.

    INSERT INTO T_Translations
    (
    SELECT ID, SOURCE, TEXT, OF
    (
    SELECT distinct ID, SOURCE, DOMAIN,
    TransText AS TEXT
    DE)

    -Deutsche text aus TKZ_1
    SELECT TransText OF
    -... - Source table 1
    UNION ALL
    -... - Source table 2
    UNION ALL
    -... - Source table 3
    UNION ALL
    -... - Source table 4

    ) WHERE TransText IS NOT NULL
    )

    WHEN NOT IN TEXT (SELECT TEXT FROM T_Translations)
    );

    Any suggestions?

    Thank you very much.

    It might be a problem with the alias.

    The TEXT column can come from many different parts of your query. I changed it a bit and removed unnecessary inline views.

    INSERT INTO T_Translations i
      SELECT distinct v.ID, v.SOURCE, v.DOMAIN, v.TransText
      FROM (
                  --Deutsche Texte aus TKZ_1
                  SELECT TransText FROM
                  --...--Source Table 1
                  UNION ALL
                  --...--Source Table 2
                  UNION ALL
                  --...--Source Table 3
                  UNION ALL
                  --...--Source Table 4
                  ) v
       WHERE v.TransText IS NOT NULL
       AND not exists (SELECT null FROM T_Translations t2 where v.TransText = t2.TEXT )
      ;
    
  • Character of sql, simple sorting

    Hello

    I have three SQLS which I'm running with 'Union '.

    for example

    Select col1, count (*) in the table where type = 'pieces '.
    Group of col1
    Union
    Select col1, count (*) in the table where type = "consumables".
    Group of col1
    Union
    Select 'Total', count (*) table
    Group by 'Total '.

    I want to force the total column or the last row to select it and the column of pieces to always be the first line. Any suggestions? I tried something like prefixing the col1 with an alphabet. But that appears in the output also. Was looking for a better way!

    Thank you
    Sun

    Select col1, cnt,
    from (select 1 order2, col1, count (*) NTC table where type = 'parts')
    Group of col1
    Union
    Select 2, col1, count (*) from table where type = "consumables".
    Group of col1
    Union
    Select 3, 'Total', count (*) table
    control group by 'Total') by order2.

Maybe you are looking for