Union question
HelloI created for the quarter, month, week one day invite here.
SQL are
the SQL code:
SELECT CASE WHEN 1 = 0 THEN TMP_VAC. "" Activity ID "ANOTHER"quarter"to the END"Dashboard ".
UNION
SELECT CASE WHEN 1 = 0 THEN TMP_VAC. "" Activity ID "OTHER"current month"end"Dashboard ".
UNION
SELECT CASE WHEN 1 = 0 THEN TMP_VAC. "" Activity ID "ELSE 'Current week' the end 'Dashboard '.
UNION
SELECT CASE WHEN 1 = 0 THEN TMP_VAC. "" The activity ID ' ELSE 'Day' to the END 'Dashboard '.
I get the error here.
Error codes: OPR4ONWY:U9IM8TAC:OI2DL65P:OI2DL65P
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 59019] All the input stream for the Union operator should have the same number of columns and the Union compatible data types. (HY000)
Publ. SQL: {call NQSGetQueryColumnInfo ("SELECT CASE WHEN 1 = 0 THEN TMP_VAC." Activity ID"OTHER"current quarter"end 'FTOPTY dashboard' UNION SELECT CASE WHEN 1 = 0 THEN TMP_VAC. "" Activity ID "OTHER"current month"the end 'FTOPTY dashboard' UNION SELECT CASE WHEN 1 = 0 THEN TMP_VAC. "" Activity ID "ANOTHER"week"to the END 'FTOPTY dashboard' UNION SELECT CASE WHEN 1 = 0 THEN TMP_VAC. "" Activity ID "ANOTHER 'day', MV_IW_EMP_HIERARCHY. (» Nom responsable"DELEDE"Tableau de bord FTOPTY» ')}
Issued SQL: SELECT BOX WHEN 1 = 0 THEN TMP_VAC. "" Activity ID "ANOTHER"quarter"to the END 'FTOPTY dashboard' UNION SELECT CASE WHEN 1 = 0 THEN TMP_VAC. "" Activity ID "OTHER"current month"the end 'FTOPTY dashboard' UNION SELECT CASE WHEN 1 = 0 THEN TMP_VAC. "" Activity ID "ELSE"Current week"the end 'FTOPTY dashboard' UNION SELECT CASE WHEN 1 = 0 THEN TMP_VAC. "" Activity ID "ELSE 'Day', MV_IW_EMP_HIERARCHY. "" Manager name "of the"FTOPTY dashboard.
Hi user,
Replace the TMP_VAC. "Activity ID with a column of type char var
Thank you
Saichand.v
Tags: Business Intelligence
Similar Questions
-
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.
-
Need help for the Partition of PL/SQL query for a question
Hi all
I'm running on a question that I'm not able to get the desired result. I would appreciate if one of you experts can help resolve this.SQL * more: Production of release 11.2.0.1.0 game 4 Feb 09:31:26 2016
Copyright (c) 1982, 2010, Oracle. All rights reserved.Connected to:
Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production
With partitioning, OLAP, Data Mining and Real Application Testing options
with t as)
Select 1 numero_enregistrement, Student_ID 123, nvl (trim (01), 'NULL') like Item_id, 'ITEM_ID_01' FIELD_NAME Union double all the
Select 1 numero_enregistrement, Student_ID 123, nvl (trim(' '), 'NULL') like Item_id, 'ITEM_ID_02' FIELD_NAME Union double all the
Select 1 numero_enregistrement, Student_ID 123, nvl (trim(' '), 'NULL') like Item_id, 'ITEM_ID_03' FIELD_NAME Union double all the
Select 1 numero_enregistrement, Student_ID 123, nvl (trim(' '), 'NULL') like Item_id, 'ITEM_ID_04' FIELD_NAME Union double all the
Select 1 numero_enregistrement, Student_ID 123, nvl (trim(' '), 'NULL') like Item_id, 'ITEM_ID_05' FIELD_NAME Union double all the
Select 1 numero_enregistrement, Student_ID 123, nvl (trim(' '), 'NULL') like Item_id, 'ITEM_ID_06' FIELD_NAME Union double all the
Select 2 numero_enregistrement, Student_ID 123, nvl (trim('01'), 'NULL') like Item_id, 'ITEM_ID_01' FIELD_NAME Union double all the
Select 2 numero_enregistrement, Student_ID 123, nvl (trim('02'), 'NULL') like Item_id, 'ITEM_ID_02' FIELD_NAME Union double all the
Select 2 numero_enregistrement, Student_ID 123, nvl (trim('03'), 'NULL') like Item_id, 'ITEM_ID_03' FIELD_NAME Union double all the
Select 2 numero_enregistrement, Student_ID 123, nvl (trim('01'), 'NULL') like Item_id, 'ITEM_ID_04' FIELD_NAME Union double all the
Select 2 numero_enregistrement, Student_ID 123, nvl (trim('01'), 'NULL') like Item_id, 'ITEM_ID_05' FIELD_NAME Union double all the
Select 2 numero_enregistrement, Student_ID 123, nvl (trim('02'), 'NULL') like Item_id, 'ITEM_ID_06' double FIELD_NAME)
SELECT distinct COUNT (*) OVER (PARTITION BY numero_enregistrement ORDER BY numero_enregistrement) REC_COUNT, numero_enregistrement, STUDENT_ID, ITEM_ID, Field_Name FROM t
where ITEM_ID = 'NULL '.I get the following result.
NUMERO_ENREGISTREMENT ITEM_ID FIELD_NAME STUDENT_ID REC_COUNT
5 1 123 NULL ITEM_ID_02
5 1 123 NULL ITEM_ID_03
5 1 123 NULL ITEM_ID_04
5 1 123 NULL ITEM_ID_05
5 1 123 NULL ITEM_ID_06
My desired output isRec_COUNT Student_ID ITEM_ID FIELD_NAME numero_enregistrement
5 1 123 NULL ITEM_ID_02, ITEM_ID_03, ITEM_ID_04, ITEM_ID_04, ITEM_ID_05Thanks in advance
Rajesh
Hi, Renon,
Thanks for posting the sample data and results; It is very useful.
Be sure to explain exactly how you get these results from these data. There are many different reasons you may have, that all happen to produce the same results with the sample data you posted, but will get different results with other data sets.
This looks like a job for aggregate (including the LISTAGG) functions and GROUP BY, not for functions, analytical and PARTITION BY
-
How to filter records in a UNION ALL query
Hi all
I have only one requirement to filter records in a query UNION all. If we do not all matching records to one of the union, all question them.
create table test_1(n1 number,n2 number,n3 number) insert into test_1 values(1,2,3); insert into test_1 values(11,22,33); insert into test_1 values(55,66,77); Case-1 : SELECT N1,N2,N3 FROM TEST_1 WHERE N2=2 UNION ALL SELECT N1,N2,N3 FROM TEST_1 WHERE N3=3 Output is : This is desired output(so we are good) 1,2,3 1,2,3 Case 2 : SELECT N1,N2,N3 FROM TEST_1 WHERE N2=22 UNION ALL SELECT N1,N2,N3 FROM TEST_1 WHERE N3=44 Output : (Here is the problem: If we don't have matching records for anyone union all query we don't want any records) Output is coming : 11,22,33 Out put : No Records (We want this output.)
I hope I have given the clear example of my requirement.
Thank you.
with
test_1 as
(select 1 n1, n2 2, n3 3 of all the double union)
Select 11,22,33 from all the double union
Select double 55,66,77
)
Select the n1, n2, n3
from (select n1, n2, n3
of test_1
where n2 =: n2
Union of all the
Select the n1, n2, n3
of test_1
where = n3: n3
)
where exists (select null from test_1 where n2 =: n2)
and it exists (select null from test_1 where = n3: n3)
Concerning
Etbin
-
Oracle version = 10g
Hi gurus
I have the sample data and I want to order this that data down so I use the multiple case statement, my question is that is a smart way to do the same task without using the multiple case statement, see below
Examples of data
WITH AS A REFERENCE
(
SELECT 1000 TM, 'A' am_pm OF DOUBLE UNION ALL
SELECT 100, 'P' FROM DUAL UNION ALL
SELECT 900 DUAL UNION ALL ' P'
SELECT 500, 'A' FROM DUAL UNION ALL
SELECT 920, 'P' FROM DUAL UNION ALL
SELECT 345, 'P' FROM DUAL UNION ALL
SELECT 230, 'A' FROM DUAL UNION ALL
SELECT 1230, 'A' FROM DUAL UNION ALL
SELECT 444, 'A' FROM DUAL UNION ALL
SELECT 500, 'P' FROM DUAL UNION ALL
SELECT 1030, 'A' FROM DUAL UNION ALL
SELECT 300, 'P' FROM DUAL UNION ALL
SELECT 333, 'P' FROM DUAL UNION ALL
SELECT 555, 'P' FROM DUAL UNION ALL
SELECT 1200, 'A' FROM DUAL UNION ALL
SELECT 100, 'A' FROM DUAL UNION ALL
SELECT 900 DUAL UNION ALL ' A'
SELECT 200, 'P' FROM DUAL UNION ALL
SELECT 323, 'P' FROM DUAL UNION ALL
SELECT 800, 'A' FROM DUAL UNION ALL
SELECT 236, 'A' FROM DUAL UNION ALL
SELECT 1100, 'A' FROM DUAL UNION ALL
SELECT 400, 'P' FROM DUAL UNION ALL
SELECT 200, 'A' FROM DUAL UNION ALL
SELECT 222, 'P' FROM DUAL UNION ALL
SELECT 1145, 'A' FROM DUAL UNION ALL
SELECT 1200, 'P' FROM DUAL UNION ALL
SELECT 930, DUAL UNION ALL ' A'
SELECT 130, 'P' OF THE DOUBLE
)
SELECT TM, AM_PM, BOX WHEN AM_PM = 'P' AND TM AS 12% ' THEN TM
WHEN AM_PM = 'P' AND TM AS 1% ' THEN TO_NUMBER(13||) SUBSTR (TM, 2, 3))
WHEN AM_PM = 'P' AND TM AS 2% ' THEN TO_NUMBER(14||) SUBSTR (TM, 2, 3))
WHEN AM_PM = 'P' AND TM AS 3% ' THEN TO_NUMBER(15||) SUBSTR (TM, 2, 3))
WHEN AM_PM = 'P' AND TM 4% ' THEN TO_NUMBER(16||) SUBSTR (TM, 2, 3))
WHEN AM_PM = 'P' AND TM 5% ' THEN TO_NUMBER(17||) SUBSTR (TM, 2, 3))
WHEN AM_PM = 'P' AND TM AS 6% ' THEN TO_NUMBER(18||) SUBSTR (TM, 2, 3))
WHEN AM_PM = 'P' AND TM AS 7% ' THEN TO_NUMBER(19||) SUBSTR (TM, 2, 3))
WHEN AM_PM = 'P' AND TM AS 8% ' THEN TO_NUMBER(20||) SUBSTR (TM, 2, 3))
WHEN AM_PM = 'P' AND TM AS 9% ' THEN TO_NUMBER(21||) SUBSTR (TM, 2, 3))
WHEN AM_PM = 'P' AND TM AS 10% ' THEN TO_NUMBER(22||) SUBSTR (TM, 2, 3))
WHEN AM_PM = 'P' AND TM AS 11% ' THEN TO_NUMBER(23||) SUBSTR (TM, 2, 3))
ANOTHER TM
END FORMATED_RESULT
REFERENCE
ORDER BY FORMATED_RESULT DESC;
Result
TM, AM_PM, FORMATED_RESULT
920 P 2120
900 P 2100
555 P 1755
500 1700 P
400 P 1600
345 P 1545
333 P 1533
323 P 1523
300 P 1500
222 P 1422
200 P 1400
130 P 1330
100 P 1300
1230 1230 A
1200 1200 A
1200 P 1200
A 1145 1145
1100 1100 A
1030 1030 A
1000A 1000
930 930 A
900 A 900
800 TO 800
500A 500
444 A 444
236 A 236
230 A 230
200A 200
100A 100
Concerning
MUT
Hello
Mitchels wrote:
If I can add a colon (:) in the meantime?.) Thank you
Sure. If you have a NUMBER as 145, and you want to display it as ' 01:45 ', you can use
To_char (n, 'FM00G00', 'NLS_NUMERIC_CHARACTERS ='.: "')
-
Anlytical &; Windowing function logic question
All,
Last question, I promise you
I have often wondered why the below SQL never works how I think,You would think he would return the average value on Monday and Tuesday, according to the partitioning parameters (i.e. the ddate + 1 offset), but it doesn't! He only brings the average for Monday.
Anyone know why?
For the query wait below:
1 av_measure_value_mon = 5 (which does)
2 av_measure_value_tue = 6 (which it doesn't not it returns 5 (of Monday))
WITH tblData AS ( SELECT 1 AS measure_value, TO_DATE('01/01/2015', 'DD/MM/YYYY') AS ddate FROM DUAL UNION ALL -- Thu SELECT 2, TO_DATE('02/01/2015', 'DD/MM/YYYY') FROM DUAL UNION ALL -- Fri SELECT 3, TO_DATE('03/01/2015', 'DD/MM/YYYY') FROM DUAL UNION ALL -- Sat SELECT 4, TO_DATE('04/01/2015', 'DD/MM/YYYY') FROM DUAL UNION ALL -- Sun SELECT 5, TO_DATE('05/01/2015', 'DD/MM/YYYY') FROM DUAL UNION ALL -- Mon SELECT 6, TO_DATE('06/01/2015', 'DD/MM/YYYY') FROM DUAL UNION ALL -- Tue SELECT 7, TO_DATE('07/01/2015', 'DD/MM/YYYY') FROM DUAL UNION ALL -- Wed SELECT 1, TO_DATE('08/01/2015', 'DD/MM/YYYY') FROM DUAL UNION ALL -- Thu SELECT 2, TO_DATE('09/01/2015', 'DD/MM/YYYY') FROM DUAL UNION ALL -- Fri SELECT 3, TO_DATE('10/01/2015', 'DD/MM/YYYY') FROM DUAL UNION ALL -- Sat SELECT 4, TO_DATE('11/01/2015', 'DD/MM/YYYY') FROM DUAL UNION ALL -- Sum SELECT 5, TO_DATE('12/01/2015', 'DD/MM/YYYY') FROM DUAL -- Mon ) SELECT ddate, TO_CHAR(ddate, 'Dy') AS dday, av_measure_value_mon, av_measure_value_tue FROM ( SELECT ddate, ROUND(AVG(measure_value) OVER ( PARTITION BY TO_CHAR(ddate, 'Dy')), 2) AS av_measure_value_mon, ROUND(AVG(measure_value) OVER ( PARTITION BY TO_CHAR(ddate + 1, 'Dy')), 2) AS av_measure_value_tue FROM tblData ) WHERE ddate = TO_DATE('12/01/2015', 'DD/MM/YYYY') ;
Hello
Analytic functions, perhaps not the best solution for this problem.
For this problem, you might be better off using the aggregate AVG, not the analytical function, as this function:
WITH got_avg AS
(
SELECT TO_CHAR (ddate, "Dy") AS the dy
ROUND (AVG (measure_value)
2
) AS avg_measure_value
OF tbldata
GROUP OF TO_CHAR (ddate, "Dy")
)
SELECT t.ddate
, TO_CHAR (t.ddate, 'Dy') AS dy
a0.avg_measure_value AS avg_today
a1.avg_measure_value AS avg_tomorrow
OF tbldata t
JOIN got_avg ON a0.dy = TO_CHAR (t.ddate, 'Dy') a0
LEFT OUTER JOIN got_avg ON a1.dy a1 = TO_CHAR (t.ddate + 1, "Dy")
WHERE t.ddate = TO_DATE (December 1, 2015 ', "DD/MM/YYYY")
;
-
I have problem with value NULL when the use CASE statement please help this question
I have problem with value NULL when the use CASE statement please help this question
Table: digital_val
SNO cl C2
1 San1 11
2 22 San2
Actual result: expected to A B
A B 11 22
11 NULL
22 NULL
query:
Select case when c1 = "san1" then c2,.
case If c1 = "san2" then c2 B
of digital_val
I'm more curious why, when you select 2 rows, you expect a result of row?
WITH digital_val
AS (SELECT 1 AS 'Sno', 'San1"C1, c2 FROM DUAL 11)
UNION ALL
2 SELECT AS 'Sno', 'San2"C1, c2 FROM DUAL 22)
SELECT CASE WHEN c1 is "San1" THEN END AS A c2.
CASE WHEN c1 = "San2" THEN END AS B c2
OF digital_val;
With no other input, if you select 2 rows, you get 2 rows. One of the other solutions use a max function, but is this really what you want, does not specify?
-
Lack of question Expression with I$ as he attempted to charge incr
Hi friends,
Im trying to do an incr charge using the incremental update of the IKM oracle. When it im running the interface im getting lack expression in I$ table.
I have two tables with same as columns below and im doing the union transformation to load the data of my two tables (table 1 and table 2) at my target table
Table 1
A
B
C
D
Table 2
A
B
C
D
In doing so I need to run an incr load strategy to my target table... but it translates into lack of question expression with I$ table.
That's why I will not hold a key column in the table with control flow as false target.
How to solve this problem.
Kind regards
Saro
Your unique key must be a column or combination of columns of the source, or how the process to identify the lines, lines that day to be the target! This is why you are getting the error. So just follow these rules when you use the incremental update:
(1) do not try one generate a new column on the target which does not exist in the source (you can do this, but it is not the key used for the update)
(2) select a single column or a combination of columns found in the source text and target that will uniquely identify the key to update records
-
More on my table of full scan question...
Ok. Apology. start one new thread, like other a receipt very complicated... If anyone can help Id be very grateful, because this results in a significant performance problem...
XE 11.2
Re this query:
Select ENTITY_BUDGET_CAT,
Sum (actual) real by
de)
Select Br ENTITY_BUDGET_CAT_ID as ENTITY_BUDGET_CAT,
sum (br. BRI_CREDIT) under the real name
from: br bri_recon
Group of BR. ENTITY_BUDGET_CAT_ID
)
where ENTITY_BUDGET_CAT = (SELECT "EBC". (' ' ID ' FROM 'ENTITY_BUDGET_CAT' "EBC" WHERE 'ENTITY_ID' = 55)
ENTITY_BUDGET_CAT group
The query results in a table full of BRI_RECON scan, even if there is an index on BR. ENTITY_BUDGET_CAT_ID... If I put the where conditition on the inner circle question it works fine.
The void, select retrieve entity_budget_cat on where clause returns a single value.
If I replace the subselect statement to get the entity_budget_cat with a literal value, it uses the index on ENTITY_BUDGET_CAT and is much faster with a much lower cost.
If I remove the sum (actual) external and just retrieve the value and no group, it also uses a sweep of indexes on the inner query on BRI_RECON.
I need instruction in this format because its share actually well expand with unions comprising the sum of 4 tables, then later adds the value of the outer query to retrieve a single value by group of... The docs say that the filter must be passed to any SQL internally, but everything Ive tried to change the query, but leave the internal SQL without a where clause clause and apply it on the outer query. (as I would a view) translates into a full table scan.
Here is a simple example of the view I have as an example of how the larger view needs to look for tables of the amount and return a single sum by group...
Create union_sum_view like)
Select sum (a) as a 'b' b
de)
Select nvl (sum (2), 0) as a 'b' of the double
Union of all the
Select nvl (sum (2), 0) as a 'b' of the double
)
Group by 'b '.
)
Select * from union_sum_view where b = (select "b" double)
Ive tried to put a hint about it, and it doesn't seem to make a difference...
Ive looked full statistics on the diagram too...
So my question is: what is causing the full table scan (which is clearly much less effective). And given that I need to build a view in this way, how can I change to use an index in this format, or what I do to make it work... All variants and the traces are below...
Select ENTITY_BUDGET_CAT,
Sum (actual) real by
de)
Select Br ENTITY_BUDGET_CAT_ID as ENTITY_BUDGET_CAT,
sum (br. BRI_CREDIT) under the real name
from: br bri_recon
Group of BR. ENTITY_BUDGET_CAT_ID
)
where ENTITY_BUDGET_CAT = (SELECT "EBC". (' ' ID ' FROM 'ENTITY_BUDGET_CAT' "EBC" WHERE 'ENTITY_ID' = 55)
ENTITY_BUDGET_CAT group
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time | --------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | 230. 3910 | 3335 (3) | 00:00:41 | | 1. HASH GROUP BY. 230. 3910 | 3335 (3) | 00:00:41 | |* 2 | VIEW | 230. 3910 | 3333 (3) | 00:00:40 | | 3. HASH GROUP BY. 230. 1610. 3333 (3) | 00:00:40 | | 4. TABLE ACCESS FULL | BRI_RECON | 589K | 4031K | 3287 (2) | 00:00:40 | | 5. TABLE ACCESS BY INDEX ROWID | ENTITY_BUDGET_CAT | 1. 8. 2 (0) | 00:00:01 | |* 6 | INDEX RANGE SCAN | ENTITY_BUDGET_CAT_ENTITY_IDX1 | 1 | | 1 (0) | 00:00:01 | --------------------------------------------------------------------------------------------------------------- Information of predicates (identified by the operation identity card): --------------------------------------------------- 2 - filter("ENTITY_BUDGET_CAT"= (SELECT "EBC".")) ID""ENTITY_BUDGET_CAT""EBC"WHERE 'ENTITY_ID' = 55)) 6 - access ("ENTITY_ID" = 55) Select ENTITY_BUDGET_CAT,
Sum (actual) real by
de)
Select Br ENTITY_BUDGET_CAT_ID as ENTITY_BUDGET_CAT,
sum (br. BRI_CREDIT) under the real name
from: br bri_recon
Group of BR. ENTITY_BUDGET_CAT_ID
)
where ENTITY_BUDGET_CAT = (382)
ENTITY_BUDGET_CAT group
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time | ---------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | 1. 17. 54 (0) | 00:00:01 | | 1. GROUP SORT BY NOSORT | 1. 17. 54 (0) | 00:00:01 | | 2. VIEW | 1. 17. 54 (0) | 00:00:01 | | 3. GROUP SORT BY NOSORT | 1. 7. 54 (0) | 00:00:01 | | 4. TABLE ACCESS BY INDEX ROWID | BRI_RECON | 808 | 5656. 54 (0) | 00:00:01 | |* 5 | INDEX RANGE SCAN | BRI_RECON_IDX_EBC | 808 | 4 (0) | 00:00:01 | ---------------------------------------------------------------------------------------------------- Information of predicates (identified by the operation identity card): --------------------------------------------------- 5 - access("BR".") ENTITY_BUDGET_CAT_ID "= 382) Richard Legge wrote:
The void, select retrieve entity_budget_cat on where clause returns a single value.
If I replace the subselect statement to get the entity_budget_cat with a literal value, it uses the index on ENTITY_BUDGET_CAT and is much faster with a much lower cost.
Because the query runs faster when you use literal is because Oracle merges internal queries and views, so that it looks to below.
Select Br ENTITY_BUDGET_CAT_ID as ENTITY_BUDGET_CAT
sum (br. BRI_CREDIT) under the real name
from: br bri_recon
where br. ENTITY_BUDGET_CAT_ID =
Group of BR. ENTITY_BUDGET_CAT_ID
However when a subquery is used, as in the column ENTITY_BUDGET_CAT - the subquery must be run before the outer query can send more data, so that the outer query to only return results that match records based on the subquery.
Richard Legge wrote:
I need instruction in this format because its share actually well expand with unions comprising the sum of 4 tables, then later adds the value of the outer query to retrieve a single value by group of...
Maybe you should re - write the query as follows so that the optimizer would get the opportunity to merge the view and give you better performance...
Select entity_budget_cat
, sum (actual) real by
from (select br.entity_budget_cat_id as entity_budget_cat
, sum (br.bri_credit) real by
from: br bri_recon
Br.entity_budget_cat_id group
) a1
, (select ebc.id from entity_budget_cat where entity_id = 55 ebc) b1
where a1.entity_budget_cat = b1.id
A1.entity_budget_cat group;
or just... would...
Select entity_budget_cat_id entity_budget_cat
, sum (actual) real by
bri_recon a1
, (select ebc.id from entity_budget_cat where entity_id = 55 ebc) b1
where a1.entity_budget_cat_id = b1.id
A1.entity_budget_cat_id group
-
2 questions about Calendar implementations (APEX 5.0)
Hello
I use 5 APEX on Oracle Express Edition.
I created a calendar that displays data in multiple tables.
Here is the query to simplify:
Select an evt, b datevt
FROM table1
Union
Select evt c, datevt d
from table2
Union
Select e TTE, f datevt
table 3;
I need to put up a link in the calendar on these data that display a modal page where users can see the details and update the data.
I have seen that it is possible to create a link on the calendar, but this link is considered to be a single page. In my case, I need to 3 different links, one per page.
Another question: I want to display these data on the calendar with a color that depends on the table. For example, blue for the first table, the Red during the second and the Orange for the third.
You have a solution that helps me implement those needs?
You will appreciate any help, and sorry if these questions have already addressed the Forum.
Thanks in advance
Vincent
2979122 wrote:
Please update your forum profile with a recognizable username instead of "2979122": Video tutorial how to change username available
Always include the information described in these guidelines when you post a question: How to get the answers from the forum
I use 5 APEX on Oracle Express Edition.
I created a calendar that displays data in multiple tables.
Here is the query to simplify:
Select an evt, b datevt
FROM table1
Union
Select evt c, datevt d
from table2
Union
Select e TTE, f datevt
table 3;
I need to put up a link in the calendar on these data that display a modal page where users can see the details and update the data.
I have seen that it is possible to create a link on the calendar, but this link is considered to be a single page. In my case, I need to 3 different links, one per page.
Another question: I want to display these data on the calendar with a color that depends on the table. For example, blue for the first table, the Red during the second and the Orange for the third.
You have a solution that helps me implement those needs?
An explanation of how to display events in different colors using CSS classes is given in the online help for the region calendar Class CSS attribute:
select ID, START_DATE, END_DATE, TASK_NAME, case STATUS when 'Open' then 'apex-cal-green' when 'Pending' then 'apex-cal-yellow' when 'Closed' then 'apex-cal-red' when 'On-Hold' then 'apex-cal-black' end as css_class, ASSIGNED_TO as supplemental_info from PROJECTS
The column specifying the apex - cal-* color class is then selected in the attribute of Class CSS region.
Link target URL can be built dynamically in the region of link attributes using chains of substitution that reference columns in the query. Again, see the online help for the link attributes. In a UNION like yours, a different target page can be specified in each request, and referenced in the link attribute display/change page numbers to specify the page number and set the values of the elements of the requested page:
Source of the region
select 10 x , trunc(sysdate) - 9 d , 'Foo' s , 'apex-cal-green' css_class , '10' link_page from dual union all select 20 , trunc(sysdate) - 6 , 'Bar' , 'apex-cal-yellow' , '11' from dual union all select 30 , trunc(sysdate) , 'Baz' , 'apex-cal-red' , '12' from dual
View/Edit link
f?p=&APP_ID.:&LINK_PAGE.:&SESSION.::&DEBUG.:10:P&LINK_PAGE._X:&X.
-
Question: Using Sqlplus to create a report
Hi masters Sqlplus,
I have the same question as the old thread calculate from the number
COIL D:\TEST. TXT
BREAK ON COL1 ON REPORT
CALCULATION NUMBER OF COL1 NODUP REPORT
CALCULATION NUMBER OF COL2 ON REPORT
with the data as
(
Select 'AAA' COL1, COL2 '1111' from dual
Union of all the
Select 'AAA' COL1, COL2 '2222' from dual
Union of all the
Select 'AAA' COL1, COL2 '3333' from dual
Union of all the
Select 'AAA' COL1, COL2 '4444' from dual
Union of all the
Select 'AAA' COL1, COL2 '5555' from dual
Union of all the
Select 'BBB' COL1, COL2 '1111' from dual
Union of all the
Select 'BBB' COL1, COL2 '2222' from dual
Union of all the
Select 'BBB' COL1, COL2 '3333' from dual
Union of all the
Select 'BBB' COL1, COL2 '4444' from dual
Union of all the
Select 'BBB' COL1, COL2 '5555' from dual
Union of all the
Select 'BBB' COL1, COL2 '6666' from dual
Union of all the
Select 'BBB' COL1, COL2 '7777' from dual
Union of all the
Select 'BBB' COL1, COL2 '8888' from dual
Union of all the
Select 'BBB' COL1, COL2 '9999' from dual
Union of all the
Select "CCC" COL1, COL2 '1111' from dual
Union of all the
Select "CCC" COL1, COL2 '2222' from dual
Union of all the
Select "CCC" COL1, COL2 '3333' from dual
Union of all the
Select "CCC" COL1, COL2 '4444' from dual
Union of all the
Select "CCC" COL1, COL2 '5555' from dual
)
Select * from data;
SPOOL OFF
ED D:\TEST. TXT
The result is like that.
COL COL2 --- ---- AAA 1111 2222 3333 4444 5555 BBB 1111 2222 3333 4444 5555 6666 7777 8888 9999 CCC 1111 2222 3333 4444 5555 --- ---- 19 19 19 rows selected.
How to get the count (col1) = 3, no 19?
For now, I can't use grouping to customize the result, because I have to give the secondary account for each col1 and the short dash line.
Please give me advice.
Phil
Post edited by: Phil in Sydney
The end result is the sequel.
COL COL2 --- ---- AAA 1111 2222 3333 4444 5555 BBB 1111 2222 3333 4444 5555 6666 7777 8888 9999 CCC 1111 2222 3333 4444 5555 --- ---- 3 19 19 rows selected.
Hi, Phil,
Here's a way to change the query:
WITH hide_col1 AS
(
SELECT col1 AS original_col1
col2
ROW_NUMBER () OVER (PARTITION BY col1
ORDER BY col2
) AS r_num
FROM the data
)
SELECT THE CHECK BOX
WHEN r_num = 1
THEN original_col1
END AS col1
col2
OF hide_col1
ORDER BY original_col1
r_num
;
All SQL * most orders can stay as they are.
-
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
-
Questioning REGEXP_SUBSTR, regular expressions
With the expression below, I expect to come back the first 4 words and do not understand why it is not doing.
db > select regexp_substr('This is a sample text string', '([[:alpha:]]+){3,4}') from dual; REGE ---- This
This works as expected.
db > select regexp_substr('This is a sample text string', '([[:alpha:]]+ ){3,4}') from dual; REGEXP_SUBSTR('TH ----------------- This is a sample
Hello
Solomon Yakobson says:
Frank Kulash wrote:
If you are looking for 3 or 4 instances of 1 or more letters, without anything in addition to the letters between them. Any group of 3 or more consecutive letters matches. For example,.
- "Th" as the 1st appearance of 1 or more letters,
- 'i' as the 2nd appearance of 1 or more letters, and
- of ' as the 3rd appearance of 1 or more letters
is a substring that matches the pattern you described.
In fact T is the 1st appearance of 1 or several letters, h is the second, I ranked third and s are defined. Otherwise:
SQL > select regexp_substr ('the following is an example of text string', ' ([[: alpha:]] +) {3,4}') of the double
2.REG
---
TheSQL >
returns no rows.
Not that it is important for the OP's question, but I think the way I presented it is more precise.
How can tell us if 'This' match of the 4 occurrences (all 1 character) or 3 occurrences (1 with 2 characters and 2 with 1 character each)?
In more general terms, when we say something like
(expr +) {x, y}
is '+' more greedy than "{x, y}.
It seems to me that '+' is dishonest in this case. Consider this query:
WITH sample_data AS
(
SELECT "This is an example of text string" dual UNION ALL STR
SELECT 'the following is an example of text string' FROM dual UNION ALL
SELECT 'Fubar' double UNION ALL
SELECT 'chat' FROM dual
)
SELECT str
REGEXP_REPLACE (str
, ' ([[: alpha:]] {1,2})([[:alpha:]]+) ([[: alpha:]] +)([[:alpha:]]+)?'
, "\1=1;\2=2;\3=3;\4=4".
) And matches
OF sample_data
;
which produces this output:
STR MATCHES
------------------------------------- ------------------------------
This is an example of text string Th = 1; i = 2; s = 3; = 4 is a samp = 1; l =
2; e = 3; 4 = = you 1; x = 2; t = 3; = 4 = stri
1; n = 2; g = 3; = 4
The following is an example of text string T = 1; h = 2; e = 3; = 4 followi = 1; n = 2; g
= 3 ; = 4 is a samp = 1; l = 2; e = 3; = 4 t
e = 1; x = 2; t = 3; = stri 4 = 1; n = 2; g = 3;
= 4
Fubar Fub = 1; a = 2; r = 3; = 4
cat c=1;a=2;t=3;=4
In this case, '+' appears to be labels as "{3.4}.
I don't have not seen this documented anywhere, but it seems it's because + gets to go first in the model. In other words, there is nothing to inherently rapacity on ' + '. If we change the first '+' above "{1,9}", like this
WITH sample_data AS
(
SELECT "This is an example of text string" dual UNION ALL STR
SELECT 'the following is an example of text string' FROM dual UNION ALL
SELECT 'Fubar' double UNION ALL
SELECT 'chat' FROM dual
)
SELECT str
REGEXP_REPLACE (str
, ' ([[: alpha:]]{1,9}) ([[: alpha:]] +) ([[: alpha:]] +)([[:alpha:]]+)?'
, "\1=1;\2=2;\3=3;\4=4".
) And matches
OF sample_data
;
the result remains the same.
Of course, is using the first query I posted above
(expr) (expr) (expr) (expr)?
It is possible that
(expr) {3,4}
which is what OP posted, is handled differently.
-
Want to Aviod Union and convert to decode
Ask for help on this
SELECT T3. "" LOB Cd. "
-- T1." End benefits Cd. "
T6. R_FND_CD AS "Cd of funds."
T6. C_ADJ AS "Clm Hdr Dt-Adjud"
T7. C_COS_CD AS 'Clm Cos Cd',
T7. C_PEND AS ' Clm Fscl hangs Ind. "
T6. C_PYE AS 'Clm Hdr - third-party payer Cd',
T6. C_PYE AS "Clm Hdr-payer ID,"
T5. "' Name of Pye fin-Pyr."
T6. C_REI AS "expenses".
HDR_CRT T3,
H_TMP_TB T6,
AUX_TB_TMP T7,
K_AUX_TB T5
WHERE T3. "' CLM Stat Cd ' = 'o'
AND T6. B_SYS_ID = T3. "" MBR. "
AND T6. C_TCN_NUM = T3. "' CLM '.
AND T7. B_SYS_ID = T3. "" MBR. "
AND T7. C_TCN_NUM = T3. "' CLM '.
AND T7. C_BATCH_PMT_TY_CD = '0'
AND T5. "" End Pye Pyr Id ' = T6. G_PYE_CMN_ENTY_SK;
UNION ALL
SELECT T3. "" LOB Cd. "
-- T1." End benefits Cd. "
T8. R_FND_CD AS "Cd of funds."
T6. C_ADJ AS "Clm Hdr Dt-Adjud"
T8. C_LI_COS_CD AS 'Clm Cos Cd',
T7. C_PEND AS ' Clm Fscl hangs Ind. "
T6. C_PYE AS 'Clm Hdr - third-party payer Cd',
T6. C_PYE AS "Clm Hdr-payer ID,"
T5. "' Name of Pye fin-Pyr."
T8. C_LI_REIMB_AMT AS "expenses".
HDR_CRT T3,
H_TMP_TB T6,
AUX_TB_TMP T7,
C_LI_TB T8,
K_AUX_TB T5
WHERE T3. "' CLM Stat Cd ' = 'o'
AND T6. B_SYS_ID = T3. "" MBR. "
AND T6. C_TCN_NUM = T3. "' CLM '.
AND T7. B_SYS_ID = T3. "" MBR. "
AND T7. C_TCN_NUM = T3. "' CLM '.
AND T8. B_SYS_ID = T7. B_SYS_ID
AND T8. C_TCN_NUM = T7. C_TCN_NUM
AND T7. C_BATCH_PMT_TY_CD = '0'
AND T8. C_LI_STAT_CD IN ('O', 'P')
AND T5. "" End Pye Pyr Id ' = T6. G_PYE_CMN_ENTY_SK;
If your question is:
I have a bunch of tables and an additional table called T8. There is a corresponding row in the T8, I want to show a column of T8 if I want to show a column of T5, how do I do it? So the answer is something like:
SELECT
, cases where t8.b_sys_id is not null, then T8. C_LI_REIMB_AMT another T6. C_REI end SUB 'estimates.
Of
left on join T8
-
SQL GROUP BY / HAVING a question
Hello
A few days earlier, I came across an interview question that I can not resolve correctly.
In short, there are two tables: BOOKS and TAGS.
ID TITLE AUTHOR 1 Twilight Stephenie Meyer 2 Catch fire Suzanne Collins 3 Animal farm George Orwell BOOK_ID TAG 1 Best Seller 1 Science Fiction 1 TOP10 2 Best Seller 2 Note. 2 TOP10 3 TOP110 However several tags and the result must be a set of appropriate books, users can enter.
For example, in the case of tags 'Best Seller', 'Science Fiction' and 'Top 10', the result must be "Twilight."
My solution was something like this:
SELECT b.title FROM books b WHERE b.id IN ( SELECT book_id FROM tags WHERE LOWER(tag) = 'best seller' ) AND b.id IN ( SELECT book_id FROM tags WHERE LOWER(tag) = 'science fiction' ) AND b.id IN ( SELECT book_id FROM tags WHERE LOWER(tag) = 'top10' )
But it is definetaly not an elegant and flexible query. In the case of labels of 10 or more incoming, we get a code 'spagetti '.
Somehow, it should be possible to resolve using GROUP BY and HAVING, but I don't really know how.
Could someone help what would be the most elegant solution to this problem?
Thank you so much in advance.
Maybe:
SQL >-generating sample data:
SQL > with books like)
2. select id 1, the title of 'Twilight', author of "Stephenie Meyer" Union double all the
3 select 2, "Taking fire", "Suzanne Collins' Union double all the
4 Select 3, 'Animal Farm', 'George Orwell' of the double
5)
6, tags such as)
7 select 1 book_id, tag "Best Seller" of all the double union
8. Select 1, 'Science Fiction' from dual union all
9. Select 1, 'TOP10' from dual union all
10. Select 2, 'Best Seller' from dual union all
11. Select 2, 'Roman' from dual union all
12. Select 2, 'TOP10' from dual union all
13. Select 3, 'TOP110' from dual
14)
15-
16 - the actual query:
17-
18 select b.title
Books b 19
20, tags t
21 where t.book_id = b.id
22 and t.tag ('Best Seller', 'Science Fiction', 'Top 10')
23 by b.title group
24 after having count (*) = 3
25.
TITLE
-------------
Twilight
1 selected line.
Maybe you are looking for
-
Hello I have iphone 5s version 7.1.1 and my bad (a friend) friend created icloud account in my iphone with his apple ID and when I asked the collar him remove this account he refuses in the last time it closed the line in my face and that's why? beca
-
video files do not work on the rocket / battery life only half
I can't read music on my Sansa 4 GB rocket videos. I use Sansa media converter. I want to watch videos on it but I wait like 20 to 30 minutes just to appear in the menu and see just a black screen when I try to watch it. I think a new firmware update
-
Linksys EA9500 LED problem - a solid blue line
I had the EA9500 for a little more than a month without problems and the strong performance. Just yesterday, I noticed that the extreme left LED is a solid blue line on the top and the bottom of the white LED. So the white LED is there (al that stro
-
Hello! I recently bought Buffalo Nfiniti WII - HP - G300NH Wireless - N HighPower Wireless router. It should support speeds of up to 300 Mbps I have activated a bandwidth of 40 Mhz on it and the wpa2/aes encryption. However, I can connect only with s
-
Smartphones blackBerry BIS on Bold 9790
Up until this morning I had access to Blackberry Services on my device, Internet, BBM, email etc, but now I have Blackberry logo on my home screen (up top-right). Looking at my account online for my phone I can see that the services are active. Can