Syntax Error - Using "Group By" with "Union All"

Dear SAP community, I am a newb in need of help.
Just spent the past 2 days searching for answers on how to build this query.
Basically, I just want to group the Item Names (U_ItemName) together and have their respective quantities (U_Cart) added together so the same items display as one total quantity, no duplicates.
I have tried so many combinations of GroupBy and Sum/Count....etc.  Nothing is working.
The query:
SELECT T1.[U_ItemName] AS 'Item Name', T1.[U_Cart] AS 'Cartons Available', T0.[Country] AS 'Country', T1.[U_ShlfLife] AS 'Shelf Life' FROM [dbo].[OWHS] T0 inner join [dbo].[@SICAS_EXT_WHS] T1  on T0.WhsCode=T1.U_WhseCode WHERE T0.[Country] = (N'JP' ) and DateDiff(Month, GetDate(),T1.[U_ShlfLife]) <= 6 union all
SELECT T0.[U_ItemName], Sum(T0.[U_Cart]) as Cartons, T1.[Country], null FROM [dbo].[@SICAS_EXT_WHS]  T0, OWHS T1 WHERE T1.[Country] = (N'JP' ) and DateDiff(Month, GetDate(),T0.[U_ShlfLife]) >= 6
GROUP BY T0.[U_ItemName], T0.[U_Cart], T1.[Country]
Can anybody advise how to get this working?
Thank you,
Justice Nerenberg

hi justice,
I checked your code and it seems correct. but I don't have same table in database so i can't check it correctly.
but I tried your problem with same situation and I am getting actual result.
Example :-
select itemcode,dscription,quantity from inv1
where docdate>'2011-02-18 00:00:00.000'
union all
select itemcode,dscription,Sum(quantity) from inv1
where docdate<'2011-02-18 00:00:00.000'
group by itemcode,dscription
Please do one thing rum both select queries separately whether running properly. Using above example you can check your code
Thanks
Annu

