with the clause with union all?

Hello

I tried to use 'by' article with union all. .but it gives me error...
   with t1 as 
        (select '1'col1 from dual union all
         select '2' col2 from dual)select * from t1
         union 
        with t2 as 
        (select '3' col1 from dual union all
         select '4' col1 from dual )
          select * from t2
            
What harm am I doing here? Thank you very much!!

Use the WITH clause, once for you all the subqueries, and then add the main request;

with t1 as
 (select '1' col1
  from dual
  union all
  select '2' col2
  from dual),
t2 as
 (select '3' col1
  from dual
  union all
  select '4' col1
  from dual)
select *
from t1
union
select *
from t2;

Tags: Database

Similar Questions

  • get the result without Union all the

    < pre >
    WITH GET_BALANCE AS
    (SELECT "CREDIT2' AS TYPE, - 6336.37 AS A AMOUNT OF DOUBLE
    Union of all the
    SELECT 'CREDIT', 8340.52 OF THE DOUBLE
    Union of all the
    SELECT 'CREDIT', THE DOUBLE 609.48
    Union of all the
    SELECT 'CREDIT', 50 OF THE DOUBLE
    Union of all the
    SELECT 'CREDIT', 6336.37 OF THE DOUBLE
    Union of all the
    Select "DEBIT", 628.68 DUAL FROM
    Union of all the
    Select "DEBITORG", 9000 DUAL FROM
    Union of all the
    SELECT 'DEBIT1', DOUBLE 50,81
    Union of all the
    SELECT 'DEBIT2',-679.49 OF THE DOUBLE
    UNION ALL
    SELECT 'DEBIT1', THE DOUBLE 679.49
    UNION ALL
    SELECT 'DEBIT2',-679.49 OF THE DOUBLE
    )

    SELECT sum (debit) debit, sum (credit) in the form of credit, (sum (debit) - sum (credit)) such as (FROM) balance
    SELECT FLAT CREDIT, DEBIT GET_BALANCE 0
    WHERE TO TYPE LIKE 'CREDIT %'
    UNION ALL
    SELECT 0 CREDIT, DEBIT GET_BALANCE PLATE
    WHERE TO TYPE LIKE' FLOW %')

    I got the result;
    credit debit balance
    9000 9000 0
    < / pre >
    But,
    I want to get the result without union all.
    I try sum on the partition by, or group by type...
    can not get the result. you would tell me the other way to get above result

    Thank you

    Published by: Jimmie_M on October 4, 2010 14:59

    Published by: Jimmie_M on October 4, 2010 15:01

    Hello

    Here's one way:

    WITH   got_credit_and_debit     AS
    (
         SELECT     SUM ( CASE
                     WHEN  SUBSTR (type, 1, 6) = 'CREDIT'
                         THEN  amount
                    END
                  )     AS credit
         ,     SUM ( CASE
                        WHEN  SUBSTR (type, 1, 5) = 'DEBIT'
                         THEN  amount
                    END
                  )     AS debit
         FROM    get_balance
    )
    SELECT     credit
    ,     debit
    ,     debit - credit     AS balance
    FROM     got_credit_and_debit
    ;
    

    What type of application is as follows, where the balance is defined as the debit - credit? Usually, it's the opposite: balance = credit - debit.

    You don't absolutely need a subquery:

    SELECT     SUM ( CASE
                WHEN  SUBSTR (type, 1, 6) = 'CREDIT'
                    THEN  amount
               END
             )     AS credit
    ,     SUM ( CASE
                   WHEN  SUBSTR (type, 1, 5) = 'DEBIT'
                    THEN  amount
               END
             )     AS debit
    ,     SUM ( CASE
                WHEN  SUBSTR (type, 1, 6) = 'CREDIT'
                THEN  amount
                   WHEN  SUBSTR (type, 1, 5) = 'DEBIT'
                    THEN  -amount
               END
             )     AS balance
    FROM    get_balance
    

    Published by: Frank Kulash, October 4, 2010 18:15
    Added query replacing without subquery

  • Problem with Union All

    Hello Experts,

    I'm still on the learning curve in PL/SQL and I have 2 different. I need to create a view that will merge these 2 tables.
    create view eft_view as
    select 
      BILL_TO_RETAILER      ,
      RETAILER_NAME         ,
      NAME_ON_BANK_ACCOUNT  ,
      BANK_ABA              ,
      BANK_ACCT             ,
      ON_LINE_AMOUNT        ,
      INSTANT_AMOUNT        ,
      TOTAL_AMOUNT          ,
      SOURCE                ,
      INSERTED_DATE         ,
      CDC                   from weekly_eft_temp union all
    select 
      BILL_TO_RETAILER  ,
      RETAILER_NAME     ,
      STATUS            ,
      ON_LINE_AMOUNT    ,
      INSTANT_AMOUNT    ,
      NON_SWEPT_AMT     ,
      TTYPE             ,
      EXCEPTION_REASON   from weekly_bill_expt_temp;
    I used the union of all, but it doesn't seem to work. I don't know where it's track. I searched on the net but his send me examples for 2 tables tat are similar.

    Any suggestions please

    You must replicate the columns that do not exist fill them with NULL values.

    Perhaps;

    create view eft_view as
      select bill_to_retailer,
             retailer_name,
             name_on_bank_account,
             bank_aba,
             bank_acct,
             null status,
             on_line_amount,
             instant_amount,
             total_amount,
             source,
             inserted_date,
             cdc,
             cast (null as number) non_swept_amt,
             null ttype,
             null exception_reason
        from weekly_eft_temp
      union all
      select bill_to_retailer,
             retailer_name,
             null name_on_bank_account,
             null bank_aba,
             null bank_acct,
             status,
             on_line_amount,
             instant_amount,
             null total_amount,
             null source,
             null inserted_date,
             nul cdc,
             non_swept_amt,
             ttype,
             exception_reason
        from weekly_bill_expt_temp;
    
  • show all columns with union all

    Hi all
    select m_id, total, cat_id
    from scott.maintenance
    where prod_id = 1
    union all
    select m_id, total, prod_id
    from scott.maintenance
    where prod_id = 4
    How can I view all (and not common) columns of the two tables when I use union all like
    m_Id, total, cat_id, prod_id

    Thank you
    Johnny

    Hi, Johnny,.

    user9542267 wrote:
    Hi all

    select m_id, total, cat_id
    from scott.maintenance
    where prod_id = 1
    union all
    select m_id, total, prod_id
    from scott.maintenance
    where prod_id = 4
    

    How can I view all (and not common) columns of the two tables when I use union all like
    m_Id, total, cat_id, prod_id

    Thank you
    Johnny

    There is no need to make a trade UNION for this:

    SELECT  *
    FROM    scott.maintenance
    WHERE   prod_id IN (1, 4)
    ;
    

    If you really need to do a UNION and basic tables were the same or had the same number and types of columns, then you can use SELECT * in the two branches of the UNION:

    SELECT  *
    FROM    scott.maintenance
        --
    UNION ALL
        --
    SELECT  *
    FROM    foo.maintenance
    ;
    

    If the columns have different names in the two tables, the names of the first branch of the UNION will be used in the output.

    In all cases, you can add literal NULL values to the SELECT one or more branches of the UNION clause:

    SELECT  ename     AS name
    ,       hiredate
    ,       deptno
    FROM    scott.emp
        --
    UNION ALL
        --
    SELECT  dname     AS name        -- alias not necessary, but helpful
    ,       NULL      AS hiredate    -- alias not necessary, but helpful
    ,       deptno
    FROM    scott.dept
    ;
    

    Depending on your tables and your requirements of yor, you might be able to use SELECT * in a branch of the UNION.

    Published by: Frank Kulash, February 15, 2011 12:29

  • Adding columns with union all?

    --------------------------------------------------------------------------------------------------------
    SELECT BAGLANTIDATE, CABONE
    FROM SEDEF_BILGI
    WHERE CABONE = '1' AND
    BAGLANTIDATE BETWEEN TO_DATE('10-JUN-2009','DD,MON-YYYY')
    AND TO_DATE('11-JUN-2009','DD-MON-YYYY')
    
    UNION ALL
    
    SELECT KAYITDATE, ABONE
    FROM SEDEF_ISEMRI
    WHERE ABONE = '1' AND
    KAYITDATE BETWEEN TO_DATE('10-JUN-2009','DD,MON-YYYY')
    AND TO_DATE('11-JUN-2009','DD-MON-YYYY')
    ------------------------------------------------------------------------------------------------------------
    
    BAGLANTITARIH        ABONE
    ------------------------      ----------------
    10-JUN-09 03.01.52.546000000 AM 1          
    10-JUN-09 05.02.06.453000000 PM 1          
    10-JUN-09 01.01.20.421000000 PM 1          
    10-JUN-09 07.01.42.062000000 AM 1          
    10-JUN-09 09.44.59.515000000 AM 1          
    10-JUN-09 09.58.07.843000000 AM 1          
    10-JUN-09 09.01.50.546000000 PM 1    
    10-JUN-09 09.52.57.796000000 AM 1
    10-JUN-09 02.13.32.343000000 PM 1
    
    9 rows selected
    How can I add a column in the tables on that?

    Published by: niennamiriel on August 18, 2009 12:12 AM

    Yes it is possible.

    SELECT BAGLANTIDATE, CABONE, MSISDN
      FROM SEDEF_BILGI
      ...
    UNION ALL
    SELECT KAYITDATE, ABONE, null
      FROM SEDEF_ISEMRI
    
  • How to use the clause type conditionally create new lines

    This question is just for learning - no object other than to start real world to create versions of some queries known to learn how to measure the performance of the MODEL clause clause of the MODEL versions.

    The question is: How can you write a STANDARD clause that pivots (updates) ONLY the lines that actually need to rotate and do NOT change the lines that have no value and cannot be rotated.

    I found a good site that has about two dozen example articles on different pieces. This first link is the beginning of the series.

    SQL features tutorials - Clause TYPE

    http://www.sqlsnippets.com/en/topic-11663.html

    This link is to a clause of FAQ of BluShadow MODEL version "how to convert rows to columns."

    Line - MODEL method string

    http://www.sqlsnippets.com/en/topic-11987.html

    The solution to this link uses this line of source:

    POSITION KEY VAL

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

    R08 0 v1, v2, v3,.

    and this result set:

    POSITION KEY VAL

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

    R08 1 v1

    R08 2 v2

    R08 3 v3

    The reason why it produces that result set is this clause of the statement of MODEL

    RETURN THE UPDATED LINES

    If you comment on this article, you will see that the original lines are all in position 0. This means that the solution reproduced EACH SOURCE LINE even if there is only one item in the list of values.

    Thus, even a line source with a single value (for example, the r01 'a') will be updated and updated this line is returned.

    For a large number of data sources with only a few lines that actually need to rotate it would be a great performance of infringement.

    This is the sample data source

    with t as (button 1, 'a' value 'abc' col2, col3 'def' of the double
    Select Union all 2, 'b', 'ghi', 'jkl' from dual
    Union all select 3, 'c, d, e, 'mno', 'pqr' from dual.
    Union all select 4, 'f', 'stu', 'vwx' from dual
    )
    Select the key, value, col2, col3
    t

    KEY, VALUE, COL2, COL3
    1, a, abc, def
    2, b, GHI, jkl
    3, "c, d, e, mno, pqr.
    4, f, stu, vwx

    Lines 1, 2 and 4 only have a value of (a, b, c respectively.

    Only line 3 must rotate. It contains "c, d, e" and which must become 3 lines in the result set

    Value of the key, col2 col3
    1 an abc def
    2B ghi jkl
    3 c mno, pqr
    3 d mno, pqr
    3 e mno, pqr
    4 f stu vwx

    The nut of the problem is that if the clause 'RETURN UPDATED ROWS' is used, then the lines 1, 2 and 4 must be updated in order to be returned in the result set. And if this clause is NOT used, then line 3 must be updated by 'c', d, e 'c' and two new product lines: one line for a ' and one for 'e '.

    How can you do this with the TYPE clause without the help of the clause "Return LINES UPDATE"? I don't have a solution to sample showing what I tried because I can't understand what it takes to even try.

    I have a solution that uses "RETURN UPDATED ROWS" but I want to compare this performance to the exercise, when this clause is NOT used.

    We ask BluShadow to add the solution of MODEL clause to this FAQ with other similar solutions.

    Like this?

    SQL > with t as
    () 2
    3 select the 1 key, 'a' val, 'abc' col2, col3 'def' of the double


    Select 4 Union all 2, 'b', 'ghi', 'jkl' from dual
    5 union all select 3, 'c, d, e, 'mno', 'pqr' from dual.
    Select 6 Union all the 4 'f', 'stu', 'vwx' from dual
    7)
    8. Select the key
    9, key_1
    10, val
    11, regexp_substr (val, ' [^,] +', 1, key_1) val_new
    12, col2
    13, col3
    14 t
    model 15
    16 partition by (key)
    dimension (1 key_1) 17
    18 measures (val, col2, col3, (length (val) - length (replace (val, ",")) + 1) as len)
    19 rules
    (20)
    21 val [for 1 to increment of len key_1 [1] 1] = val [1]
    22, col2 [for 1 to increment of len key_1 [1] 1] = col2 [1]
    23, col3 [for 1 to increment of len key_1 [1] 1] = col3 [1]
    24)
    25 order
    26 by key
    27, key_1;

    KEY KEY_1 VAL VAL_N NECK NECK
    ---------- ---------- ----- ----- --- ---
    1 1 has an abc def
    2 b 1 b ghi jkl
    3 1 c, d, e c mno pqr
    3 2 c, d, e d mno pqr
    3 3 c, d, e e mno pqr
    4 1 f f stu vwx

    6 selected lines.

  • Question of the effectiveness of UNION

    Explain the plan on a union involving several selects a single table means the table is read only once for each selection. But is this actually happens? Are there tips to control this? Conceptually the table could be read only once, and each line is read that it could be provided with each selection, 'feed' the data for each selection as a set of pipelines. This is perhaps what is happening behind the scenes, but I don't know how to check or control that is relevant to me because the table involved is very large, but a union of several chooses is easier to write and maintain.

    This example shows two queries that provide the same result to illustrate what I mean. The table can be read once by using a single select that switches on the data. But the logic to pass values like this can get ugly pretty quick. A query of the unions allows each to be as simple as possible, but it seems to force the table to be read several times. Suggestions on how to optimize a popular union.

    This is Oracle Database 10 g Enterprise Edition Release 10.2.0.4.0.

    create table t1 (val1 val2 val3 number, number, type);

    insert into t1 (1, 21, 31, 1) values;
    insert into t1 (2, 22, 32, 1) values;
    insert into t1 (3, 23, 33, 1) values;
    insert into t1 (4, 24, 34, 2) values;
    insert into t1 (25, 35, 5, 2) values;
    insert into t1 (6, 26, 36, 2) values;
    insert into t1 (27, 37, 7, 3) values;
    insert into t1 (8, 28, 38, 3) values;
    insert into t1 (9, 29, 39, 3) values;

    explain plan for
    -a single query, logical ugly
    Select
    type deal when 1 then val1
    When 2 then val2
    When 3 then val3
    end
    COL1
    from t1;

    explain plan for
    -simple logic, but three queries
    Select val1 from t1 where type = 1 union of all the
    Select val2 from t1 where type = 2 union of all the
    Select val3 t1 where type = 3;

    user13027026 wrote:
    Explain the plan on a union involving several selects a single table means the table is read only once for each selection. But is this actually happens? Are there tips to control this? Conceptually the table could be read only once, and each line is read that it could be provided with each selection, 'feed' the data for each selection as a set of pipelines. This is perhaps what is happening behind the scenes, but I don't know how to check or control that is relevant to me because the table involved is very large, but a union of several chooses is easier to write and maintain.

    This example shows two queries that provide the same result to illustrate what I mean. The table can be read once by using a single select that switches on the data. But the logic to pass values like this can get ugly pretty quick. A query of the unions allows each to be as simple as possible, but it seems to force the table to be read several times. Suggestions on how to optimize a popular union.

    This is Oracle Database 10 g Enterprise Edition Release 10.2.0.4.0.

    create table t1 (val1 val2 val3 number, number, type);

    insert into t1 (1, 21, 31, 1) values;
    insert into t1 (2, 22, 32, 1) values;
    insert into t1 (3, 23, 33, 1) values;
    insert into t1 (4, 24, 34, 2) values;
    insert into t1 (25, 35, 5, 2) values;
    insert into t1 (6, 26, 36, 2) values;
    insert into t1 (27, 37, 7, 3) values;
    insert into t1 (8, 28, 38, 3) values;
    insert into t1 (9, 29, 39, 3) values;

    explain plan for
    -a single query, logical ugly
    Select
    type deal when 1 then val1
    When 2 then val2
    When 3 then val3
    end
    COL1
    from t1;

    explain plan for
    -simple logic, but three queries
    Select val1 from t1 where type = 1 union of all the
    Select val2 from t1 where type = 2 union of all the
    Select val3 t1 where type = 3;

    Well, the questions on the UNION, but your example has UNION ALL (they are not equivalent).

    In the latest version of the basis of the answer (for UNION ALL) is Yes using factorization of join.

    http://blogs.Oracle.com/optimizer/entry/optimizer_transformations_join_factorization

    That be answered, they technically correct answer would be to fix the data model. Having COL_1, COL_2, COL_X... usually reflects a design flaw.

  • With the clause of DML (DEC/insert/insert-all)

    Hello


    I have tables t1, t2, t3, t4

    with w
    (
    Select t1.* from t1, t2
    where t1.c1 = t2.c1
    and t1.c2 = t2.c2
    )


    I need to create or insert data in new tables n1 and n2
    Like this..

    Insert into n1
    Select * from w, t3
    where w.c1 = t3.c1

    Insert into n2
    Select * from w, t4
    where w.c2 = t4.c2
    ----

    I will make references the object 'w' several times.
    My concern is because the inserts above are run independently in the same session, the oracle executes the
    with the clause for each reference or runs one time?

    Essentially of iam looking for an insert-all statement
    where it inserts data into multiple tables from target
    something like that...


    Insert into n1
    When
    Select * from w, t3
    where w.c1 = t3.c1
    Insert into n2
    When
    Select * from w, t4
    where w.c1 = t4.c1
    with w
    (
    Select t1.* from t1, t2
    where t1.c1 = t2.c1
    and t1.c2 = t2.c2
    )

    ----
    Usually, I'm doing my basic work before posting on oracle forums, currently iam unable to connect to one
    Oracle sessions. Can someone help me?


    Thanks in advance.

    If your application will have the same number and type of columns, then you can do something like that.

    SQL> create table t1
      2  as
      3  select level no, 'karthick' name
      4    from dual
      5  connect by level <= 5
      6  /
    
    Table created.
    
    SQL> create table t2
      2  as
      3  select no, 'vimal' name
      4    from t1
      5  /
    
    Table created.
    
    SQL> create table t3
      2  as
      3  select no, 'vijay' name
      4    from t1
      5  /
    
    Table created.
    
    SQL> create table t4
      2  as
      3  select no, 'subha' name
      4    from t1
      5  /
    
    Table created.
    
    SQL> create table n1
      2  as
      3  select * from t1 where 1=2
      4  /
    
    Table created.
    
    SQL> create table n2
      2  as
      3  select * from t1 where 1=2
      4  /
    
    Table created.
    
    SQL> insert when view_name = 'v1' then
      2             into n1 values (no, name)
      3         when view_name = 'v2' then
      4                     into n2 values (no, name)
      5  with v
      6  as
      7  (
      8     select t1.*
      9       from t1, t2
     10      where t1.no = t2.no
     11  ),
     12  v1
     13  as
     14  (  select t3.*, 'v1' view_name
     15       from v, t3
     16      where v.no = t3.no
     17  ),
     18  v2
     19  as
     20  (  select t4.*, 'v2' view_name
     21       from v, t4
     22      where v.no = t4.no
     23  )
     24  select * from v1
     25  union all
     26  select * from v2
     27  /
    
    10 rows created.
    
    SQL> select * from n1
      2  /
    
            NO NAME
    ---------- --------
             1 vijay
             2 vijay
             3 vijay
             4 vijay
             5 vijay
    
    SQL> select * from n2
      2  /
    
            NO NAME
    ---------- --------
             1 subha
             2 subha
             3 subha
             4 subha
             5 subha
    
  • Trying to create the table using Clause any Union with Select multiple stmts

    The motion seeks to get the substring of the value to for example.
    If the value is * ASA 2 * then so do ASA
    where as if the value is * 1.5 TST * it sholud come as TST as wise for others too.
    I am trying to execute stmt SQL written but in error as below:

    * ' ORA-00998 must appoint this expression with the alias column 00998.00000 - must appoint this expression with the column alias. "

    CREATE TABLE TEST_CARE AS
    (
    SELECT row_id, old_care_lvl, SUBSTR(old_care_lvl,3), len test_care_lvl FROM
    WHERE LENGTH (old_care_lvl) = 5
    UNION ALL
    SELECT row_id, old_care_lvl, SUBSTR(old_care_lvl,3), len test_care_lvl FROM
    WHERE LENGTH (old_care_lvl) = 7
    UNION ALL
    SELECT row_id, old_care_lvl, SUBSTR(old_care_lvl,3), len test_care_lvl FROM
    WHERE LENGTH (old_care_lvl) = 14
    UNION ALL
    Row_id SELECT, old_care_lvl, SUBSTR (old_care_lvl, 3), LEN test_care_lvl
    WHERE LENGTH = 7 AND old_care_lvl (old_care_lvl) = "Regular."
    );

    I want to create the table using the above given the multiple selection by using the Union ALL clause, but trying to create run query error like "ORA-00998 must appoint this expression with the alias column 00998.00000 - must appoint this expression with the column alias.

    Please guide me how to approach to solve this problem.
    Thanks in advance.

    Try this->

    CREATE TABLE TEST_CARE
    AS
      select *
      from (
              SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
              WHERE LENGTH(old_care_lvl) =5
              UNION ALL
              SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
              WHERE LENGTH(old_care_lvl) =7
              UNION ALL
              SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
              WHERE LENGTH(old_care_lvl) =14
              UNION ALL
              SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3),LEN FROM test_care_lvl
              WHERE LENGTH(old_care_lvl) =7 AND old_care_lvl ='Regular'
          );
    

    N.B.: Not tested...

    Kind regards.

    LOULOU.

  • Please help me with the Alternative of queries to replace the UNION ALL for two queries

    Hi all

    I have the query to retrieve assets employees salary count and in so far as below:

    Select ename, emp_no, sum (sal_till_2010), sum (sal_till_2014) of

    (select emp_no, ename, salary as sal_till_2010, 0 as sal_till_2014 of employee e1

    where effective_date < = 1 January 2010 ' and not exists (select 1 from e2 employee_deletion where e2.emp_no = e1.emp_no and e2.deletion_date < = January 1, 2010 "")

    UNION ALL

    Select ename, emp_no, 0 as sal_till_2010, salary as employee e1 sal_till_2014 - here is a dummy 0 salary until 2010 for the union of all the

    where effective_date < = 1 January 2014 "and not exists (select 1 from e2 employee_deletion where e2.emp_no = e1.emp_no and e2.deletion_date < = 1 January 2014") "

    Group of emp_no, ename;

    In this query, I get the total salary until 2010 and until 2014 in the employee table, dates are dynamically passed to the procedure, and this can change.

    But assume the date above and let me know the alternative of queries to improve performance because I use Union ALL and read the same table twice in the above query.

    Advice me with request to read the table once to fetch the same data as the above query.

    Thanks in advance.


    Hello

    Thanks for the display of the data of the sample; It's very useful!

    I think OP wants something like this:

    WITH cutoff_dates AS

    (

    SELECT TO_DATE (January 1, 2010 ', ' DD/MM/YYYY') AS cutoff_date, 2010 UNDER the label OF dual UNION ALL

    SELECT TO_DATE (1 January 2014 ', "DD/MM/YYYY"), double 2014

    )

    SELECT e.emp_no, e.ename

    , NVL (SUM (CASE WHEN c.label = 2010 THEN e.salary END), 0) AS sal_till_2010

    , NVL (SUM (CASE WHEN c.label = 2014 THEN e.salary END), 0) AS sal_till_2014

    E employee

    JOIN cutoff_dates c ON e.effective_date<=>

    WHERE DOES NOT EXIST)

    SELECT 1

    Of employee_deletion ed

    WHERE ed.emp_no = e.emp_no

    AND ed.deletion_date<=>

    )

    E.emp_no GROUP, e.ename

    ORDER BY e.emp_no

    ;

    Output of your sample data:

    EMP_NO ENAME SAL_TILL_2010 SAL_TILL_2014

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

    1 Mickey 450 0

    2 Donald 750 0

  • Relating to the creation of a graph, get an error with a statement "Union All".

    Hello

    I have some data in the table with the following fields;

    Product, Jul-08 Aug-08, Sep - 08 etc. to Jan - 10.

    The PRODUCT field is text showing many product names

    The month of Jul-08 & others have numbers by product that must be aggregated for this month & plotted on the graph of the line.

    My SQL to create the first point on the chart is as below;

    Select the link null, label, SUM(JUL-08) "FFF".
    of "SCHEMANAME." "' TABLENAME '.
    WHERE PRODUCT = "FFF".
    PRODUCT GROUP
    ORDER BY PRODUCT

    It works fine until I want to add the second point of this graphic line by using a "union all" join as follows:

    Select the link null, label, SUM (JUL_08) "FFF".
    of "SCHEMANAME." "' TABLENAME '.
    WHERE PRODUCT = "FFF".

    UNION ALL

    Select the link null, label, SUM (AUG_08) "FFF".
    of "SCHEMANAME." "' TABLENAME '.
    WHERE PRODUCT = "FFF".

    I can't work on how I can join the other months on the line graph of a series.

    The error is as follows;

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

    1 error has occurred
    Failed to parse the SQL query:
    Click link null, label, SUM (OCT_09) 'Non-communicable diseases - STD' of 'BI_A_DATA '. "" CDW_VS_NCDS_CALLS "WHERE PRODUCT ="MNT - STD' UNION ALL select link null, PRODUCT, SUM (NOV_09) "Non-communicable diseases - LOCAL" label of "BI_A_DATA". "" CDW_VS_NCDS_CALLS "WHERE PRODUCT ="MNT - LOCAL.

    ORA-00937: not a single group group function

    Some queries can be run when you run your application, if your query is syntactically correct, you can save your query without validation (see options below the source of the query).

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

    If anyone can help?

    I want a continuous linear graph showing monthly July 2008, Aug-08 Sep - 08 etc. to Jan - 10 for the same product.

    I will then add other series for other products, thanks

    OK a graphic line will only allow you to draw 1 variable (in this case period). Given that it is only for a single product, so here should be the final sql:

    SELECT null link, PERIOD label, SUM(ABC)
    FROM
    (SELECT 'JUL_08' PERIOD,SUM(JUL_08)ABC
    FROM BI_A_DATA.APEX_TEST
    WHERE PRODUCT = 'ABC'
    
    UNION ALL
    
    SELECT 'AUG_08' PERIOD,SUM(AUG_08)ABC
    FROM BI_A_DATA.APEX_TEST
    WHERE PRODUCT = 'ABC'
    
    UNION ALL
    
    SELECT 'SEP_08' PERIOD,SUM(SEP_08)ABC
    FROM BI_A_DATA.APEX_TEST
    WHERE PRODUCT = 'ABC')
    
    GROUP BY PERIOD
    
  • WITH THE CLAUSE

    Hi all

    I'm using oracle 11.2.0.4

    I m using this for the purpose of learning

    Below is my table and insert statement

    CREATE TABLE COMPANY (NUMBER EMPLOYEE_ID, EMPLOYEE_NAME VARCHAR2 (30), NUMBER OF MANAGER_ID)

    INSERT INTO THE COMPANY'S VALUES (1, 'FRED', ");

    SOCIETY VALUES (2, 'BARNEY', '1');

    SOCIETY VALUES (3, 'WILMA', '1');

    SOCIETY VALUES (4, 'BETTY', '3');

    INSERT IN THE VALUES(5,'PEBBLES','3') SOCIETY;

    INSERT IN THE VALUES(6,'BAM-BAM','4') SOCIETY;

    INSERT IN THE VALUES(7,'DINO','4') SOCIETY;

    INSERT IN THE VALUES(8,'HOPPY','4') SOCIETY;

    WITH RSFC(CK,PK,LVL,HIER) AS

    (SELECT EMPLOYE_ID, MANAGER_ID, 0 AS LVL, EMPLOYEE_NAME LIKE YESTERDAY)

    SOCIETY

    WHERE MANAGER_ID IS NULL

    UNION ALL

    SELECT EMPLOYE_ID, MANAGER_ID, LVL + 1, YESTERDAY. '/' || EMPLOYEE_NAME

    OF THE RSFC R INNER JOIN COMPANY F

    ON R.CK = F.MANAGER_ID

    )

    WIDTH OF SEARCH FIRST BY CK ORDR SET

    SELECT A.LVL, A.CK, A.PK, A.HIER, ORDR

    THE RSFC HAS

    ORDER BY ORDR

    01FRED1
    121FRED/BARNEY2
    131FRED/WILMA3
    243FRED/WILMA/BETTY4
    253FRED/WILMA/PEBBLES5
    364FRED/WILMA/BETTY/BAM-BAM6
    374FRED, WILMA, BETTY, DINO7
    384FRED, WILMA, BETTY, HOPPY8

    First part, I believe, as well, explains Frank

    hierarchical queries

    next part in bold, I need to understand

    Thanks and respect.

    Guylaine

    Hi, lyly,

    You said that you did not understand the part highlighted in your query.  It looks like the 2 lines are highlighted:

    WIDTH OF SEARCH FIRST BY CK ORDR SET

    SELECT A.LVL, A.CK, A.PK, A.HIER, ORDR

    I guess that it's a typo.  The 2nd day of these lines is just the main SELECT clause; This is the 1st line, the clause of the SEARCH, who really needs an explanation.

    As far as I know, the SEARCH clause is only for the sorting of the results.  In other words, the a WITH recursive clause results will be the same, no matter what you put in the SEARCH clause, or if you omit the clause of RESEARCH.  The only purpose of the clause of RESEARCH is to generate the column command (ORDR in your example), which reflects where each row fits in the graph defined by your recursive query.  (Maybe, if you use non-deterministic user-defined functions, it can be a difference in the results.  Chances are, you never have to worry about this).

    If you do not use a clause in RESEARCH at all, it seems like by default

    WIDTH OF SEARCH FIRST BY NULL...

    In other words, the lines appear in order by level and in no particular order after that.  In your case, that would mean 'FRED' would come first, then "BARNEY" and "WILMA" (not necessarily in that order), followed by all the children of 'BARNEY' or 'WILMA' and so on.  No column order would be generated, so you could not guarantee order in the ORDER BY clause.

    I'm not sure that there is nothing you can do with a clause of RESEARCH that you can not do without a.  In other words, the SEARCH clause automatically generates a command column.  I believe you can still create an equivalent ordering column in the recursive query itself.  In your example, you could say

    ORDER BY lvl, ck

    to get the results sorted the same way.  Sometimes, using a SEARCH clause is much more convenient, and I bet that sometimes it is therefore more effective, too.

    2937991 wrote:

    Hi all

    I'm using oracle 11.2.0.4

    I m using this for the purpose of learning

    Below is my table and insert statement

    CREATE TABLE COMPANY (NUMBER EMPLOYEE_ID, EMPLOYEE_NAME VARCHAR2 (30), NUMBER OF MANAGER_ID)

    INSERT INTO THE COMPANY'S VALUES (1, 'FRED', ");

    SOCIETY VALUES (2, 'BARNEY', '1');

    ...

    As always, thank you for posting this information: it really helps!

    Manager_id is a NUMBER, it would be better if you don't quote it.  In other words, it would be more clear, more effective and less prone to say:

    INSERT INTO COMPANY (EMPLOYE_ID, EMPLOYEE_NAME, MANAGER_ID) VALUES (1, 'FRED', NULL);

    INSERT INTO COMPANY (EMPLOYE_ID, EMPLOYEE_NAME, MANAGER_ID) VALUES (2, 'BARNEY', 1);

    ...

    In this example, the unnecessary quotation marks do not hurt a lot, but they do not help all.

  • Union all with addistional field

    Hello

    Maybe this is a stupid question.

    I have two tables with 22 columns.

    Another table with 23 columns

    I want to combine these two tables using union all.

    In the first picture, I want back "NA" as the last field.

    In the second table, last column is varchar2.

    Instead of every column one by one and if I use select * in two queries and add "NA" to one?

    I want the union two queries can order and use it with the clause to retrieve values based on conditions somany.

    So I have to specify the names of column three times.

    I use oracle 10g

    Hello Krishna,

    Try

    select t1.*, 'NA' as  from table1 t1
    union
    select t2.* from table2 t2;
    

    concerning

    Kay

  • 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 >

  • Problem with dynamic setting where the clause OFA

    Hi all

    I have a view object with the following query:

    SELECT rownum LINENUM,

    B.line_id LINE_ID,

    B.INVENTORY_ITEM_ID INVITMID,

    B.QUANTITY_DELIVERED PICKQTY

    MTL_TXN_REQUEST_HEADERS a,.

    MTL_TXN_REQUEST_LINES B

    WHERE A.HEADER_ID = B.HEADER_ID

    AND A.MOVE_ORDER_TYPE = 2

    AND "on" =: 1

    AND B.TO_SUBINVENTORY_CODE = NVL(:4,B.TO_SUBINVENTORY_CODE)

    AND A.request_number = NVL(:5,A.REQUEST_NUMBER)

    UNION ALL

    SELECT rownum LINENUM,

    a.wip_entity_id LINE_ID,

    a.INVENTORY_ITEM_ID INVITMID,

    a.QUANTITY_ISSUED PICKQTY

    WIP_REQUIREMENT_OPERATIONS has

    eam_work_orders_v b

    WHERE a.wip_entity_id = b.wip_entity_id

    AND "on" =: 2

    AND a.ATTRIBUTE2 = NVL(:4,a.ATTRIBUTE2)

    and b.wip_entity_name = NVL(:6,b.wip_entity_name)

    I need to dynamically pass a condition to my where clause that I can manage it by setting two binding settings in the query of vo and can pass it on but the problem is the connection variable contains a string like 1311,13112,14445 that I need to spend for a domain like B.line_id in the first query and b.wip_entity_id in the second query , so when I'm passing the string as a value it works fine, but it gives for value separetd by comma prob.

    so I tried passing dynamic where clause, but there is every time that the execution of the first clause only how can I dynamically pass both queries.

    vo.setWhereClause ("LINE_ID in" + wherclause);

    Please help me

    Thnaks

    Deb

    Hello

    Actually I'm passing the parameter to the basic page popup, so in page popup page and the base, I was using the VO even to run then, probably due to that he was running again for all data, so for the basic page I created a new VO and tried to pass the parameter like when clause for questioning now it runs very well Thank you for all your help

