Simplify the query by using Analytics
Hi gurus,I need to humiliate you help by simplifying the application, as shown below:
with REC_GRP_CNT as (select round (count (*) / 3) HML_CNT of JJVC_ACTIVITY_FREQ_RECENCY).
REC_RANK as
(select a.*, rownum rn of)
Select custid, ((total_edm_opened/total_edm_delivered) * 100) percentage from JJVC_ACTIVITY_FREQ_RECENCY by 2 desc) a).
FREQUENCY_HIGH like)
Select custid, 'H' rec_rank FREQUENCY_RANK where rn < = (select HML_CNT FROM REC_GRP_CNT)).
FREQUENCY_MEDIUM like)
Select custid, I ' rec_rank a FREQUENCY_RANK
where
not exist (select custid from b FREQUENCY_HIGH where b.custid = a.custid)
and rn < = (select HML_CNT * FROM REC_GRP_CNT 2)).
FREQUENCY_LOW like)
Select custid, 'L' rec_rank a FREQUENCY_RANK
where
not exists(select * from)
(select custid from FREQUENCY_HIGH
Union of all the
custid SELECT of FREQUENCY_MEDIUM p) WHERE the p.custid = a.custid)
and rn > = (select HML_CNT * 2 OF REC_GRP_CNT))
Select * from FREQUENCY_HIGH
Union of all the
Select * from FREQUENCY_MEDIUM
Union of all the
Select * from FREQUENCY_LOW
Thanks in advance,
BTF
You are going to have to explain what you mean by
Total records H=33.3%
Total records M=33.3%
Total records L=33.4%
What criteria do you use to create these "buckets" that fall under the data?
Tags: Database
Similar Questions
-
Question related to the execution of the query by using the links to the DB
Hi all
I have a source and target database. Both are 11.2.0.3.
I have a query that is running on the source database and load data into the target database.
I created synonyms in the target for all of the tables referenced in the query, remaining at the source.
I run the query in the target using synonyms that I created. I see that the entire query became transferred to the source database and executed. The execution plan of the source was exactly the same as the way in which we could, if the query has been run directly there.
No problems so far.
Now, I have a database from different sources. Version 11.2.0.4.
When I try to mimic the same behavior using this data source, the complete query will NOT be transferred to the source. He made on the source (remote site) full table scans, transfer of data to the target (local site) and then by performing sort operations & the index range scans (min/max) on the target.
In both cases, all of the tables referenced in the query are accessible through the link in the DB.
Please let me know if there is no setting of database / everything which could control how or where a query with all accessible by link DB tables are optimized and executed? Ideally, I want the entire query to be transferred to the remote and executed site.
I can provide more details if necessary.
Thanks in advance.
Thank you sol.beach. Queries I tried both sources are in fact different. I failed to mention that.
@John,
We did recommend the creation of a view of the source, which is synonym on target and run the query. The client was not ready to create any object on the source system and so to test this workaround solution.
********************************************
After some time, I realized that there is a hardcoded as SYSDATE column. Whenever I took it / I did as null, because the entire query is getting transferred to the source DB.
"I changed 'SYSDATE column-name' to ' col_name (select SYSDATE from dual@remote_db_link). But this also seems to stop the query to be sent to the remote db as a whole.
Try to work around this problem, but any ideas are much appreciated.
-
Hi gurus
I have the following data:
Drop table
DROP TABLE lb_source;
DROP TABLE lb;
Insertion and table creation
CREATE TABLE lb_source
(
source_cd VARCHAR2 (5));
INSERT INTO lb_source
(
SELECT 'a' STARTING from two
UNION ALL
SELECT 'b' double
UNION ALL
Select 'l' to double
);CREATE TABLE lb
(
group_number VARCHAR2 (10),
source_cd varchar2 (5)
);INSERT INTO lb
(
SELECT '100', 'l' FROM dual
UNION ALL
SELECT '100', double null);
------------
If you see table lb then it contained a line with source_cd = l against 100 and source_cd = Null group against group 100, now I want to create this kind of query, in which all correspondence lines in tables to join both if lb is null, then query join all the source_cd of table lb_source except source_cd = 'l '. So far, I created the following query and its works ok but I want to do all my work in one in where condition...
Query
SELECT * FROM
(
SELECT s1, s2 b.source_cd A.source_cd
OF lb_source A
lb b
WHERE A.source_cd = nvl (b.source_cd, A.source_cd)
)
WHERE s2 IS NULL
;
Result
s1 s2
a null value
b zero
l null
Please guide
Hello
So, you want something that produces the same accurate results as the query you posted, but does more just; Isn't it?
Here's one way:
SELECT ls.source_cd S1
NULL AS s2
OF ls lb_source
JOIN lb l WE l.source_cd IS NULL
AND ls.source_cd IS NOT NULL;
I'm curious; What is the business problem that requires this request? What tables and columns represent, and what tell you the query?
Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!
-
The query options using command exp
Hello
I'm trying to export a data tables under the following conditions, but it fails. How to export data from tables with the sub condition? The data type of the column is ID NOT NULL VARCHAR2 (80)
test/test exp = EMP query = tables------"' where id like ' % 00% ' \ ' log = emp.log file = emp.dmp"
Export: Release 11.2.0.1.0 - Production Fri Nov 21 21:54:12 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With partitioning, OLAP, Data Mining and Real Application Testing options
Export in US7ASCII and AL16UTF16 NCHAR character set
Server uses WE8MSWIN1252 (possible character set conversion) character set
About to export specified tables by conventional means...
. . export the table EMP
EXP-00056: ORACLE 911 error encountered
ORA-00911: invalid character
Export completed successfully with warnings.
The same conditions as the table below mentioned number of records.
SQL > select count (*) from emp where id like ' % 00% ';
COUNT (*)
----------
2701
Kind regards
007
PL note that first export is desupported in 11 GR 2 - see the first section of the Note to the Original export
You should use expdp with the QUERY parameter - Data Pump Export
HTH
Srini -
compose the query without using the query designer
New on this BEEP 10.1.3.4.1 product,
questions
1. is there a way to compose a query without using query builder but still has a way to see the result of the query under the PIF?
2. How is - a to compose a query prompt? I know that I can create parm after you create the data set, but at the stage of all data already call you query prompt as where employee id =? E_ID? or just not where clause
Sorry if these questions are too rudimentary, but I did not see that what we have answered according to the user's guide.
Thank you.
WANWhen you select the 'View' link, you should be able to see this option.
-
Problem with the query operation using less
Hi all
I have the dataset of all organization numbers like as below
DataSet:
('528801', '528802', '536101', '536102', '100601 ', '536401', ' 536402 ', ' 530701',' 536501', ' 536502 ', ' 540501',' 599101 ', ' 133301',)
('531101', '143101', '536601', '536602', '534401 ', '535501', ' 535401', ' 536801 ', ' 536802',' 531001 ', ' 537501',' 537502 ', ' 540601',' 540801 ', ' 528401')
And I also have a W_INT_ORG_D table where in a column like ORG_NUM that contains the figures of the Organization in the database, now I'll try to find the numbers of the exclusive organization in the value data that does not exist in W_INT_ORG_D using an oracle sql query.
Here is the sql code I wrote well that my request is wrong you could probably understand what I'm trying to say or do, I'm not ok with creating another table and filled in the data and compare two tables later, I want to do it without creating any additional table. Please let me know if you have an idea to do this, appreciate your time.
Request:_
WITH ABC AS
('528801', '528802', '536101', '536102', '100601 ', '536401', ' 536402 ', ' 530701',' 536501', ' 536502 ', ' 540501',' 599101 ', ' 133301',)
('531101', '143101', '536601', '536602', '534401 ', '535501', ' 535401', ' 536801 ', ' 536802',' 531001 ', ' 537501',' 537502 ', ' 540601',' 540801 ', ' 528401')
SELECT DISTINCT ORG_NUM
OF W_INT_ORG_D, ABC
WHERE DATASOURCE_NUM_ID = ' 211 '.
AND ORG_NUM IN
('528801', '528802', '536101', '536102', '100601 ', '536401', ' 536402 ', ' 530701',' 536501', ' 536502 ', ' 540501',' 599101 ', ' 133301',)
('531101', '143101', '536601', '536602', '534401 ', '535501', ' 535401', ' 536801 ', ' 536802',' 531001 ', ' 537501',' 537502 ', ' 540601',' 540801 ', ' 528401')
LESS
SELECT * FROM ABC
Thank you
SamThis wil give a list of numbers of overall organization of data that are not present in the view:
SELECT column_value org_num FROM TABLE(sys.odciVarchar2List( '528801', '528802', '536101', '536102', '100601', '536401', '536402', '530701', '536501', '536502', '540501', '599101', '133301', '531101', '143101', '536601', '536602', '534401', '535501', '535401', '536801', '536802', '531001', '537501', '537502', '540601', '540801', '528401' ) ) MINUS SELECT DISTINCT ORG_NUM FROM W_INT_ORG_D WHERE DATASOURCE_NUM_ID='211' /
SY.
Published by: Solomon Yakobson, June 29, 2009 10:49
-
How to prioritize the query result using analytic functions
Hello
Published by: prakash on May 20, 2013 01:42Use ROW_NUMBER
SQL> select PRVDR_LCTN_X_SPCLTY_SID,PRVDR_LCTN_IID,PRVDR_TYPE_X_SPCLTY_SID,STATUS_CID 2 from 3 ( 4 select t.*, 5 row_number() over(partition by PRVDR_TYPE_X_SPCLTY_SID 6 order by STATUS_CID) rn 7 from your_table t 8 ) 9 where rn = 1; PRVDR_LCTN_X_SPCLTY_SID PRVDR_LCTN_IID PRVDR_TYPE_X_SPCLTY_SID STATUS_CID ----------------------- -------------- ----------------------- ---------- 75292110 10153920 75004770 1 75291888 10153920 75004884 2 75292112 10153920 75004916 1 75292117 10153920 75004974 1
-
Need help to resolve the query by using analytic functions
Hello
I need help to solve this problem, I tried an analytical function but could not solve the problem.
I have three table as illustrated below the table is filled with a flat file. The records are arranged sequentailly based on the name of the file.
The first record of the game based on EIN goes to TAB_RCE
the following records then goes to TAB_RCW
and last save of the game based on EIN goes to the RCT table
How can I make groups and
assign a
EIN * 12345 * line number * 02, 03, 04 * in the table TAB_RCW and * 05 * in the table TAB_RCT
EIN * 67890 * line number * 07, 08, 09,10 * in the table TAB_RCW and * 11 * in the table TAB_RCT
and so on...
Thank you
Rajesh
TAB RCE_--------------------------------------------------------------
LineNumber EIN FILENAME TYPE
-----
01 12345 ABC NCE. TXT
06 67890 ABC NCE. TXT
12 76777 ABC NCE. TXT
-----
TAB_RCW
-----
LineNumber TYPE SSN FILENAME
-----
02 22222 ABC RCW. TXT
03 33333 ABC RCW. TXT
04 44444 ABC RCW. TXT
07 55555 ABC RCW. TXT
08 66666 ABC RCW. TXT
09 77777 ABC RCW. TXT
10 88888 ABC RCW. TXT
13 99998 ABC RCW. TXT
14 99999 ABC RCW. TXT
-----
TAB_RCT
-----
NAME OF THE FILE OF TYPE LINENUMBER
-----
RCT 05 ABC. TXT
RCT 11 ABC. TXT
RCT 15 ABC. TXT
-----SQL> with TAB_RCE as ( 2 select 'RCE' rtype,'01' linenumber, '12345' EIN,'ABC.TXT' FILENAME from dual union all 3 select 'RCE','06','67890','ABC.TXT' from dual union all 4 select 'RCE','12','76777','ABC.TXT' from dual 5 ), 6 TAB_RCW as ( 7 select 'RCW' rtype,'02' linenumber,'22222' ssn,'ABC.TXT' FILENAME from dual union all 8 select 'RCW','03','33333','ABC.TXT' from dual union all 9 select 'RCW','04','44444','ABC.TXT' from dual union all 10 select 'RCW','07','55555','ABC.TXT' from dual union all 11 select 'RCW','08','66666','ABC.TXT' from dual union all 12 select 'RCW','09','77777','ABC.TXT' from dual union all 13 select 'RCW','10','88888','ABC.TXT' from dual union all 14 select 'RCW','13','99998','ABC.TXT' from dual union all 15 select 'RCW','14','99999','ABC.TXT' from dual 16 ), 17 TAB_RCT as ( 18 select 'RCT' rtype,'05' linenumber,'ABC.TXT' FILENAME from dual union all 19 select 'RCT','11','ABC.TXT' from dual union all 20 select 'RCT','15','ABC.TXT' from dual 21 ) 22 select rtype, 23 last_value(ein ignore nulls) over(partition by filename order by linenumber) ein, 24 linenumber, 25 ssn 26 from ( 27 select rtype, 28 linenumber, 29 ein, 30 to_char(null) ssn, 31 filename 32 from TAB_RCE 33 union all 34 select rtype, 35 linenumber, 36 to_char(null) ein, 37 ssn, 38 filename 39 from TAB_RCW 40 union all 41 select rtype, 42 linenumber, 43 to_char(null) ein, 44 to_char(null) ssn, 45 filename 46 from TAB_RCt 47 ) 48 order by linenumber 49 / RTY EIN LI SSN --- ----- -- ----- RCE 12345 01 RCW 12345 02 22222 RCW 12345 03 33333 RCW 12345 04 44444 RCT 12345 05 RCE 67890 06 RCW 67890 07 55555 RCW 67890 08 66666 RCW 67890 09 77777 RCW 67890 10 88888 RCT 67890 11 RTY EIN LI SSN --- ----- -- ----- RCE 76777 12 RCW 76777 13 99998 RCW 76777 14 99999 RCT 76777 15 15 rows selected. SQL>
SY.
-
Slow index by using the query. Fast with full table Scan.
Salvation;
(Thanks for the links)
Here's my question correctly formatted.
The query:
Works on 32 seconds!SELECT count(1) from ehgeoconstru ec where ec.TYPE='BAR' AND ( ec.birthDate <= TO_DATE('2009-10-06 11:52:12', 'YYYY-MM-DD HH24:MI:SS') ) and deathdate is null and substr(ec.strgfd, 1, length('[CIMText')) <> '[CIMText'
Same query, but with an extra where clause:
This is 400 seconds.SELECT count(1) from ehgeoconstru ec where ec.TYPE='BAR' and ( (ec.contextVersion = 'REALWORLD') --- ADDED HERE AND ( ec.birthDate <= TO_DATE('2009-10-06 11:52:12', 'YYYY-MM-DD HH24:MI:SS') ) ) and deathdate is null and substr(ec.strgfd, 1, length('[CIMText')) <> '[CIMText'
It should return data from a table, given the conditions.
The database version is Oracle9i Release 9.2.0.7.0
These are the parameters relevant for the optimizer:
Here is the output of the PLAN to EXPLAIN for the first quick query:SQL> show parameter optimizer NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ optimizer_dynamic_sampling integer 1 optimizer_features_enable string 9.2.0 optimizer_index_caching integer 99 optimizer_index_cost_adj integer 10 optimizer_max_permutations integer 2000 optimizer_mode string CHOOSE SQL>
Here is the output of the EXPLAIN of PLAN for slow queries:PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | -------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | | | 1 | SORT AGGREGATE | | | | | |* 2 | TABLE ACCESS FULL | EHCONS | | | | -------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- 2 - filter(SUBSTR("EC"."strgfd",1,8)<>'[CIMText' AND "EC"."DEATHDATE" IS NULL AND "EC"."BIRTHDATE"<=TO_DATE('2009-10-06 11:52:12', 'yyyy -mm-dd hh24:mi:ss') AND "EC"."TYPE"='BAR') Note: rule based optimization
The TKPROF output for this slow statement is:PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- | | | 1 | SORT AGGREGATE | | | | | |* 2 | TABLE ACCESS BY INDEX ROWID| ehgeoconstru | | | | |* 3 | INDEX RANGE SCAN | ehgeoconstru_VSN | | | | PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - filter(SUBSTR("EC"."strgfd",1,8)<>'[CIMText' AND "EC"."DEATHDATE" IS NULL AND "EC"."TYPE"='BAR') PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- 3 - access("EC"."CONTEXTVERSION"='REALWORLD' AND "EC"."BIRTHDATE"<=TO_DATE('2 009-10-06 11:52:12', 'yyyy-mm-dd hh24:mi:ss')) filter("EC"."BIRTHDATE"<=TO_DATE('2009-10-06 11:52:12', 'yyyy-mm-dd hh24: mi:ss')) Note: rule based optimization
Published by: PauloSMO on November 17, 2009 04:21TKPROF: Release 9.2.0.7.0 - Production on Tue Nov 17 14:46:32 2009 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Trace file: gen_ora_3120.trc Sort options: prsela exeela fchela ******************************************************************************** count = number of times OCI procedure was executed cpu = cpu time in seconds executing elapsed = elapsed time in seconds executing disk = number of physical reads of buffers from disk query = number of buffers gotten for consistent read current = number of buffers gotten in current mode (usually for update) rows = number of rows processed by the fetch or execute call ******************************************************************************** SELECT count(1) from ehgeoconstru ec where ec.TYPE='BAR' and ( (ec.contextVersion = 'REALWORLD') AND ( ec.birthDate <= TO_DATE('2009-10-06 11:52:12', 'YYYY-MM-DD HH24:MI:SS') ) ) and deathdate is null and substr(ec.strgfd, 1, length('[CIMText')) <> '[CIMText' call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 2 0.00 538.12 162221 1355323 0 1 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 4 0.00 538.12 162221 1355323 0 1 Misses in library cache during parse: 0 Optimizer goal: CHOOSE Parsing user id: 153 Rows Row Source Operation ------- --------------------------------------------------- 1 SORT AGGREGATE 27747 TABLE ACCESS BY INDEX ROWID OBJ#(73959) 2134955 INDEX RANGE SCAN OBJ#(73962) (object id 73962) ******************************************************************************** alter session set sql_trace=true call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 0 0.00 0.00 0 0 0 0 Execute 1 0.00 0.02 0 0 0 0 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 1 0.00 0.02 0 0 0 0 Misses in library cache during parse: 0 Misses in library cache during execute: 1 Optimizer goal: CHOOSE Parsing user id: 153 ******************************************************************************** OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 2 0.00 0.02 0 0 0 0 Fetch 2 0.00 538.12 162221 1355323 0 1 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 5 0.00 538.15 162221 1355323 0 1 Misses in library cache during parse: 0 Misses in library cache during execute: 1 OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 0 0.00 0.00 0 0 0 0 Execute 0 0.00 0.00 0 0 0 0 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 0 0.00 0.00 0 0 0 0 Misses in library cache during parse: 0 2 user SQL statements in session. 0 internal SQL statements in session. 2 SQL statements in session. ******************************************************************************** Trace file: gen_ora_3120.trc Trace file compatibility: 9.02.00 Sort options: prsela exeela fchela 2 sessions in tracefile. 2 user SQL statements in trace file. 0 internal SQL statements in trace file. 2 SQL statements in trace file. 2 unique SQL statements in trace file. 94 lines in trace file.
Published by: PauloSMO on November 17, 2009 07:07
Published by: PauloSMO on November 17, 2009 07:38 - title changed to be more correct.Although your optimizer_mode is choosing, it seems that there are no statistics collected on ehgeoconstru. The absence of estimated costs and estimated row counts of each of the stages of the plan and the "Note: optimization based on rules" at the end of these two plans would tend to confirm this.
Optimizer_mode choose means that if statistics are collected then it will use the CBO, but if no statistic is present in any of the tables in the query, the optimizer to rule will be used. The RBO tends to be happy in the best of the index case. I guess the index ehgeoconstru_VSN contextversion as the main column and also includes the date of birth.
You can either gather statistics on the table (if all other tables have statistics) using dbms_stats.gather_table_stats, or suggest the query to use a full scan instead of index. Another solution would be to apply a function or an operation against the contextversion to prevent the use of the index. something like this:
SELECT COUNT(*) FROM ehgeoconstru ec WHERE ec.type='BAR' and ec.contextVersion||'' = 'REALWORLD' ec.birthDate <= TO_DATE('2009-10-06 11:52:12', 'YYYY-MM-DD HH24:MI:SS') and deathdate is null and SUBSTR(ec.strgfd, 1, LENGTH('[CIMText')) <> '[CIMText'
or maybe UPPER (ec.contextVersion) so that would not change the rows returned.
John
-
help in the application without using the pivot function
Hi gurus,
Can you please help write the query without using the PIVOT function.
Thanks in advance!...WITH indata AS (SELECT 1 sn, '123:456,789,323:456,213,344,345:5454' x from dual UNION ALL SELECT 2, 'abcd:fgrfr,rfrf,rfred,tg:tg,tg:ophhh,op,vdfgbh:poijn' x from dual), instr AS (SELECT a.SN, rownum RN, B.column_value || CASE WHEN B.column_value NOT LIKE '%:%' THEN ':' END column_value FROM indata a, TABLE(CAST(multiset (SELECT trim(SUBSTR(x, (CASE LEVEL WHEN 1 THEN 1 ELSE instr(x, ',', 1, LEVEL - 1) + 1 END), (CASE instr(x, ',', 1, LEVEL) WHEN 0 then 4000 ELSE instr(x, ',', 1, LEVEL) - 1 - (CASE LEVEL WHEN 1 THEN 0 ELSE instr(x, ',', 1, level - 1) END) END))) FROM dual CONNECT BY level <= LENGTH(x) - LENGTH(REPLACE(x, ',', '')) + 1) AS sys.odcivarchar2list)) b) SELECT col1_val2, col1_val1, col2_val2, col2_val1, systimestamp FROM (select SN, ROW_NUMBER() over(partition by SN order by RN) RN, SUBSTR(column_value, INSTR(column_value, ':') + 1) VAL1, substr(column_value, 1, instr(column_value, ':') - 1) val2 FROM instr ) PIVOT(MAX(VAL1) VAL1, MAX(VAL2) VAL2 FOR SN IN(1 as col1,2 as col2));
Any help would be appreciated.user590978 wrote:
Can you please help write the query without using the PIVOT function.
with indata as ( select 1 sn,'123:456,789,323:456,213,344,345:5454' x from dual union all select 2, 'abcd:fgrfr,rfrf,rfred,tg:tg,tg:ophhh,op,vdfgbh:poijn' x from dual ), t1 as ( select x from indata where sn = 1 ), t2 as ( select x from indata where sn = 2 ), t3 as ( select level lvl, substr( x, instr(',' || x,',',1,level), instr(x || ',',',',1,level) - instr(',' || x,',',1,level) ) col1 from t1 connect by level <= length(x) - length(translate(x,'A,','A')) + 1 ), t4 as ( select level lvl, substr( x, instr(',' || x,',',1,level), instr(x || ',',',',1,level) - instr(',' || x,',',1,level) ) col2 from t2 connect by level <= length(x) - length(translate(x,'A,','A')) + 1 ), t5 as ( select lvl, substr(col1,1,instr(col1 || ':',':') - 1) col1_val1, substr(col1,instr(col1 || ':',':') + 1) col1_val2 from t3 ), t6 as ( select lvl, substr(col2,1,instr(col2 || ':',':') - 1) col2_val1, substr(col2,instr(col2 || ':',':') + 1) col2_val2 from t4 ) select col1_val1, col1_val2, col2_val1, col2_val2, systimestamp from t5 full join t6 on ( t6.lvl = t5.lvl ) order by coalesce(t5.lvl,t6.lvl) / COL1_VAL1 COL1_VAL2 COL2_VAL1 COL2_VAL2 SYSTIMESTAMP ---------- ---------- ---------- ---------- ------------------------------------- 123 456 abcd fgrfr 23-OCT-12 11.50.12.015000 AM -04:00 789 rfrf 23-OCT-12 11.50.12.015000 AM -04:00 323 456 rfred 23-OCT-12 11.50.12.015000 AM -04:00 213 tg tg 23-OCT-12 11.50.12.015000 AM -04:00 344 tg ophhh 23-OCT-12 11.50.12.015000 AM -04:00 345 5454 op 23-OCT-12 11.50.12.015000 AM -04:00 vdfgbh poijn 23-OCT-12 11.50.12.015000 AM -04:00 7 rows selected. SQL>
SY.
-
Join the query - confused behavior
Hello.. I need to make a join on four tables and select one data tables. The query is as below,
SELECT THE VIRTUAL MACHINE. SEGMENT, VM.CA, VM. PR, VM. BP, VM. TERM_ID, VM. TL v_mlr_cable VM, v_neicode NEI, v_mlr MLR, v_fibre_ntwk_type FIBER WHERE MLR.master_key = 62 AND MLR.dslam_tid = NEI.id AND NEI.type = 'OLT' AND MLR.ntwk_type = FIBRE.id AND MLR.master_key = VM.master_key;
This query works very well. I want to change the query to have an OR condition by combining certain conditions in the WHERE clause as below,
SELECT THE VIRTUAL MACHINE. SEGMENT, VM.CA, VM. PR, VM. BP, VM. TERM_ID, VM. TL v_mlr_cable VM, v_neicode NEI, v_mlr MLR, v_fibre_ntwk_type FIBER WHERE MLR.master_key = 62 AND ((MLR.dslam_tid = NEI.id ET NEI.type = 'OLT') or MLR.ntwk_type = FIBRE.id) AND MLR.master_key = VM.master_key;
This translates into several duplicates of the correct result lines (about 93 272 rows).
I suspect this is a unwanted Cartesian product.
I am limited to use a 'different' because my application performs custom, so 'distinct' query analysis is out of the option.
I struggle to understand the result of this query. You can help... ! Thanks in advance.
My database: Oracle Enterprise Edition 10.2.0.2.0
Published by: vanessa on June 9, 2011 12:49 AMHello
Can hide you the SELECT DISTINCT in a subquery, like this:
SELECT * FROM ( SELECT DISTINCT VM.SEGMENT, ... );
or in a view?
If this is not the case, use GROUP BY. The GROUP BY clause contains all the columns in the SELECT clause.
You could also re - write the query to use EXISTS or IN, instead of a jon.
For example:SELECT SEGMENT , CA , PR , BP , TERM_ID , TL FROM v_mlr_cable vm WHERE master_key = 62 AND EXISTS ( SELECT 0 FROM v_neicode NEI , v_mlr MLR , v_fibre_ntwk_type FIBRE WHERE MLR.master_key = vm.master_key AND ( ( MLR.dslam_tid = NEI.id AND NEI.type = 'OLT' ) OR MLR.ntwk_type = FIBRE.id ) ) ;
Do you think it is easier to read and understand the code formatted, as the query above, or unformatted, as what you posted?
Who do you think will encourage people to read your question and provide accurate responses?
Never write, not to mention NPA, not formatted.I hope that answers your question.
If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) of all the tables and the results desired from these data.
Explain how you get these results from these data.
Always tell what version of Oracle you are using. -
Necessary assistance to the query
Hello world
In Oracle 10G
Support to the construction of a query where the data in the Table is
value of type date
6 30
7 0
8 0
9 0
10 10
11 0
12 20
13 0
14 0
Output must be
Value of type date
6 30
7 30
8 30
9 30
10 10
11 10
12 20
13 20
14 20
Where the value is zero there onscreen and previous peak non zero value
I tried to use lead/lag but failed.
Please suggest a way to wright the queryUse NULLIF:
SQL> -- generating sample data: SQL> with t as ( 2 select 6 dt, 30 val from dual union all 3 select 7, 0 from dual union all 4 select 8, 0 from dual union all 5 select 9, 0 from dual union all 6 select 10, 10 from dual union all 7 select 11, 0 from dual union all 8 select 12, 20 from dual union all 9 select 13, 0 from dual 10 ) 11 -- 12 -- actual query: 13 -- 14 select dt 15 , last_value(nullif(val, 0) ignore nulls) over (order by dt) val 16 from t; DT VAL ---------- ---------- 6 30 7 30 8 30 9 30 10 10 11 10 12 20 13 20 8 rows selected.
-
'Function SQL Query return' using with Flash graphics
I created a pl/sql function that returns a SQL query in a varchar2 of this form:
Select the null link
-value > < x value
< value y of Series1 > series 1 label
< value Series2 y > 2 series label
< value of y Series3 > series 3 Label
...
...
from tablea a
Join tableb b
On a.col = b.col
order of < x value >
If I call the function of a graphic Flash box series SQL with the Type of Source query "SQL query" value that returns the function like this:
return functionname (to_date ('30-sep-2010, ' mon-dd-yyyy ""))
It parses correctly and the page is saved; However, when I run the page I get no output - error messages or another indication of a problem.
Now, if I call the function in a SQL client, capture the result of the query SQL using the dbms_output and paste that into the box graphic Flash series SQL - change the Source Type of SQL query query - and save the page it works fine when I run it and returns a chart series flash.
Can anyone suggest either;
1. what I might have missed or done wrong?
2. a way to effectively diagnose the problem...
I tried to use the debugger Apex - what is very nice, indeed - but it provides no information on what might be my problem. I tried to write my own my function debug messages using the apex_debug_message package - nothing...
Thank you
EricHi Eric,.
Try to pull the source like this:
begin return functionname(to_date('30-sep-2010', 'dd-mon-yyyy')); end;
This works very well for me, and if I take the begin-end and the final semicolon from the return statement I get the same behavior as you.
He doesn't mention in aid of the source (only during the wizard if) this source type must be expressed in this way, but I agree, it would be useful that the tool would validate to this format meets it "Query SQL that returns the function" or give some sort of indication of the sentence. In any case, this should help you will again.
Hope this helps,
JohnIf you find this information useful, please do not forget to mark the 'useful' or 'correct' post so that others benefit as well.
-
How to simplify this query in sql simple select stmt
Hello
Please simplify the query
I want to convert this query in a single select statement. Is this possible?
If uarserq_choice_ind is not null then
Select ubbwbst_cust_code
From ubbwbst,utrchoi
Where utrchoi_prop_code=ubbwbst_cancel_prod
Else
Select max(utvsrvc_ranking)
From utvsrvc,ubbwbst
Where utvsrvc_code=ubbwbst_cancel_prod
End ifSelect ubbwbst_cust_code as val From ubbwbst,utrchoi Where utrchoi_prop_code=ubbwbst_cancel_prod AND uarserq_choice_ind is not null union all Select max(utvsrvc_ranking) as val From utvsrvc,ubbwbst Where utvsrvc_code=ubbwbst_cancel_prod and uarserq_choice_ind is null
Without more information, we are unable to combine the two queries in 1 without a union.
Looks like you select values totally disperate of totally different tables -
help to try to simplify the form table, based on the collection using dynamic measurements
Hi everyone, I have tried cleaning and simplify an application designed in 2008 apex 3.2. We have improved in 4.1.2 and want to take advantage of our understanding of the apex and the dynamic measures to simplify a large part of our code, get rid of the redundancies and make it easier for the programmer to debug and improve next.
The application is for traders and commercial fishermen and currently has around 4100 users.
The part that I'm trying to simplify is a tabular report, based on a collection. Almost all areas in this tabular form has a logic linked to it... and in most cases, it is superfluous in that it executes a UPDATE_MEMBER on the collection. I would like to remove as much of javascript and additional processes as possible. I'm also still very new to jQuery and javascript, and faced with the two... but competent in pl/sql.
tabular query is:
{code}
SELECT
seq_id,apex_item. Text (1, seq_id, "," "id ="f01_"| seq_id,",")"DeleteRow. "
apex_item.text_from_LOV (C004, 'SPECIES'). » -'|| apex_item.text_from_LOV (C005, 'RANK') | » -'|| apex_item.text_from_LOV (C006, 'MARKETCODE') | » -'|| Unit apex_item.text_from_LOV_query (c007, 'select unit_of_measure d, unit_of_measure r species_qc'),
apex_item.select_list_from_LOV (6, c008, "STOP," onchange = "getAllDisposition('||) seq_id. "" ")" ',' YES, '0', "- Select favorite -", ' f06_ ' | seq_id, cm) available.
apex_item.select_list_from_LOV (7, c009, style of ' GEAR, "=" background-color: #FBEC5D;) "onFocus ="checkGearPreviousFocus('||). " seq_id |') ; "OnChange ="getAllGears('|| seq_id ||). " "" ")" ',' YES, 'f07_', "- Select favorite -", "3333" | seq_id, cm) Gear,.
apex_item. Text (8, TO_NUMBER (c010), 5, null, "onchange ="setTotal('||)) seq_id. ")" «, » f08_'|| seq_id, cm) quantity.
apex_item. Text (9, TO_NUMBER (c011), 5, null, "onchange ="getPriceBoundaries('||)) seq_id. ")" «, » f09_'|| seq_id, cm) price.
apex_item. Text (10, TO_NUMBER (c012), 5, null, "onchange ="changePrice)
('| seq_id |') "onKeyDown = selectDollarsFocus('||) "(seq_id |', event);" ',' f10_'| "" seq_id, cm) $,.Decode (c013, 'Y', apex_item.text (11, c014, 30, null, "style =" background-color: #FBEC5D;)) ' onClick = 'onFocusAreaFished('|| seq_id||'); "',' f11_'. seq_id, cm), "n","N/A") Area_Fished, "
Decode (c017, 'Y', apex_item.text (12, c018, 4, null, "style =" background-color: #FBEC5D;)) "onBlur ="setUnitQuantity('||). " seq_id. ")" «, » f12_'|| seq_id, cm), "n","N/A") UNIT_QUANTITY, "
Decode (c017, 'Y', apex_item.text (13, 'CN', 3, null, "readOnly = readOnly; ',' f13_'|")) seq_id, cm), "n","N/A") UNIT_COUNT, "
Decode (c050, 'Y', apex_item.checkbox (14, 'Y','id = "f14_" | seq_id |')) "style =" background-color: #FBEC5D; " onClick = "alterYes('|| seq_id||');" "onKeyPress = alterYes('||) (("(seq_id |');" ', c021), "n", "S/o") FinsAttached,.
decode (c050, 'Y', apex_item.checkbox (15, ', "id ="f15_"|")) seq_id |' "style =" "background-color: #FBEC5D;" onClick = "alterNo('||)" seq_id |') ; "onKeyPress = alterNo('||) (("(seq_id |');" ', c022), "n", "S/o") FinsNotAttached,.
Decode (c050, 'Y', apex_item.checkbox (16, 'U','id = "f16_" | seq_id |')) "style =" "background-color: #FBEC5D;" onClick = "alterUnk('||)" seq_id |') ; "onKeyPress = alterUnk('||) (("(seq_id |');" ', c023), "n", "S/o") FinsUnknown,.
Decode (c050, 'Y', apex_item.textarea (17, c028, 3, null, "onchange ="setExplanation('||))) seq_id. ")" «, » f17_'|| seq_id, cm), "n","N/A") explanation, "
Decode (c024,' no, apex_item.select_list_from_LOV (18, c029, 'HMSNATURE','onchange = 'saveNature('||))) seq_id. ")" ',' YES, ' one ', "- Select Nature of sales -", "f18_" | seq_id, cm), 'U', apex_item.select_list_from_LOV (18, c029, 'HMSNATURE','onchange = "saveNature('||)) seq_id. ")" ',' YES, ' one ', "- Select Nature of sales -", "f18_" | seq_id, cm), 'Y', 'N/a') Nature_Of_Sale,.
decode (c020, 'Y',
apex_item.select_list_from_LOV (40, c040, 'HMS_AREA_CODE',
"style =" background-color: #FBEC5D;
"onchange ="saveHMSAREA('||). " seq_id |', this.value) "',' f40_'|" seq_id, cm),
(' N N/A ',' ') HMS_AREA_CODE;C020, c050,
decode (c020, 'Y',
apex_item. Text (41, TO_NUMBER (c041), 5, null, "onchange ="setSalePrice('||)) seq_id |', this.value) "',' f41_'|" seq_id, cm),
(' N n/a ',' ') Sale_Priceof apex_collections
where collection_name = 'SPECIES_COLLECTION' order by desc seq_id{code}
I am slow at first and just try to replace the ONCHANGE for apex_item 41 (retail price). I hope that finally replace all the onblur/onchange to use the same dynamic action.
The ONCHANGE for apex_item 41 is currently:
{code}
function setSalePrice (pRow, savePrice)
{
get var = new htmldb_Get (null, & APP_ID., 'APPLICATION_PROCESS is saveSalePrice', 0);
Get.Add ('SETVALUE3', savePrice);
Get.Add('ATTRNBR3','41');
Get.Add ('SEQUENCEID', Prow);
gResult = get.get ();
}
{code}
the saveSalePrice application process is:
{code}
Start
apex_collection.update_member_attribute (p_collection_name = > 'SPECIES_COLLECTION',)
p_seq = >: SEQUENCEID.
p_attr_number = >: ATTRNBR3,.
p_attr_value = >: SETVALUE3);
end;
{code}
I created two new hidden fields: P110_ID and P110_VALUE.
I created a dynamic action: CHANGE COLUMN
event: change
selection type: jQuery Selector
jQuery Selector: input [name = "f41"]
real action 1 - records P110_ID with javascript expression: this.triggeringElement.id
real action 2 - P110_VALUE value with javascript expression: this.triggeringElement.value
true action 3 - run pl/sql code
{code}
declare
number of v_member;
number of v_seq;Start
v_member: = TO_NUMBER (SUBSTR (: p110_id, 2, 2));
Select ltrim (substr(:p110_ID,5,4),'0 ') in the double v_seq;safis_collections.update_column (v_seq,
v_member,
(: p110_value);
end;{code}, where safis_collections.update_column is a package of db
{code}
Procedure update_column ()v_seq in varchar2
v_attr in number ,
v_value in VARCHAR2 )
is
Start
apex_collection . update_member_attribute()p_collection_name=> 'SPECIES_COLLECTION'
p_seq = > v_seq ,
p_attr_number = > v_attr ,
p_attr_value = > v_value );
apex_debug . message ()'put a day of column.seq ='| v_seq || 'attribute =' || v_attr || "with" || v_value );
end ;
{code}
real action 4 - refreshment area
I modified the query in a table to reference apex_item 41 to be
Decode(C020,'Y',apex_item.) Text (41, TO_NUMBER (c041), 5, null), 'No,' N/a ') Sale_Price in the hope that it would fire the dynamic action. I get the below error. The value of P110_ID is null, the value of P110_VALUE seems to be correctly set.
call returned Ajax Server ora error-sequence of 20103:member does not work
There are in the collection 'SPECIES_COLLECTIO' application to run PL/SQL codeI appreciate all thoughts/help on this.
Thank you, Karen
AHHA. change the query to
Decode (c050, 'Y', apex_item.textarea (28, c028, 3, null, null,,'f28_'| seq_id, cm), ' n ',' n/d "") explanation,.
and that did the trick. On the next item.
Maybe you are looking for
-
Windows Server 2008 SP2 remote management for the
I am trying to install windows on windows server remote management 2008, but it continues to tell me that this update is not appy to this system. I'm trying to manage windows Server 2008 Windows server 2012. I have the updated 2012 in place like ac
-
Share folders shared audit manager
Hello everyone, I am Saeed and I am EXPERT in dairy business. I need your help. I need a solution to audit in the shared folders and files. Let me explain, I have shared files and folders in a network for customers and I put some NTFS permissions, so
-
How to set 2 pc using the printer wireless?
I use an HP laptop and a printer HP Envy connected via wireless, how I configured to use a second workbook use the printer?
-
I am trying to install a software on my laptop and its give me error code 6005
-
Why can't I do a update of security 2.5.0.1 on media player win 7
I have win 7 Home Edition and I'm trying to download the overdrive console one software library books it says wmp needs to upgrade 2.5.0.1 and it will not be upgraded even NICU ms site: drmlicense.microsoft... What should I do now?