Similar Messages

  • Error creating materilalized view with union all

    Could please anybody advice? What I do wrong?
    create table test
    i number not null,
    constraint pk_test primary key( i ));
    create materialized view log on test with rowid;
    create materialized view mvtest refresh fast on demand as
    SELECT i, 1 umarker FROM test where i < 10000
    UNION ALL SELECT i, 2 umarker FROM test where i > 10000;
    ORA-12052: cannot fast refresh materialized view MVTEST
    It looks like I accomplished all fast refresh requirements, didn't I?
    Thanks a lot.
    Alexander.

    SQL> create table test
      2  (i number not null,
      3  constraint pk_test primary key( i ));
    Table created.
    SQL> create materialized view log on test with rowid;
    Materialized view log created.
    SQL> create materialized view mvtest refresh fast on demand as
      2  SELECT t.i, 1 umarker, t.rowid row_id FROM test t where t.i <= 10000
      3  UNION ALL
      4  SELECT t.i, 2 umarker, t.rowid row_id FROM test t where t.i > 10000;
    Materialized view created.(This is on 11.2)

  • Materalized view with union all and fast referesh

    I have a one view which is very slow. in this view we are joining many tables and many union all queries.
    now I am planing to make materalized view
    Tell me how i will created view with fast refresh with union all query.
    Pls help its urgent..
    Thanks
    Reena

    Refer to the Replication Manual for the create syntax and exceptions.

  • Report which concatenates 13 views with union all running slowly

    Oracle 8.1.7 windows 2000 server
    I am trying to improve the performance of a report which is comprised of 13 views.
    When I run each of the views individually, the total run time for the views is less than 5 minutes. When I run the report, it takes 28 minutes.
    Can anyone suggest why the extra time is being taken?
    To reiterate:
    select a,b from c; (executes in 10 seconds)
    select d, e from f (executes in 3 seconds)
    select x, y from z (executes in 1 minute)
    total runs time = 5 minutes
    However,
    select a,b from c
    union all
    select d, e from f
    union all
    select x, y from z (executes in 28 minutes)
    The execution plans do not change between the report and the indiividual views. Views are being concatenated with union all so no sorting is taking place
    Many thanks,
    Jason Parker.
    Edited by: jclparker on Feb 18, 2009 4:26 AM
    Edited by: jclparker on Feb 18, 2009 4:30 AM

    Could you post the execution plan? Please use formatting tags to save the white space while posting the plan.

  • Different results using View with union all in 11R1 compared to 10R2

    Hello,
    I have the following situation:
    In Oracle 10R2 I defined a view which looks like this
    create view test_view
    as
    select 'field1;field2;field3' field from dual
    union all
    select field
    from (
    select tfield1||';'||tfield2||';'||tfield3 field
    from table1
    order by tfield1,tfield2,tfield3
    The idea is, my first line contains a header information an then the data in the required sorting order.
    So, in 10R2, when I export the view with select field from test_view, I get the result as expected, which means, the header from the part with the dual was in the first line and after that, the data in the required sort order.
    Now, in 11.1.0.7, it is completely different, because the row of the dual is somewhere in my result set. But if I send the sql instead of the view, I get the expected result as in 10R2.
    I have no idea why this is the case now, because in 10R2 this was working permanently as expected. When I look at the execution plan, I see, that he starts parallelisation, which is ok, but the difference is, that in this parallelisation the select from dual is included and in 10R2 he first make the line from the dual and then the parallelisation with the data. It's not clear to me, that if I send the sql to the database I see the required result, but if i define the view as mentioned, and start a select field from view, I get now get the different sorting, because of the parallelisation, where the optimizer he changes his behavior comparing the both database versions. So my question ist, how can I change this behavior to get the same behavior as in release 10R2.
    Best regards
    Rainer

    Hello,
    thank you for your sample, I see your idea for my sorting purpose.
    I want to look at the following point:
    I create the table, as you described. The table has the degree and instances 1. Now I deefine the following view:
    create view view_test
    as
    select 'field1;field2;field3' field
    from dual
    union all
    select tfield1 || ';' || tfield2 || ';' || tfield3 field
    from (select * from table1 order by tfield1,tfield2).
    This is the way I used it in 10 R2.
    Now, the SQL select field from view_test delivers the expected result:
    field1;field2;field3
    a;b;c
    d;e;f
    So far so good. But now, I changed the degree of the table1 (alter table table1 parallel (degree 4 instances 1);).
    The result looks like that:
    a;b;c
    field1;field2;field3
    d;e;f
    So, the parallelisation of my object seems to be the reason for the, in my eyes, "wrong" sort order. In 10R2 I used this degree and instance values for my table and defined a view and it was working fine. Now, after our migration, I had this "trouble". For me it seems, that the optimizer made some changes, or mabe this is a bug, who knows ?
    I also tried, to change the nls_comp, and set the undocumented parameters as described in the Metalink note 7497640.8, but with no effect of my result set.
    Best regards
    Rainer

  • Inconsistent SQL results when using View with UNION-ALL and table function

    Can any of you please execute the below scripts and check the output. In the table type variable, I am adding 4 distinct object ids, where as in the result, I get only the row pertaining to last id in the table type variable. Same row is returned 4 times (4= number of values in the table type).
    This scenario is occurring in our product with a SQL with exactly same pattern. I could simulate the same issue with the sample script I have provided.
    Database version: 11.2.0.3 Enterprise Edition, Single node
    Thank you.
    CREATE TABLE TEMP_T1 AS SELECT * FROM ALL_OBJECTS;
    CREATE TABLE TEMP_T2 AS SELECT * FROM ALL_OBJECTS;
    UPDATE TEMP_T2 SET OBJECT_ID = OBJECT_ID * 37;
    CREATE UNIQUE INDEX TEMP_T1_U1 ON TEMP_T1(OBJECT_ID);
    CREATE UNIQUE INDEX TEMP_T2_U1 ON TEMP_T2(OBJECT_ID);
    CREATE OR REPLACE VIEW TEMP_T1T2_V AS
    SELECT * FROM TEMP_T1 UNION ALL SELECT * FROM TEMP_T2;
    CREATE OR REPLACE TYPE TEMP_OBJ_TYPE AS OBJECT (OBJ_ID NUMBER);
    CREATE OR REPLACE TYPE TEMP_OBJ_TAB_TYPE IS TABLE OF TEMP_OBJ_TYPE;
    SET SERVEROUTPUT ON;
    DECLARE
    TYPE TEMP_T1T2_V_ROW_TAB_TYPE IS TABLE OF TEMP_T1T2_V%ROWTYPE;
    TEMP_T1T2_V_ROW_TAB TEMP_T1T2_V_ROW_TAB_TYPE;
    TEMP_OBJ_TAB TEMP_OBJ_TAB_TYPE := TEMP_OBJ_TAB_TYPE();
    PROCEDURE ADD_TO_TEMP_OBJ_TAB(OBJ_ID IN NUMBER) IS
    BEGIN
    TEMP_OBJ_TAB.EXTEND;
    TEMP_OBJ_TAB(TEMP_OBJ_TAB.LAST) := TEMP_OBJ_TYPE(OBJ_ID);
    END;
    BEGIN
    ADD_TO_TEMP_OBJ_TAB(100);
    ADD_TO_TEMP_OBJ_TAB(116);
    ADD_TO_TEMP_OBJ_TAB(279);
    ADD_TO_TEMP_OBJ_TAB(364);
    DBMS_OUTPUT.PUT_LINE('=====================');
    FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
    LOOP
    DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('---------------------');
    SELECT * BULK COLLECT INTO TEMP_T1T2_V_ROW_TAB
    FROM TEMP_T1T2_V VW
    WHERE ((VW.OBJECT_ID) IN (SELECT OBJ_ID
    FROM TABLE(CAST(TEMP_OBJ_TAB AS TEMP_OBJ_TAB_TYPE))));
    FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
    LOOP
    DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('---------------------');
    IF TEMP_T1T2_V_ROW_TAB.COUNT > 0 THEN
    FOR I IN TEMP_T1T2_V_ROW_TAB.FIRST..TEMP_T1T2_V_ROW_TAB.LAST
    LOOP
    DBMS_OUTPUT.PUT_LINE(TEMP_T1T2_V_ROW_TAB(I).OBJECT_ID||' : '||TEMP_T1T2_V_ROW_TAB(I).OBJECT_NAME);
    END LOOP;
    ELSE
    DBMS_OUTPUT.PUT_LINE('NO ROWS RETURNED!');
    END IF;
    DBMS_OUTPUT.PUT_LINE('---------------------');
    END;
    /

    I can reproduce it:
    SQL*Plus: Release 11.2.0.3.0 Production on Tue Oct 30 14:05:39 2012
    Copyright (c) 1982, 2011, Oracle.  All rights reserved.
    Enter user-name: scott
    Enter password:
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> select  *
      2    from  v$version
      3  /
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for 64-bit Windows: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    SQL> CREATE TABLE TEMP_T1 AS SELECT * FROM ALL_OBJECTS;
    Table created.
    SQL>
    SQL> CREATE TABLE TEMP_T2 AS SELECT * FROM ALL_OBJECTS;
    Table created.
    SQL>
    SQL> UPDATE TEMP_T2 SET OBJECT_ID = OBJECT_ID * 37;
    72883 rows updated.
    SQL>
    SQL> CREATE UNIQUE INDEX TEMP_T1_U1 ON TEMP_T1(OBJECT_ID);
    Index created.
    SQL>
    SQL> CREATE UNIQUE INDEX TEMP_T2_U1 ON TEMP_T2(OBJECT_ID);
    Index created.
    SQL>
    SQL> CREATE OR REPLACE VIEW TEMP_T1T2_V AS
      2  SELECT * FROM TEMP_T1 UNION ALL SELECT * FROM TEMP_T2;
    View created.
    SQL>
    SQL> CREATE OR REPLACE TYPE TEMP_OBJ_TYPE AS OBJECT (OBJ_ID NUMBER)
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE TEMP_OBJ_TAB_TYPE IS TABLE OF TEMP_OBJ_TYPE
      2  /
    Type created.
    SQL> SET SERVEROUTPUT ON;
    SQL>
    SQL> DECLARE
      2  TYPE TEMP_T1T2_V_ROW_TAB_TYPE IS TABLE OF TEMP_T1T2_V%ROWTYPE;
      3  TEMP_T1T2_V_ROW_TAB TEMP_T1T2_V_ROW_TAB_TYPE;
      4  TEMP_OBJ_TAB TEMP_OBJ_TAB_TYPE := TEMP_OBJ_TAB_TYPE();
      5  PROCEDURE ADD_TO_TEMP_OBJ_TAB(OBJ_ID IN NUMBER) IS
      6  BEGIN
      7  TEMP_OBJ_TAB.EXTEND;
      8  TEMP_OBJ_TAB(TEMP_OBJ_TAB.LAST) := TEMP_OBJ_TYPE(OBJ_ID);
      9  END;
    10  BEGIN
    11  ADD_TO_TEMP_OBJ_TAB(100);
    12  ADD_TO_TEMP_OBJ_TAB(116);
    13  ADD_TO_TEMP_OBJ_TAB(279);
    14  ADD_TO_TEMP_OBJ_TAB(364);
    15  DBMS_OUTPUT.PUT_LINE('=====================');
    16  FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
    17  LOOP
    18  DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
    19  END LOOP;
    20  DBMS_OUTPUT.PUT_LINE('---------------------');
    21  SELECT * BULK COLLECT INTO TEMP_T1T2_V_ROW_TAB
    22  FROM TEMP_T1T2_V VW
    23  WHERE ((VW.OBJECT_ID) IN (SELECT OBJ_ID
    24  FROM TABLE(CAST(TEMP_OBJ_TAB AS TEMP_OBJ_TAB_TYPE))));
    25  FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
    26  LOOP
    27  DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
    28  END LOOP;
    29  DBMS_OUTPUT.PUT_LINE('---------------------');
    30  IF TEMP_T1T2_V_ROW_TAB.COUNT > 0 THEN
    31  FOR I IN TEMP_T1T2_V_ROW_TAB.FIRST..TEMP_T1T2_V_ROW_TAB.LAST
    32  LOOP
    33  DBMS_OUTPUT.PUT_LINE(TEMP_T1T2_V_ROW_TAB(I).OBJECT_ID||' : '||TEMP_T1T2_V_ROW_TAB(I).OBJECT_NAME);
    34  END LOOP;
    35  ELSE
    36  DBMS_OUTPUT.PUT_LINE('NO ROWS RETURNED!');
    37  END IF;
    38  DBMS_OUTPUT.PUT_LINE('---------------------');
    39  END;
    40  /
    =====================
    OBJ_ID = 100
    OBJ_ID = 116
    OBJ_ID = 279
    OBJ_ID = 364
    OBJ_ID = 100
    OBJ_ID = 116
    OBJ_ID = 279
    OBJ_ID = 364
    364 : I_AUDIT
    364 : I_AUDIT
    364 : I_AUDIT
    364 : I_AUDIT
    PL/SQL procedure successfully completed.
    SQL> column object_name format a30
    SQL> select  object_id,
      2          object_name
      3    from  dba_objects
      4    where object_id in (100,116,279,364)
      5  /
    OBJECT_ID OBJECT_NAME
           100 ORA$BASE
           116 DUAL
           279 MAP_OBJECT
           364 I_AUDIT
    SQL>  Works fine in:
    =====================
    OBJ_ID = 100
    OBJ_ID = 116
    OBJ_ID = 279
    OBJ_ID = 364
    OBJ_ID = 100
    OBJ_ID = 116
    OBJ_ID = 279
    OBJ_ID = 364
    100 : ORA$BASE
    116 : DUAL
    364 : SYSTEM_PRIVILEGE_MAP
    279 : MAP_OBJECT
    PL/SQL procedure successfully completed.
    SQL> select  object_id,
      2          object_name
      3    from  dba_objects
      4    where object_id in (100,116,279,364)
      5  /
    OBJECT_ID OBJECT_NAME
          100 ORA$BASE
          116 DUAL
          364 SYSTEM_PRIVILEGE_MAP
          279 MAP_OBJECT
    SQL> select  *
      2    from  v$version
      3  /
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    SQL>SY.
    Edited by: Solomon Yakobson on Oct 30, 2012 2:14 PM

  • Dont want to use group by with sum function..

    Hi all
    I am using sum function but i dont want to use group by since my query give me following output which i dont want I want.
    0------------22---------(null)     Furniture
    0-----------     3700------     (null)     अनपेड बिल्स देणे
    15800-----14202-----(null)     Petty Cash
    (null)------     (null)------ 9109     Furniture
    (null)------ (null)------ 1789     Petty Cash
    (null)-------(null)------ 0     Checking In-Transfer
    I want like
    0------------22---------9109     Furniture
    0-----------     3700------     0     अनपेड बिल्स देणे
    15800-----14202-----1789     Petty Cash
    what should be the problem how I can handle the query my query is
    select  null as totalcr, null as totaldr, (sum(acct.amtsourcecr)-sum(acct.amtsourcedr)) as opening , ev.name as accountname
    from fact_acct acct right OUTER join  c_elementvalue ev on acct.account_id= ev.c_elementvalue_id
    where acct.dateacct < '01/04/2010'
    and ev.cr_account_base=2
    group by ev.name
    UNION
    select sum(acct.amtsourcecr) as totalcr, sum(acct.amtsourcedr) as totaldr, null as opening
    *,ev.name as accountname*
    from fact_acct acct right OUTER join  c_elementvalue ev on acct.account_id= ev.c_elementvalue_id
    where  acct.datetrx BETWEEN '01/04/2010' and '01/04/2010'
    group by  ev.name
    if I remove group by it shows me error .....not a single group by function ...
    please help me out ,,,
    thanking you

    This is one way you can do it without a group by:
    SQL> with t as
      2    (
      3      select 0 amt1, 22 amt2, null amt3, 'Furniture' tag from dual union all
      4      select 15800,14202,null, 'Petty Cash' from dual union all
      5      select null, null, 9109, 'Furniture' from dual union all
      6      select null, null, 1789, 'Petty Cash' from dual
      7    )
      8  select tag, amt1, amt2, amt3
      9  from
    10  (
    11    select sum(amt1) over (partition by tag) amt1
    12          ,sum(amt2) over (partition by tag) amt2
    13          ,sum(amt3) over (partition by tag) amt3
    14          ,first_value(t.tag) over (partition by t.tag order by rownum) tag
    15          ,row_number() over (partition by t.tag order by rownum) rn
    16    from t
    17  )
    18  where rn = 1
    19  /
    TAG              AMT1       AMT2       AMT3
    Furniture           0         22       9109
    Petty Cash      15800      14202       1789

  • Using order by in Union ALL

    hi Following is my query and am unable to accomplish my order by statement in Union All . please help me in this.
    <code>
    SELECT b.audit_trail_id,
    TO_CHAR (b.last_update_date, 'DD-Mon-YYYY') "Revision Date",
    (u.last_name || ', ' || u.first_name || ' ' || u.mi) "By",
    b.col_name "Field",
    b.new_value "New Value",b.previous_value "Old Value",
    a.lot_id,
    b.comment_text "Comments"
    FROM clem_audit_trail b,lot a, users u
    WHERE a.lot_id = b.lot_id(+)
    AND u.user_id(+) = b.last_update_user_id
    AND a.lot_id in (select lot_id from request_lot where request_id = 51914)
    AND col_name IN
    ('Interim Release Date',
    'Final Disposition Date',
    'On Time Disposition',
    'Intended Use',
    'REJECTS_YN',
    '# of QARs',
    '# of Quality Events',
    '# of LIRs',
    '# of Change Controls',
    '# of Batch Records',
    '# of GMP Batch Records',
    'EXPLANATION',
    'QA Notes',
    'GDMS_LINK')
    AND UPPER (table_name) IN('LOT') order by b.last_update_date
    UNION ALL
    SELECT b.audit_trail_id,
    TO_CHAR (b.last_update_date, 'DD-Mon-YYYY') "Revision Date",
    (u.last_name || ', ' || u.first_name || ' ' || u.mi) "By",
    b.col_name "Field",
    b.new_value "New Value",b.previous_value "Old Value",
    r.request_id,
    b.comment_text "Comments"
    FROM clem b,request r, users u
    WHERE r.request_id = b.request_id(+)
    AND u.user_id(+) = b.last_update_user_id
    AND r.request_id = 51914
    AND UPPER (table_name) IN ('REQUEST') AND
    b.col_name IN ('Partial Release',
    'All QP Docs in GDMS',
    'Number of Batch Records',
    'Request',
    'QP Issues',
    'Snag Comments',
    'Responsible Group',
    'Reason Late',
    'Study Impact',
    'Other Details',
    'Request Status',
    'QP Link to GDMS'
    ) order by b.last_update_date
    </code>
    If i execute individually it works fine, if i use union all it throughs error for me.
    Any suggestion...

    Hi,
    In a set operation (such as UNION) table aliases (such as b.) only have meaning within the branch in which they are defined. The ORDER BY clause is not part of any 1 branch, so a table alias can't be used there.
    In most cases, you can use a column name (or alias) from the first branch, like this:
    SELECT    b.audit_trail_id,
              TO_CHAR (b.last_update_date, 'DD-Mon-YYYY') "Revision Date",
    order by  "Revision Date"
    ;and you can always order by column number, like this:
    SELECT    b.audit_trail_id,
              TO_CHAR (b.last_update_date, 'DD-Mon-YYYY') "Revision Date",
    order by  2
    ;In this case, however, there's an extra problem. You're transforming the DATE to a string in the SELECT clause. The string is all that's available in the ORDER BY clause, and the string '19-NOV-2012' comes after the string '01-JAN-2015', because the character '1' comes after '0'. Perhaps the simplest solution is to have your front end, and not the query, format the dates. In SQL*Plus, you can do this:
    ALTER SESSION  SET NLS_DATE_FORMAT = 'DD-MON-YYYY';
    SELECT    b.audit_trail_id,
              b.last_update_date    AS "Revision Date",
    order by  2
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • Creating M.V on time with union all

    Hi,
    Here i am creating a M.V and i want refresh this on time(example every day 12.00)
    create materialized view log on emp
    with primary key
    including new values;
    create materialized view log on dept
    with primary key
    including new values;
    create materialized view  emp_dept_new
    refresh on (what ever)
    as select deptno from emp
    union all
    select deptno from dept;when i am executing the last script i am getting some error.
    Please help me in this issue very argent .............
    Thanks
    SKPR.

    SKPR wrote:
    Hi,
    Here i am creating a M.V and i want refresh this on time(example every day 12.00)
    create materialized view log on emp
    with primary key
    including new values;
    create materialized view log on dept
    with primary key
    including new values;
    create materialized view  emp_dept_new
    refresh on (what ever)
    as select deptno from emp
    union all
    select deptno from dept;when i am executing the last script i am getting some error.You will do as "(what ever)" isn't valid syntax.
    Please help me in this issue very argent .............Not for us it's not.
    If you expect help, post your actual code and post the error message you're getting. We're not mind readers, so "some error" means nothing to us.

  • Probelm with Union all in view

    I'm tring to create a view by using the following:
    SELECT MASTER_IDX.MASTER_IDX_ID, CREATE_BY AS PERSON, CREATE_DATE AS WORKDATE, 'CREATE' AS WORKTYPE
    FROM MASTER_IDX
    WHERE CREATE_BY <> 'IQS'
    UNION ALL
    SELECT MASTER_IDX.MASTER_IDX_ID, INDEX_BY AS PERSON, INDEX_DATE AS WORKDATE, 'INDEX' AS WORKTYPE
    FROM MASTER_IDX
    WHERE INDEX_BY <> 'IQS'
    UNION ALL
    SELECT MASTER_IDX.MASTER_IDX_ID, VER_BY AS PERSON, VER_DATE AS WORKDATE, 'INDEX' AS WORKTYPE
    FROM MASTER_IDX
    WHERE VER_BY <> 'IQS'
    UNION ALL
    SELECT MASTER_IDX.MASTER_IDX_ID, MOD_BY AS PERSON, MOD_DATE AS WORKDATE, 'INDEX' AS WORKTYPE
    FROM MASTER_IDX
    WHERE MOD_BY <> 'IQS'
    UNION ALL
    SELECT MASTER_IDX.MASTER_IDX_ID, MAILBACK_BY AS PERSON, MAILBACK_DATE AS WORKDATE, 'INDEX' AS WORKTYPE
    FROM MASTER_IDX
    WHERE MAILBACK_BY <> 'IQS'
    UNION ALL
    SELECT IDX_IMAGE.MASTER_IDX_ID, SCANNED_BY AS PERSON , SCANNED_DATETIME AS WORKDATE, 'SCANNED' AS WORKTYPE
    FROM IDX_IMAGE
    WHERE SCANNED_BY <> 'IQS'
    when I run this in the sql developer environment I get the results that I expect. When I try to put this into a view I get this error:
    java.lang.NullPointerException
    Can anyone please look at this and give me a clue as to what i'm doing worng?
    Thanks!

    Can you give a bit more detail about which SQL Developer version you are using, what you mean by "put this into a view" (using the "New View ..." window?) and just what you were doing when you got the NPE (ie Test Syntax or OK to create or something else)?
    theFurryOne

  • Oracle doc inconsistent on materialize view with union all and self joins

    First of all, I can't seem to create a materialized view containing self-joins AND union all. Is it possible?
    I checked Oracle 9i (my version: PL/SQL Release 9.2.0.4.0 - Production) documentation and I get different answers (or so it seems to me).
    First I saw this: "The COMPATIBILITY parameter must be set to 9.0 if the materialized aggregate view has inline views, outer joins, self joins or grouping sets and FAST REFRESH is specified during creation..."
    Did you see the part about 'self joins' in there? I did and I was pumped because that seems to say that you CAN have 'self joins' (and my compatibility is 9.2...)
    BUT
    In the very same document I also found "Oracle does not allow self-joins in materialized join views." (rage)
    You can see the document I am speaking of here: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96520/mv.htm#574889
    Whenever I try to create the mview I get the following error. (
    In any caseORA-01446 cannot select ROWID from view with DISTINCT, GROUP BY, etc.

    First of all, I can't seem to create a materialized view containing self-joins AND union all. Is it possible?
    I checked Oracle 9i (my version: PL/SQL Release 9.2.0.4.0 - Production) documentation and I get different answers (or so it seems to me).
    First I saw this: "The COMPATIBILITY parameter must be set to 9.0 if the materialized aggregate view has inline views, outer joins, self joins or grouping sets and FAST REFRESH is specified during creation..."
    Did you see the part about 'self joins' in there? I did and I was pumped because that seems to say that you CAN have 'self joins' (and my compatibility is 9.2...)
    BUT
    In the very same document I also found "Oracle does not allow self-joins in materialized join views." (rage)
    You can see the document I am speaking of here: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96520/mv.htm#574889
    Whenever I try to create the mview I get the following error. (
    In any caseORA-01446 cannot select ROWID from view with DISTINCT, GROUP BY, etc.

  • Syntax error using try statement in WLST

    Hi All,
    I have a WLST script to create some JMS resources.
    I want to implement exception handling in such a way that if the script fails at any point, all the changes done should be reverted back.
    However, whenever I am trying to put a try block, the script is throwing syntax error on the first line after the try statement.
    Please find below the script I am using. Please suggest
    import sys
    from java.lang import System
    *# Putting a try statement here results in a syntax error at the below line*
    print "Starting the script ..."
    connect('weblogic',password,'t3://osbdev:7001')
    edit()
    startEdit()
    servermb=getMBean("Servers/osb_server")
    if servermb is None:
    print 'Value is Null'
    else:
    +# Creating the JMS Server+
    jmsserver1mb = create('WLSTJMSServer','JMSServer')
    jmsserver1mb.addTarget(servermb)
    +# Creating the JMS Module+
    jmsMySystemResource = create("WLSTJmsSystemResource","JMSSystemResource")
    jmsMySystemResource.addTarget(servermb)
    subDep1mb = jmsMySystemResource .createSubDeployment('WLSTJMSSubDeployment')
    subDep1mb.addTarget(jmsserver1mb)
    theJMSResource = jmsMySystemResource.getJMSResource()
    connfact1 = theJMSResource.createConnectionFactory('WLSTConnFact1')
    connfact1.setJNDIName('jms.WLSTConnFact1')
    connfact1.setSubDeploymentName('WLSTJMSSubDeployment')
    print "Creating WLSTQueue1..."
    jmsqueue1 = theJMSResource.createQueue('WLSTJMSQueue1')
    jmsqueue1.setJNDIName('jms.WLSTJMSQueue1')
    jmsqueue1.setSubDeploymentName('WLSTJMSSubDeployment')
    print "Creating WLSTQueue2..."
    jmsqueue2 = theJMSResource.createQueue('WLSTJMSQueue2')
    jmsqueue2.setJNDIName('jms.WLSTJMSQueue2')
    jmsqueue2.setSubDeploymentName('WLSTJMSSubDeployment')
    *# try statement is working at only this point of the program*
    try:
    save()
    activate(block="true")
    print "script returns SUCCESS"
    except:
    save()
    cancelEdit(defaultAnswer="y")
    print "Error while trying to connect to server !!!"
    print "Unexpected error: ", sys.exc_info()[0]
    dumpStack()
    raise
    Edited by: Chintan Parekh on Mar 16, 2011 7:06 AM

    Hi Chintan,
    Try doing copy pasting the below code, you have to hit the tab or space after try or except to create its block and keep an eye on the alinement's of it.
    try:
         save()
         activate(block="true")
         print "script returns SUCCESS"
    except:
         save()
         cancelEdit(defaultAnswer="y")
         print "Error while trying to connect to server !!!"
         print "Unexpected error: ", sys.exc_info()[0]
         dumpStack()Also I made the alinement's properly and the script is running properly with out any error.
    print "Starting the script ..."
    connect('weblogic','weblogic','t3://localhost:7001')
    edit()
    startEdit()
    servermb=getMBean("Servers/AdminServer")
    if servermb is None:
         print 'Value is Null'
    else:
         # Creating the JMS Server
         jmsserver1mb = create('WLSTJMSServer','JMSServer')
         jmsserver1mb.addTarget(servermb)
         # Creating the JMS Module
         jmsMySystemResource = create("WLSTJmsSystemResource","JMSSystemResource")
         jmsMySystemResource.addTarget(servermb)
         subDep1mb = jmsMySystemResource .createSubDeployment('WLSTJMSSubDeployment')
         subDep1mb.addTarget(jmsserver1mb)
         theJMSResource = jmsMySystemResource.getJMSResource()
         connfact1 = theJMSResource.createConnectionFactory('WLSTConnFact1')
         connfact1.setJNDIName('jms.WLSTConnFact1')
         connfact1.setSubDeploymentName('WLSTJMSSubDeployment')
         print "Creating WLSTQueue1..."
         jmsqueue1 = theJMSResource.createQueue('WLSTJMSQueue1')
         jmsqueue1.setJNDIName('jms.WLSTJMSQueue1')
         jmsqueue1.setSubDeploymentName('WLSTJMSSubDeployment')
         print "Creating WLSTQueue2..."
         jmsqueue2 = theJMSResource.createQueue('WLSTJMSQueue2')
         jmsqueue2.setJNDIName('jms.WLSTJMSQueue2')
         jmsqueue2.setSubDeploymentName('WLSTJMSSubDeployment')
    # try statement is working at only this point of the program
    try:
         save()
         activate(block="true")
         print "script returns SUCCESS"
    except:
         save()
         cancelEdit(defaultAnswer="y")
         print "Error while trying to connect to server !!!"
         print "Unexpected error: ", sys.exc_info()[0]
         dumpStack()Below is the output
    java weblogic.WLST test.py
    Initializing WebLogic Scripting Tool (WLST) ...
    Welcome to WebLogic Server Administration Scripting Shell
    Type help() for help on available commands
    Starting the script ...
    Connecting to t3://localhost:7001 with userid weblogic ...
    Successfully connected to Admin Server 'AdminServer' that belongs to domain 'Domain_7001'.
    Warning: An insecure protocol was used to connect to the
    server. To ensure on-the-wire security, the SSL port or
    Admin port should be used instead.
    Location changed to edit tree. This is a writable tree with
    DomainMBean as the root. To make changes you will need to start
    an edit session via startEdit().
    For more help, use help(edit)
    You already have an edit session in progress and hence WLST will
    continue with your edit session.
    Starting an edit session ...
    Started edit session, please be sure to save and activate your
    changes once you are done.
    MBean type JMSServer with name WLSTJMSServer has been created successfully.
    MBean type JMSSystemResource with name WLSTJmsSystemResource has been created successfully.
    Creating WLSTQueue1...
    Creating WLSTQueue2...
    Saving all your changes ...
    Saved all your changes successfully.
    Activating all your changes, this may take a while ...
    The edit lock associated with this edit session is released
    once the activation is completed.
    Activation completed
    script returns SUCCESSRegards,
    Ravish Mody
    http://middlewaremagic.com/weblogic
    Come, Join Us and Experience The Magic…
    Edited by: Ravish Mody-MiddewareMagic on Mar 16, 2011 8:33 PM

  • Updatable Materialized View with Union ALL

    (please don't ask about db structure)
    DB: 11gR2
    create table table_1  (
        id number primary key,
        val varchar2(100)
    create table table_2  (
        id number primary key,
        val varchar2(100)
    insert into table_1(id) values (0);
    insert into table_1(id) values (2);
    insert into table_1(id) values (3);
    insert into table_1(id) values (4);
    insert into table_1(id) values (5);
    insert into table_2(id) values (10);
    insert into table_2(id) values (12);
    insert into table_2(id) values (13);
    insert into table_2(id) values (14);
    insert into table_2(id) values (15);
    update table_1 set val='Table1 val:'||id;
    update table_2 set val='Table2 val:'||id;
    create view v_table_all as
    select * from table_1
    view V_TABLE_ALL created.
    select * from v_table_all;
    ID                     VAL                                                                                                 
    0                      Table1 val:0                                                                                        
    2                      Table1 val:2                                                                                        
    3                      Table1 val:3                                                                                        
    4                      Table1 val:4                                                                                        
    5                      Table1 val:5                                                                                        
    select column_name, updatable, insertable, deletable
    from user_updatable_columns
    where table_name = 'V_TABLE_ALL'
    COLUMN_NAME                    UPDATABLE INSERTABLE DELETABLE
    ID                             YES       YES        YES      
    VAL                            YES       YES        YES      
    update v_table_all set val='XXX changed' where id = 3;
    1 row updated.
    select * from table_1;
    ID                     VAL                                                                                                 
    0                      Table1 val:0                                                                                        
    2                      Table1 val:2                                                                                        
    3                      XXX changed                                                                                         
    4                      Table1 val:4                                                                                        
    5                      Table1 val:5                                                                                        
    rollback;
    select * from table_1;
    ID                     VAL                                                                                                 
    0                      Table1 val:0                                                                                        
    2                      Table1 val:2                                                                                        
    3                      Table1 val:3                                                                                        
    4                      Table1 val:4                                                                                        
    5                      Table1 val:5                                                                                        
    create or replace view v_table_all as
    select * from table_1
    union select * from table_2;
    view V_TABLE_ALL created.
    select * from v_table_all;
    ID                     VAL                                                                                                 
    0                      Table1 val:0                                                                                        
    2                      Table1 val:2                                                                                        
    3                      Table1 val:3                                                                                        
    4                      Table1 val:4                                                                                        
    5                      Table1 val:5                                                                                        
    10                     Table2 val:10                                                                                       
    12                     Table2 val:12                                                                                       
    13                     Table2 val:13                                                                                       
    14                     Table2 val:14                                                                                       
    15                     Table2 val:15  
    select column_name, updatable, insertable, deletable
    from user_updatable_columns
    where table_name = 'V_TABLE_ALL'
    COLUMN_NAME                    UPDATABLE INSERTABLE DELETABLE
    ID                             NO        NO         NO       
    VAL                            NO        NO         NO       
    trying update:
    update v_table_all set val='XXX changed' where id = 3;
    SQL-Fehler: ORA-01732: Datenmanipulationsoperation auf dieser View nicht zulässig
    01732. 00000 -  "data manipulation operation not legal on this view"
    *Cause:   
    *Action:
    drop view v_table_all;
    view V_TABLE_ALL dropped.all is ok before this point.
    now we want create a new materialized view with some query
    create  materialized view v_table_all
    as
    select * from table_1
    union all select * from table_2 ;
    materialized view V_TABLE_ALL created.
    select column_name, updatable, insertable, deletable
    from user_updatable_columns
    where table_name = 'V_TABLE_ALL'
    COLUMN_NAME                    UPDATABLE INSERTABLE DELETABLE
    ID                             YES       YES        YES      
    VAL                            YES       YES        YES       it seems to be ok with update.
    but...
    update v_table_all set val='XXX changed' where id = 3;
    SQL-Fehler: ORA-01732: Datenmanipulationsoperation auf dieser View nicht zulässig
    01732. 00000 -  "data manipulation operation not legal on this view"
    *Cause:   
    *Action:How can solve this issue??
    Any suggestion

    Looks like user_updatable_columns sort of thinks the MV is just a table - I don't know about that...
    An MV on a single table can be updated - I tried that and it works:
    create materialized view mv_table_1 for update
    as
    select * from table_1;I noticed [url http://download.oracle.com/docs/cd/E11882_01/server.112/e16579/advmv.htm#sthref294]examples stating the UNION ALL needs a "marker" so Oracle can know from the data which source table a row in the MV originates from - like this:
    create materialized view v_table_all for update
    as
    select 'T1' tab_id, table_1.* from table_1
    union all
    select 'T2' tab_id, table_2.* from table_2 ;But that also fails (the "marker" requirement was specifically for FAST REFRESH, so it was just a long shot ;-) )
    What are you planning to do?
    <li>Create the MV.
    <li>Update records in the MV - which then is no longer consistent with the source data.
    <li>Schedule a complete refresh once in a while - thereby overwriting/losing the updates in the MV.
    If that is the case, I suggest using a true table rather than an MV.
    <li>Create table t_table_all as select ... .
    <li>Update records in the table - which then is no longer consistent with the source data.
    <li>Schedule a job to delete table and insert into table select ... once in a while - thereby overwriting/losing the updates in the table.
    In other words a kind of "do it yourself MV".
    I cannot see another way at the moment? But perhaps try in the data warehousing forum - the people there may have greater experience with MV's ;-)

  • Issue with union all in sql

    Hi All,
    I have a requirement as below.
    SELECT 'A' AS 'XXX' FROM DUAL
    UNION ALL
    SELECT 'B' AS 'XXX' FROM DUAL
    I need to check in such a way in my second sql query if 'B'='A' then i need to print 'A' else 'B' , means in my second query i need to compare the value of XXX with the first query value of XXX if it is same then i need to print first query's value of XXX or else need to print second queries XXX value.
    Please help me on this

    user13424229 wrote:
    Hi All,
    I have a requirement as below.
    SELECT 'A' AS 'XXX' FROM DUAL
    UNION ALL
    SELECT 'B' AS 'XXX' FROM DUAL
    I need to check in such a way in my second sql query if 'B'='A' then i need to print 'A' else 'B' , means in my second query i need to compare the value of XXX with the first query value of XXX if it is same then i need to print first query's value of XXX or else need to print second queries XXX value.
    Please help me on thisYour quesiton is not very clear, I would suggest you read {message:id=9360002}.
    If you are looking at a way to see the next or previous row from your current row then you can use LEAD or LAG analytical function. They are well documented. You can read all about it there.

  • Order by decode statement with Union all

    Hi
    I use Database Version: Oracle 9.2.0.1.0
    OCI version 9.2
    I try to use order by decode while i have a select base on union and I get en error:
    ORA-01785: ORDER BY item must be the number of a SELECT-list expression
    Here is my code:
    select catalog_type, catalog_id, item_id, item_name
    from items_catalog
    union all
    select catalog_type, catalog_id, organisation_unit_id, organisation_unit_name
    from units_catalog
    order by decode(catalog_type, 1, item_id, organisation_unit_id)
    If I use the decode on a select statement without union, it works.
    What I have to do in order to make it work on union all select?
    Tnx

    Hi,
    Here's a slightly different way:
    COLUMN     sort_key   NOPRINT
    VARIABLE     catalog_type_wanted     VARCHAR2 (5)
    EXEC         :catalog_type_wanted := '4'; 
    SELECT       catalog_id, item_id, item_name
    ,       CASE
               WHEN  :catalog_type_wanted = '1'  THEN  '1'
                                               ELSE  '2'
           END || item_id          AS sort_key
    FROM       items_catalog
          UNION ALL
    SELECT    catalog_id, organisation_unit_id, organisation_unit_name
    ,       CASE
               WHEN  :catalog_type_wanted = '1'  THEN  '2'
                                               ELSE  '1'
           END || organisation_unit_name     AS sort_key
    FROM       units_catalog
    ORDER BY  sort_key
    ;This way guarantees that (for example) 'SHOP50' comes before 'SHOP58', whether or not they are in the first half of the output or the second half.
    Notice that this uses the SQL*Plus COLUMN ... NOPRINT command to hide the sort_key column.
    If you're not using SQL*Plus, then whatever front end you are using may have a similar feature.
    If not, then you can do the UNION in a sub-query, as Daniel did, but do the ORDER BY in the main query (only).

Maybe you are looking for

  • Goods issue on return basis

    Hi, My client wants to issue goods to the employee for testing or demo purpose for specified period (time limit) And wants to taken the report for returnable goods. I want to know that i have create the employee as a vendor or any other solution. In

  • Handling Multiple Host GS ID in SOA 11g B2B

    Hi, Greetings to B2B Gurus !!! We have a requirement to map different Host Group Interchange ID based on Input data and we are getting an error saying that, not able to identify the Trading Partner since the values are same. We have already added bel

  • External data sources and ODBC

    Does Numbers 2009 support connecting to external data sources such as MySQL via ODBC?

  • What is Data Re-initializations ?

    What is Data Re-initializations ? and how can we do in BW system?

  • Password wont do anything on installer for CS5 (MAC)

    When I try installing CS5 to my mac it wont do anything after I input my administrator password. I click the installer, put in my serial number, but once I get to the " Setup wants to make changes. Type your password to allow this." It does nothing b