Maybe you are looking for

  • How much memory left on iPhone 5

    I am running the latest OS and software on my iPhone 5 and the iMac. When I sync the iPhone in iTunes, iThunes indicate that I'm 5.35 GB of memory left, but on the iPhone it says I have only 3.7 GB left. Why this difference?

  • I'm going back to my e-mail address of moose. Email removed for privacy

    I tried to change to my Moose e-mailwith e-mail of changes on this site. But it isn' work. I get all my e-mail.

  • ENVY 5640: HP ENVY 5640 - cannot print more

    Hello I have a HP ENVY 5640 I had setup was working fine before.I have not used the printer for a few weeks, but there is no problem with the ink cartridges.The part Scanner works fine. I can't print anything more and I do not understand why.PowerPoi

  • T61 Bluetooth not pair w / Wiimote (Wii remote) with 5.5.0.5800

    I try to use a wiimote for an implementation of the elecronic whitebaord. (wiimoteproject.com). the wiimote does not use an access key to the pair. If one is given, it will not pair. I just downloaded the last stack of BT and now version 5.5.0.5800.

  • Using paint and how to change the text box.

    How can I select a text box that you want to modify in the paint - Windows 7 Home Premium?  Once I leave the text box I can't select again a second time to change the text or grab it to move... I must be missing something very simple?  Is there a man