Union All Function
HI All,
I am trying to make one query in wich i want territory wise sales report but i want to reflect it as territory 1 and its total than territory 2 and its total will union function will give me that result.
So need help.
Thanks-
Mona
Try:
SELECT T2.descript,SUM(T0.DocTotal) 'Total Revenue',SUM(T0.GrosProfit) 'Gross Profit', 100*SUM(T0.DocTotal)/(SELECT SUM(DocTotal)
FROM OINV) '% Total Revenue',100*SUM(T0.GrosProfit)/(SELECT SUM(GrosProfit)
FROM OINV) '% Total Gross Profit'
FROM OINV T0
INNER JOIN OCRD T1 ON T1.CardCode=T0.CardCode
INNER JOIN OTER T2 ON T2.territryID=T1.Territory
GROUP BY T2.descript
UNION ALL
SELECT 'Total',SUM(T0.DocTotal) 'Total Revenue',SUM(T0.GrosProfit) 'Gross Profit', 100,100
FROM OINV T0
INNER JOIN OCRD T1 ON T1.CardCode=T0.CardCode
INNER JOIN OTER T2 ON T2.territryID=T1.Territory
Similar Messages
-
Possible to emulate union all at column level?
The UNION ALL function of Oracle SQL is great for joining two matching results sets into one.
However, is it possible to use a similar approach to do this at column level?
EG:
The following query:
<pre>
select
cods.salesman, sum(cods.net_amount) ordval
from
ifsapp.cust_ord_back_stat cods
where
to_char(cods.statistic_date,'YYYYMMDD') = '20060314'
group by cods.salesman
</pre>
will produce details like:
<pre>
salesman ordval
ARNOTT 100
JONES 15
SMITH 300
</pre>
Showing the balance of orders for each on the 14 March 2006.
Then take the following:
<pre>
select
cods.salesman, sum(cods.net_amount) ordval
from
ifsapp.cust_ord_back_stat cods
where
to_char(cods.statistic_date,'YYYYMMDD') = '20060315'
group by cods.salesman
</pre>
will produce details like:
<pre>
salesman ordval
ARNOTT 120
JONES 5
THOMAS 10
</pre>
Showing the balance of orders for each on the 15 March 2006.
What I want to show is:
<pre>
salesman ordval1 ordval2 diff
ARNOTT 100 120 20
JONES 15 5 10-
SMITH 300 0 300-
THOMAS 0 10 10
</pre>
It seems quite complicated when I think of subqueries etc
ThanksApologies on formatting error. Resolved in some respects!
The UNION ALL function of Oracle SQL is great for joining two matching results sets into one.
However, is it possible to use a similar approach to do this at column level?
EG:
The following query:
select
cods.salesman, sum(cods.net_amount) ordval
from
ifsapp.cust_ord_back_stat cods
where
to_char(cods.statistic_date,'YYYYMMDD') = '20060314'
group by cods.salesmanwill produce details like:
salesman ordval
ARNOTT 100
JONES 15
SMITH 300Showing the balance of orders for each on the 14 March 2006.
Then take the following:
select
cods.salesman, sum(cods.net_amount) ordval
from
ifsapp.cust_ord_back_stat cods
where
to_char(cods.statistic_date,'YYYYMMDD') = '20060315'
group by cods.salesmanwill produce details like:
salesman ordval
ARNOTT 120
JONES 5
THOMAS 10Showing the balance of orders for each on the 15 March 2006.
What I want to show is:
salesman ordval1 ordval2 diff
ARNOTT 100 120 20
JONES 15 5 10-
SMITH 300 0 300-
THOMAS 0 10 10It seems quite complicated when I think of subqueries etc
Thanks -
Inventory on Hand Report - Using Union ALL - need two fields to be part of the group
Hi all,
I have created an Inventory "on Hand" Report that takes the Current Inventory from the Item Entry table and the Sales from Unposted Sales Line table and Transfers in and out from the Unposted Transfer Line table. I have joined the tables
using the UNION ALL function.
My problem is that the Transfer table has two locations whereas the other tables only have one. I am grouping on Location code from the Item Entry table which is equivalent to BOTH Transfer from location and the Transfer to.
As an example, there are 15lbs of inventory for Product A in Location #1 with a transfer out of 15 lbs. The Transfer out is going to Location #2
I don't know how to write the query or set up the group so that it recognizes both the Transfer to and the Transfer From fields
I want the report to look similar to the one below but I can only get it to show one of the locations. Is there some way to use the Union function and have one field in the first table be or equivalent to two fields in another?
Location Code
Item No.
Lbs
Sales Orders
Transfer Out
Transfer In
Available Inventory
Location #1
Product A
15
-15
Location #1
15
-15
Location #2
Product A
15
15
Location #2
15
15Hi Igor,
You can get a custom sort order added to your IP column without the need for a second column.
Consider that the sorting is done strictly left-to-right across a string in the column. The string can be any valid HTML content. So, you could wrap your string within, say, a SPAN tag and add an attribute to that tag that contains the sort order you need before the text that is displayed to the user. As long as the attribute is correctly structured (that is, all instances are of the same length, for example), then sorting will work correctly. For example:
SELECT
'<span title="' || PAD_IP_ADDRESS(IP) || '">' || IP || '</span>' Y
FROM ...Now you need to ensure that the PAD_IP_ADDRESS() function returns the correct values. In IP addresses, you have anything from "0.0.0.0" to "255.255.255.255". To get them to sort "numerically", you need to pad one or two digit numbers to get three digit numbers for each value - so, "0.0.0.0" becomes "000.000.000.000". You could create a function to do this - something like:
CREATE OR REPLACE FUNCTION PAD_IP_ADDRESS
pIP IN VARCHAR2
RETURN VARCHAR2
IS
vIP VARCHAR2(15);
vTEMP APEX_APPLICATION_GLOBAL.VC_ARR2;
vSEP VARCHAR2(1);
BEGIN
vSEP := '';
vIP := '';
vTEMP := APEX_UTIL.STRING_TO_TABLE(pIP,'.');
FOR x IN 1..vTEMP.COUNT
LOOP
vIP := vIP || vSEP || TRIM(TO_CHAR(TO_NUMBER(vTEMP(x)),'000'));
vSEP := '.';
END LOOP;
RETURN vIP;
END;The output from this would look something like:
<span title="001.001.001.001">1.1.1.1</span>
<span title="002.255.255.255">2.255.255.255</span>
<span title="010.001.199.098">10.1.199.098</span>Andy -
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 -
Error while executing UNION ALL query
Hello everyone,
I'm executing the below query on Oracle 9.2.0.8 version.
select hdr.*
from ttl_hdr hdr, ttl_service ser
where hdr.cus_nbr = ser.cus_nbr
and hdr.dn in ('1232','2342',343','343')
union all
select hdr.*
from ttl_hdr_his hdr, ttl_service ser
where hdr.cus_nbr = ser.cus_nbr
and hdr.dn in ('1232','2342',343','343')
and I encounter following error:
ORA-01790: expression must have same datatype as corresponding expression
But instead of * if I'm specifying a list of few columns, it executes the query properly.
Can anybody tell me what the problem is ?
regards,
RossyHi,
All columns in your tables TTL_HDR and TTL_HDR_HIS are not with same data type.
I'm sure you get same error if you specify all columns that * brings.
Specify column names and use conversion function to get data type same to column from both selects.
PS: and I think this is not Application Express related
Br, Jari -
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 thisuser13424229 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. -
Re Creating a chart getting an error with a 'Union All' statement
Hi
I have some data to chart with the following fields;
Product , Jul-08 , Aug-08, Sep-08 etc ...... to Jan-10.
The PRODUCT field is text showing the numerous Product Names
The Jul-08 & other month fields have numbers per product that is to be aggregated for that month & plotted on the line graph.
My SQL to create the first point on the chart is as below;
select null link, PRODUCT label, SUM(JUL-08) "FFF"
from "SCHEMANAME"."TABLENAME"
WHERE PRODUCT = 'FFF'
GROUP by PRODUCT
ORDER BY PRODUCT
This works fine until I want add the second point of this line graph using a 'union all' join as follows;
select null link, PRODUCT label, SUM(JUL_08) "FFF"
from "SCHEMANAME"."TABLENAME"
WHERE PRODUCT = 'FFF'
UNION ALL
select null link, PRODUCT label, SUM(AUG_08) "FFF"
from "SCHEMANAME"."TABLENAME"
WHERE PRODUCT = 'FFF'
I can't work out how I can join the other months on the line graph in one series.
The error is as follows;
1 error has occurred
Failed to parse SQL query:
select null link, PRODUCT label, SUM(OCT_09) "NCDS - STD" from "BI_A_DATA"."CDW_VS_NCDS_CALLS" WHERE PRODUCT = 'NCDS - STD' UNION ALL select null link, PRODUCT label, SUM(NOV_09) "NCDS - LOCAL" from "BI_A_DATA"."CDW_VS_NCDS_CALLS" WHERE PRODUCT = 'NCDS - LOCAL'
ORA-00937: not a single-group group function
Certain queries can only be executed when running your application, if your query appears syntactically correct, you can save your query without validation (see options below query source).
Can anyone assist?
I want a continuous Line Graph that shows all the months from Jul-08 , Aug-08, Sep-08 etc ...... to Jan-10 for the same product.
I will then add other series for the other products, ThanksOK, I thought each month would be separated by the different months in each selct subquery, but I see what you mean.
I'm creating a line graph for various PRODUCTS that has a numeric value for each month, from JUL_08 ..... for a number of months.
I want a LINE graph that shows the different totals each month for that PRODUCT.
The error advises that there are more values in the SELECT statement than the expected and to use Use the following syntax:
SELECT LINK, LABEL, VALUE
FROM ...
I then went on to use the '[ ]' brackets to separate data but this didn't fix the problem.
I've changed the script to suit as per your 'PERIOD' addition but now have the error as per below;
error script
1 error has occurred
Invalid chart query: SELECT null link, PRODUCT label, PERIOD, SUM(ABC) FROM (SELECT null link, PRODUCT, 'JUL_08' PERIOD,SUM(JUL_08)ABC FROM BI_A_DATA.APEX_TEST WHERE PRODUCT = 'ABC' GROUP BY PRODUCT UNION ALL SELECT null link, PRODUCT, 'AUG_08' PERIOD,SUM(AUG_08)ABC FROM BI_A_DATA.APEX_TEST WHERE PRODUCT = 'ABC' GROUP BY PRODUCT UNION ALL SELECT null link, PRODUCT, 'SEP_08' PERIOD,SUM(SEP_08)ABC FROM BI_A_DATA.APEX_TEST WHERE PRODUCT = 'ABC' GROUP BY PRODUCT) GROUP BY link, PRODUCT, PERIOD
Use the following syntax:
SELECT LINK, LABEL, VALUE
FROM ...
Or use the following syntax for a query returning multiple series:
SELECT LINK, LABEL, VALUE1 [, VALUE2 [, VALUE3...]]
FROM ...
LINK URL
LABEL Text that displays along a chart axis.
VALUE1, VALUE2, VALUE3... Numeric columns that define the data values.
Note: The series names for Column and Line charts are derived from the column aliases used in the query.
My script amended;
SELECT null link, PRODUCT label, PERIOD, SUM(ABC)
FROM
(SELECT null link, PRODUCT, 'JUL_08' PERIOD,SUM(JUL_08)ABC
FROM BI_A_DATA.APEX_TEST
WHERE PRODUCT = 'ABC'
GROUP BY PRODUCT
UNION ALL
SELECT null link, PRODUCT, 'AUG_08' PERIOD,SUM(AUG_08)ABC
FROM BI_A_DATA.APEX_TEST
WHERE PRODUCT = 'ABC'
GROUP BY PRODUCT
UNION ALL
SELECT null link, PRODUCT, 'SEP_08' PERIOD,SUM(SEP_08)ABC
FROM BI_A_DATA.APEX_TEST
WHERE PRODUCT = 'ABC'
GROUP BY PRODUCT)
GROUP BY link, PRODUCT, PERIOD -
Sample SQL Query for Creating View
CREATE MATERIALIZED VIEW TRIAL2
PARALLEL 4
BUILD IMMEDIATE
REFRESH COMPLETE
ENABLE QUERY REWRITE
AS */
select maa.INVENTORY_ITEM_ID,maa.ORGANIZATION_ID,maa.SR_INSTANCE_ID from msc_atp_rules ma,
msc_atp_assignments maa
where maa.assignment_type = 3
AND maa.ATP_RULE_ID = ma.RULE_ID
UNION ALL
select maa.INVENTORY_ITEM_ID,maa.ORGANIZATION_ID,maa.SR_INSTANCE_ID from msc_atp_rules ma,
msc_atp_assignments maa
where maa.assignment_type =3
AND maa.ATP_RULE_ID = ma.RULE_ID
Test Syntax
The SQL syntax is valid, however the query is invalid or uses functionality that is not supported.
Declarative query support does not currently include UNION, INTERSECT or MINUS
As a workaround, I created this view in the database and imported it onto jdev. This process worked totally fine. However, the Test Syntax still gives the same error, which means no modifications can be made on Jdev.
Is my conclusion right, or am I missing some procedures that might get the UNIONs working?
Thanks
RajivHi John,
Thanks.
How shall we create xdf then for such MV? Instead of xdf can we have sql script shipped.... or is there any other way of shipping such materialized view... In R12 and 11i (after 11.5.10) we used to ship corresponding xdf but in before 11.5.10 we used to ship sql scripts. -
How can we avoid union all in this query.....
Dear All,
I have a query which has union all.I want a query with the same result without using union all.Can anyone help me?Here is my query.............
SELECT DID,
DM.DISTRICT_DESCRIPTION "DISTRICT_NAME",
MID,
DM.DISTRICT_DESCRIPTION || '(D)' "MANDAL_NAME",
200706,
'SD_OB' "EXP_CAT",
SUM(NVL(AMOUNT,0))-SUM(NVL(AMOUNT1,0)) "AMOUNT" FROM
(SELECT SUBSTR(AC.PCC_INFO_CODE,3,2) "DID", SUBSTR(AC.TRANSACTION_ID,6,2) "MID",NVL(SUM(AMOUNT),0) "AMOUNT", 0 "AMOUNT1"
FROM ACCTD_CLAIMS AC
WHERE TO_CHAR(AC.CLAIM_DATE,'YYYYMM') <= PREV_MONTH(200706)
AND AC.HOA_ID='18 '
AND SUBSTR(AC.TRANSACTION_ID,1,3) <> 'CRR'
GROUP BY SUBSTR(AC.PCC_INFO_CODE,3,2),SUBSTR(AC.TRANSACTION_ID,6,2)
union all
SELECT SUBSTR(AC.PCC_INFO_CODE,3,2) "DID", SUBSTR(AC.TRANSACTION_ID,6,2) "MID",0 "AMOUNT" , NVL(SUM(AMOUNT),0) "AMOUNT1"
FROM ACCTD_CLAIMS AC
WHERE
TO_CHAR(AC.PAY_DATE,'YYYYMM') <= PREV_MONTH(200706)
AND AC.HOA_ID='18'
GROUP BY SUBSTR(AC.PCC_INFO_CODE,3,2), SUBSTR(AC.TRANSACTION_ID,6,2)), DISTRICT_MASTER DM
WHERE DM.DISTRICT_ID=DID
GROUP BY DID, MID, DM.DISTRICT_DESCRIPTION;
Regards,
Krishnadeep.<I want a query with the same result without using union all>
You can write a pipelined function, which will be about ten times the work. Its best to use the simples tools; why don't you want to use UNION ALL since its probably the best answer? -
Using timestamp in union all view
I am having a silly problem with one of my views. It is a union all with two select statements. There is a timestamp(6) in one select but not in the other so I have a to_timestamp(null) to match up the columns.
The problem is that no matter how I code the to_timestamp(null,fmt) the structure of the view is always timestamp(0). I even changed the 2nd select so that it uses a timestamp(6) column. If I create 2 views from both selects they have the correct syntax but as soon as I use a union the timestamp loses it precision.
When I acutally do a select from the view I can still see the milliseconds precision. My real problem occurs in that I have a ref cursor that is of type view_row%rowtype. When I select into the cursor I lose the precision.
Any ideas?
thxUse the cast function to cast the timestamp to timestamp(6)
SQL> create table t
2 ( id number
3 , ts timestamp(6)
4 );
Table created.
SQL> create view v
2 as
3 select id, ts
4 from t
5 union all
6 select 0, cast(to_timestamp(null) as timestamp(6))
7 from dual;
View created.
SQL> desc v
Name Null? Type
ID NUMBER
TS TIMESTAMP(6)
SQL> insert into t
2 values (1,systimestamp);
1 row created.
SQL> select * from v;
ID
TS
1
31-AUG-04 02.28.38.342412 PM
0 -
Hi Guys,
Oracle Version: 10g.
I got a materialized having the following sql. Is there anyway, the SQL can be simplified by removing the unnecessary
aggregate function and group by clause. Any pointers will be highly appreciated. Thanks in advance!
SELECT P.PRD_ID,
D.MKT_ID,
D.FY_WK_END,
D.WK_TAG_CD,
SUM (D.P_QTY) ,
SUM (D.C_QTY) ,
SUM (D.SLS_AMT) ,
SUM (D.E_QTY) ,
SUM (D.CALC) ,
SUM (D.PKG_QTY * P.FCTR) ,
SUM (D.PKG_QTY * P.U_FCTR) ,
SUM(D.PNDS)
FROM ( SELECT P.PRD_ID,
M.MKT_ID,
C.WK_ENDING_DT,
C.WK_TAG_CD,
SUM (D.PKG) AS P_QTY,
SUM (D.BILL) AS C_QTY,
SUM (D.SLS_AMT) AS SLS_AMT,
SUM (D.E_QTY) AS E_QTY,
SUM (D.BILL * P.FCTR) AS CALC,
SUM (D.BILL * BWM.GROSS_WT) AS PNDS
FROM DEL_F D,
PRD_D P,
CUST_D T,
CALD C,
(SELECT MKT_ID,
MKT_CD,
SORG
FROM MKT_M
WHERE SORG = '803'
AND UPPER (GRP_TY) = 'CGS') M,
MV_MAT BWM
WHERE D.PRD_ID = P.PRD_ID
AND D.CUST_ID = T.CUST_ID
AND T.CUST_CD = M.MKT_CD
AND M.SELORG = D.SELORG
AND D.WK_ENDING_DT = C.CAL_DY_DT
AND P.MATL_CD = BWM.MAT
GROUP BY P.PRD_ID,
M.MKT_ID,
C.WK_ENDING_DT,
C.WK_TAG_CD) D,
MV_UP P
WHERE P.FIN_ID = D.PRD_ID
GROUP BY P.PRD_ID,
D.MKT_ID,
D.WK_ENDING_DT,
D.WK_TAG_CD
UNION ALL
SELECT P.PRD_ID,
D.MKT_ID,
D.FY_WK_END,
D.WK_TAG_CD,
SUM (D.PKG_QTY) ,
SUM (D.CASE_QTY) ,
SUM (D.SLS_AMT) ,
SUM (D.EQC_QTY) ,
SUM (D.CALC_QTY) ,
SUM (D.PKG_QTY * P.FCTR) ,
SUM (D.PKG_QTY * P.U_FCTR) ,
SUM(D.PNDS)
FROM ( SELECT P.PRD_ID,
M.MKT_ID,
C.WK_ENDING_DT,
C.WK_TAG_CD,
SUM (D.PKG) AS P_QTY,
SUM (D.BILL) AS C_QTY,
SUM (D.SLS_AMT) AS SLS_AMT,
SUM (D.E_QTY) AS E_QTY,
SUM (D.BILL * P.FCTR) AS CALC,
SUM (D.BILL * BWM.GROSS_WT) AS PNDS
FROM DEL_F D,
PRD_D P,
SELD S,
CALD C,
(SELECT MKT_ID,
MKT_CD,
SORG
FROM MKT_M
WHERE SORG = '803'
AND UPPER (GRP_TY) = 'SR') M,
MV_MAT BWM
WHERE D.PRD_ID = P.PRD_ID
AND D.SLL_ID = S.SLL_ID
AND S.RGN_CD = M.MKT_CD
AND M.SORG = D.SORG
AND D.WK_ENDING_DT = C.CAL_DT
AND P.MATL_CD = BWM.MATL
GROUP BY P.PRD_ID,
M.MKT_ID,
C.WK_ENDING_DT,
C.WK_TAG_CD) D,
MV_UP P
WHERE P.FIN_ID = D.PRD_ID
GROUP BY P.PRD_ID,
M.MKT_ID,
C.WK_ENDING_DT,
C.WK_TAG_CD;SELECT P.PRD_ID,
D.MKT_ID,
D.FY_WK_END,
D.WK_TAG_CD,
SUM (D.P_QTY) ,
SUM (D.C_QTY) ,
SUM (D.SLS_AMT) ,
SUM (D.E_QTY) ,
SUM (D.CALC) ,
SUM (D.PKG_QTY * P.FCTR) ,
SUM (D.PKG_QTY * P.U_FCTR) ,
SUM(D.PNDS)
FROM ( SELECT P.PRD_ID,
M.MKT_ID,
C.WK_ENDING_DT,
C.WK_TAG_CD,
SUM (D.PKG) AS P_QTY,
SUM (D.BILL) AS C_QTY,
SUM (D.SLS_AMT) AS SLS_AMT,
SUM (D.E_QTY) AS E_QTY,
SUM (D.BILL * P.FCTR) AS CALC,
SUM (D.BILL * BWM.GROSS_WT) AS PNDS
FROM DEL_F D,
PRD_D P,
CUST_D T,
CALD C,
(SELECT MKT_ID,
MKT_CD,
SORG
FROM MKT_M
WHERE SORG = '803'
AND UPPER (GRP_TY) = 'CGS') M,
MV_MAT BWM
WHERE D.PRD_ID = P.PRD_ID
AND D.CUST_ID = T.CUST_ID
AND T.CUST_CD = M.MKT_CD
AND M.SELORG = D.SELORG
AND D.WK_ENDING_DT = C.CAL_DY_DT
AND P.MATL_CD = BWM.MAT
GROUP BY P.PRD_ID,
M.MKT_ID,
C.WK_ENDING_DT,
C.WK_TAG_CD) D,
MV_UP P
WHERE P.FIN_ID = D.PRD_ID
GROUP BY P.PRD_ID,
D.MKT_ID,
D.WK_ENDING_DT,
D.WK_TAG_CD
UNION ALL
SELECT P.PRD_ID,
D.MKT_ID,
D.FY_WK_END,
D.WK_TAG_CD,
SUM (D.PKG_QTY) ,
SUM (D.CASE_QTY) ,
SUM (D.SLS_AMT) ,
SUM (D.EQC_QTY) ,
SUM (D.CALC) ,
SUM (D.PKG_QTY * P.FCTR) ,
SUM (D.PKG_QTY * P.U_FCTR) ,
SUM(D.PNDS)
FROM ( SELECT P.PRD_ID,
M.MKT_ID,
C.WK_ENDING_DT,
C.WK_TAG_CD,
SUM (D.PKG) AS P_QTY,
SUM (D.BILL) AS C_QTY,
SUM (D.SLS_AMT) AS SLS_AMT,
SUM (D.E_QTY) AS E_QTY,
SUM (D.BILL * P.FCTR) AS CALC,
SUM (D.BILL * BWM.GROSS_WT) AS PNDS
FROM DEL_F D,
PRD_D P,
SELD S,
CALD C,
(SELECT MKT_ID,
MKT_CD,
SORG
FROM MKT_M
WHERE SORG = '803'
AND UPPER (GRP_TY) = 'SR') M,
MV_MAT BWM
WHERE D.PRD_ID = P.PRD_ID
AND D.SLL_ID = S.SLL_ID
AND S.RGN_CD = M.MKT_CD
AND M.SORG = D.SORG
AND D.WK_ENDING_DT = C.CAL_DY_DT
AND P.MATL_CD = BWM.MAT
GROUP BY P.PRD_ID,
M.MKT_ID,
C.WK_ENDING_DT,
C.WK_TAG_CD) D,
MV_UP P
WHERE P.FIN_ID = D.PRD_ID
GROUP BY P.PRD_ID,
M.MKT_ID,
C.WK_ENDING_DT,
C.WK_TAG_CD;Hi Hoek, Etbin:
Thanks for the replies. As you can see above both the SQL, SQL1 UNION ALL SQL2 are almost alike except at a few places.
1. Tables: CUST_D and SELD
2. Filtering code for MKT_M
3. JOIN conditions of INLINE VIEWS of SQL1 and SQL2.
Problem 1: SQL1 and SQL2 has SUM function which aggregates the column that comes from the inline view when "WHERE P.FIN_ID = D.PRD_ID",
this join condition is satisfied. I am thinking since outer SQL are aggregating the same columns which are aggregated in the inline view for example -
SUM (D.CALC) <- This guy is in outer sql of both SQL1 and SQL2.
SUM (D.BILL * P.FCTR) AS CALC <- This guy is in inner sql of SQL1 and SQL2.
Does that mean, I can remove the SUM from outer sql and just write D.CALC?
Can I do the same things for other SUMs too?
OR
Can I remove the aggregation from inner sql i.e. inline view e.g. SUM (D.BILL * P.FCTR) AS CALC becomes just D.BILL * P.FCTR and then aggregate it in
outer sql?
Problem 2. If the above things can be done than instead of grouping bys twice in SQL1 and SQL2, we can group by only once. Will it give the same result as the original SQL?
Problem 3. Any other way of writing the sql in a simplified way? Can it be made simple?
Please advice.
Thanks in advance!
Edited by: abyss on Mar 12, 2011 9:41 AM
Edited by: abyss on Mar 12, 2011 9:43 AM
Edited by: abyss on Mar 12, 2011 9:43 AM
Edited by: abyss on Mar 12, 2011 9:44 AM -
Materialized view - REFRESH FAST ON COMMIT - UNION ALL
In a materialized view which uses REFRESH FAST ON COMMIT to update the data, how many UNION ALL can be used.
I am asking this question because my materialized view works fine when there are only 2 SELECT statement (1 UNION ALL).
Thank you.In a materialized view which uses REFRESH FAST ON COMMIT to update the data, how many UNION ALL can be used.As far as I remember you can have 64K UNIONized selects.
I am asking this question because my materialized view works fine when there are only 2 SELECT statement (1 UNION ALL).Post SQL that does not work. -
OAF Export button fetching data in one column - view object using union all
Dear All,
Export button showing data in one column from view object,
View object is based on mulitple queries with union all ,
Please let me know the solution for this issue.
Thanks
Maheswara RajuMaheswara Raju,
As per my understanding you are not able to export all the View Attribute using export Button. Only the attribute which is used with the item/region will get exported.
There are few work around in case if you want to export the column without showing on OAF Page. Let me know.
Cheers
Gyan -
I want to check all functions of PCI 6534.I have read the user manual..I have some memory related questions.Please help me for that.
1.)If i am using the continuous output mode.and the size of generated data is less than 32 MB.If i want to preload the memory,what should i do?I want that first of all i load all my data to onboard memory & then i want to make start the transfer between 6534 & peripheral.Is it possible?As per me it should be.Plz tell me how should i do this?I think that in normal procedure the transfer between 6534-peripheral & outputting data from pc buffer to onboard memory works parallely.But i don't want this.Is it poss
ible?
(2).Similarly in finite input operation(pattern I/O) is it possible to preload the memory and then i read it?Because i think that the PC memory will be loaded automatically when 6534 acquires the data and then when we use DIO read vi the pc buffer data will be transferred to application buffer.If this is true,i do not want this.Is it possible?
(3) One more question is there if i am using normal operation onboard memory will be used bydefault right?Now if i want to use DMA and if i have data of 512 bytes to acquire.How will it work and how should i do it?Please tell me the sequence of operations.As per my knowledge in normal DMA operation we have 32 Bytes FIFO is there so after acquisition of 32 bytes only i can read it.How it will known to me that 32 bytes acquisition is complete?Next,If i want to acquire each byte separately using DMA interrupts what should i do?Provide me the name of sourse from which i can get details about onboard memory & DMA process of 6534 specifically
(4).In 6534 pattern Input mode,if i want to but only 10 bits of data.and i don't want to waste any data line what should i do?Hi Vishal,
I'll try to answer your questions as best I can.
1) It is definitely possible to preload data to the 32MB memory (per group) and start the acquisition after you have preloaded the memory. There are example programs on ni.com/support under Example Code for pattern generation and the 6534 that demonstrate which functions to use for this. Also, if your PC memory buffer is less than 32MB, it will automatically be loaded to the card. If you are in continuous mode however, you can choose to loop using the on-board memory or you can constantly be reading the PC memory buffer as you update it with your application environment.
2) Yes, your data will automatically be loaded into the card's onboard memory. It will however be transferred as quickly as possible to the DMA FIFO on the card and then transferred to the PC memory buffer through DMA. It is not going to wait until the whole onboard memory is filled before it transfers. It will transfer throughout the acquisition process.
3) Vishal, searching the example programs will give you many of the details of programming this type of application. I don't know you application software so I can't give you the exact functions but it is easiest to look at the examples on the net (or the shipping examples with your software). Now if you are acquiring 512 bytes of data, you will start to fill your onboard memory and at the same time, data will be sent to the DMA FIFO. When the FIFO is ready to send data to the PC memory buffer, it will (the exact algorithm is dependent on many things regarding how large the DMA packet is etc.).
4) If I understand you correctly, you want to know if you waste the other 6 bits if you only need to acquire on 10 lines. The answer to this is Yes. Although you are only acquiring 10 bits, it is acquired as a complete word (16bits) and packed and sent using DMA. You application software (NI-DAQ driver) will filter out the last 6 bits of non-data.
Hope that answers your questions. Once again, the example code on the NI site is a great place to start this type of project. Have a good day.
Ron -
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 suggestionLooks 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 ;-)
Maybe you are looking for
-
Add to chart button in personalized mail
Hi, Can anybody give me suggestion on how to insert an Add to chart button in a personalized html mail. There need to be functionality behind so that the customer are logged in when he presses the button. Thanks in advance. Regards Camilla
-
Backup Assistant Online Access
I installed Backup Assistant on my wife's phone. The app says that her numbers were backed up. I want to use the online assistant and link this to her Gmail account. After logging into my Verizon account, I select her phone and click on Backup Assist
-
Brightness graphic is corrupted
I recently noticed the graphic that displays the screen brightness is corrupted. The screen brightness still works correctly though. Should I try to get this fixed? I'm thinking it doesn't affect anything important. Yosemite 10.10.1 on a 2013 Macbook
-
When setting up Keychain, it requested a phone
When setting up Keychain, it requested a phone number to text a code to. I gave a landline phone # which does not give text messages. Consequently when I try to get into keychain it wants the texted code, which I do not have. Is there a way to res
-
Can someone please tell me what is the most common and best delimiter character (or string)(except "\n", "\t", " ", etc. )used in Java?? Thank you.