Need better alternative to this query
I have a table A.
Table A
X Y
1 R
2 R
3 R
3 S
4 R
4 S
5 P
5 S
I want the result as follows ( record which has Y equals to R or S but if it has both R and S then just get the one with Y equals to R)
X Y
1 R
2 R
3 R
4 R
5 S
So my query is
Select * From A
Where Y = 'R'
UNION
SELECT * FROM TEST WHERE X IN(
Select X From Test
Minus
Select X From Test
Where Y = 'R'
AND Y = 'S';
It will get me the correct result but I feel there must be some other way that is much better than this query.
Thanks,
Sam
with sample_data as (
select 1 x, 'R' y from dual union all
select 1, 'R' from dual union all
select 2, 'R' from dual union all
select 3, 'R' from dual union all
select 3, 'S' from dual union all
select 4, 'R' from dual union all
select 4, 'S' from dual union all
select 5, 'P' from dual union all
select 5, 'S' from dual)
select
x
,max(y) keep (dense_rank first order by y) y
from sample_data
where
y in ('R','S')
group by
x
order by
x
X Y
1 R
2 R
3 R
4 R
5 S It slightly more verbose than blue's solution, but gives you some more possibilites to influence the order than the simple max if necessary (e.g. NLS_SORT)
You want an example, wont you;-)
with sample_data as (
select 1 x, 'R' y from dual union all
select 1, 'R' from dual union all
select 2, 'R' from dual union all
select 3, 'r' from dual union all
select 3, 'S' from dual union all
select 4, 'R' from dual union all
select 4, 'S' from dual union all
select 5, 'P' from dual union all
select 5, 'S' from dual)
select
x
,min(y) my
,max(y) keep (dense_rank first order by nlssort(y,'NLS_SORT=LATIN')) y
from sample_data
where
y in ('R','S','r')
group by
x
order by
x
X MY Y
1 R R
2 R R
3 S r
4 R R
5 S S Edited by: chris227 on 14.09.2012 07:10
Similar Messages
-
Need better alternative to Adobe AIR Application Installer
In order to build a double-clickable desktop application,
apparently one has to use the Adobe AIR Application Installer. This
is bad for a few reasons:
It's not scriptable.
It hard-wires the name of the swf file to load into the
generated binary.
For Mac OS X, the "swf launcher" should be a simple "launcher
stub". The name of the swf file to load should be read from the
Info.plist file. If it did this, then the stub could be the same
for all applications. For Windows, there could be a simple XML
config file in the same directory as the app that serves the same
purpose as Info.plist on the Mac.
I hope Adobe addresses this soon.quote:
Originally posted by:
mattkane
How about creating your native launcher app with the whole
AIR client in the Resources folder. When you launch your app it
launches your server executable, then after its done its stuff it
launches the AIR app.
You could make the launcher app itself headless so you don't
get two dock icons.
This doesn't address the need to have a non-GUI alternative to
the Air Application Installer so builds can be completely
automated.
It definitely breaks the drag-and-drop of a file onto the
application's icon.
I never said I have 2 Dock icons. (I already solved that
problem by making the server "faceless" by setting LSUIElement to 1
in the server's Info.plist.)
Why do I want completely automated builds? Aside from the
ease of just being able to type "ant" and press Return, any real
development group has things such that a "build machine"
automatically rebuilds the app (on all platforms) after ever
developer check-in to check for accidental build breakage. Those
builds also become available to QA for them to test.
Ever time some new development tool comes out where the
authors provide a GUI tool (presumably because they think GUI =
easy), I have to wonder, "What were they thinking?" If the authors
are themselves developers, how can they not see how crippling not
providing an all-command-line tool-chain is? Don't all non-trivial
development groups do automated builds as described above? The only
answer I can think of is that some
PHB
somewhere thought it would be a "neat idea" to have an
"easy-to-use" GUI application (because that sells to other PHBs).
As to drag-and-drop: presumably, the swf launcher that gets
generated properly handles drag-and-drop of files onto the
application's icon and Does The Right Thing when it happens (where
"right thing" usually means simply opening the document dropped
onto the icon). Now, since my launcher gets launched instead, that
breaks drag-and-drop unless I implement that functionality myself.
The way I've implemented my launcher is such that, after the
fork(), it's the parent process that exec's itself into the client
thus keeping the original process ID. The hope is that Launch
Services on the Mac, when handling and drag-and-drop event, will
send said event to the original process -- which is now the client
-- and everything Just Works. I have yet to get around to testing
this (I'm busy with other things at the moment); but, if it turns
out that my hope isn't fulfilled, well then I can fall back to
keeping my launcher running to get and forward the OpenDoc
AppleEvents from my launcher to the swf launcher.
So, anyway, back to my original plea: Adobe,
please just give us a command-line replacement for the Air
Application Installer (preferably just a launcher stub that reads
Info.plist). Thanks. -
Need help in tune this query.
Hi All,
The below query is taking nearly one hour to give the output.
2 select sku.VK_UNIT
3 , sku.MODEL
4 , sku.DESCRIPTION
5 , slt.GEO
6 , slt.LEAD_TIME
7 , slt.REV_LEAD_TIME
8 , aud.LEAD_TIME as PREV_LEAD_TIME_GEO
9 , aud.REV_LEAD_TIME as PREV_REV_LEAD_TIME_GEO
10 , slt.COUNTDOWN
11 , aud.CREATION_DATE as EDD_CREATION_DATE_GEO
12 , aud.CREATED_BY as EDD_CREATED_BY_GEO
13 from LTC_GLOBAL.LTC_SKU sku
14 , LTC_GLOBAL.LTC_SKU_LEAD_TIME slt
15 , (select VK_UNIT
16 , MODEL
17 , substr(ACTION_TYPE, 9) as GEO
18 , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU EDD ' then ACTION_VALUE else null end) as LEAD_TIME
19 , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU EDD ' then CREATION_DATE else null end) as CREATION_DATE
20 , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU EDD ' then CREATED_BY else null end) as CREATED_BY
21 , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU RDD ' then ACTION_VALUE else null end) as REV_LEAD_TIME
22 , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU RDD ' then CREATION_DATE else null end) as REV_CREATION_DATE
23 , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU RDD ' then CREATED_BY else null end) as REV_CREATED_BY
24 from (select VK_UNIT
25 , MODEL
26 , ACTION_TYPE
27 , ACTION_VALUE
28 , CREATION_DATE
29 , CREATED_BY
30 , PREV_ACTION_VALUE
31 , PREV_CREATION_DATE
32 , PREV_CREATED_BY
33 from (select
34 NOTE as VK_UNIT
35 , NOTE2 as MODEL
36 , ACTION_TYPE
37 , ACTION_VALUE
38 , CREATION_DATE
39 , CREATED_BY
40 , row_number() over(partition by NOTE, NOTE2, ACTION_TYPE order by CREATION_DATE desc) as DEPTH
41 , lead(CREATION_DATE) over(partition by NOTE, NOTE2, ACTION_TYPE order by CREATION_DATE desc) as PREV_CREATION_DATE
42 , lead(CREATED_BY ) over(partition by NOTE, NOTE2, ACTION_TYPE order by CREATION_DATE desc) as PREV_CREATED_BY
43 , lead(ACTION_VALUE ) over(partition by NOTE, NOTE2, ACTION_TYPE order by CREATION_DATE desc) as PREV_ACTION_VALUE
44 from LTC_GLOBAL.LTC_AUDIT
45 where NOTE is not null
46 and NOTE2 is not null
47 and ACTION_TYPE is not null
48 )
49 where DEPTH = 2
50 and substr(ACTION_TYPE, 1, 8) in ('SKU EDD ', 'SKU RDD ')
51 )
52 group by VK_UNIT, MODEL, substr(ACTION_TYPE, 9)
53 ) aud
54 where slt.VK_UNIT = sku.VK_UNIT
55 and slt.MODEL = sku.MODEL
56 and slt.CLASS = sku.CLASS
57 and nvl(slt.LEAD_TIME, slt.REV_LEAD_TIME) is not null
58 and aud.VK_UNIT (+)= slt.VK_UNIT
59 and aud.MODEL (+)= slt.MODEL
60 and aud.GEO (+)= slt.GEO;
PLAN_TABLE_OUTPUT
Plan hash value: 2687821083
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 539K| 902M| | 1005K (1)| 03:21:05 |
|* 1 | HASH JOIN OUTER | | 539K| 902M| 62M| 1005K (1)| 03:21:05 |
|* 2 | HASH JOIN | | 539K| 56M| 27M| 66402 (1)| 00:13:17 |
|* 3 | TABLE ACCESS FULL | LTC_SKU_LEAD_TIME | 559K| 20M| | 23201 (2)| 00:04:39 |
| 4 | TABLE ACCESS FULL | LTC_SKU_UNIT | 5726K| 382M| | 19570 (1)| 00:03:55 |
| 5 | VIEW | | 4157K| 6522M| | 610K (2)| 02:02:02 |
PLAN_TABLE_OUTPUT
| 6 | HASH GROUP BY | | 4157K| 229M| 303M| 610K (2)| 02:02:02 |
|* 7 | VIEW | | 4157K| 229M| | 551K (2)| 01:50:21 |
|* 8 | WINDOW SORT PUSHED RANK| | 4157K| 229M| 303M| 551K (2)| 01:50:21 |
|* 9 | TABLE ACCESS FULL | LTC_AUDIT | 4157K| 229M| | 493K (2)| 01:38:41 |
Predicate Information (identified by operation id):
1 - access("AUD"."VK_UNIT"(+)="SLT"."VK_UNIT" AND "AUD"."MODEL"(+)="SLT"."MODEL" AND
"AUD"."GEO"(+)="SLT"."GEO")
PLAN_TABLE_OUTPUT
2 - access("SLT"."VK_UNIT"="UNIT"."VK_UNIT" AND "SLT"."MODEL"="UNIT"."MODEL" AND
"SLT"."CLASS"="UNIT"."CLASS")
3 - filter(NVL("SLT"."LEAD_TIME","SLT"."REV_LEAD_TIME") IS NOT NULL)
7 - filter("DEPTH"=2)
8 - filter(ROW_NUMBER() OVER ( PARTITION BY "NOTE","NOTE2","ACTION_TYPE" ORDER BY
INTERNAL_FUNCTION("CREATION_DATE") DESC )<=2)
9 - filter((SUBSTR("ACTION_TYPE",1,8)='SKU EDD ' OR SUBSTR("ACTION_TYPE",1,8)='SKU RDD ') AND
"NOTE2" IS NOT NULL AND "ACTION_TYPE" IS NOT NULL)
30 rows selected.
SELECT COUNT(*) FROM LTC_GLOBAL.LTC_SKU--5012335
SELECT COUNT(*) FROM LTC_GLOBAL.LTC_SKU_LEAD_TIME--8060956
SELECT COUNT(*) FROM LTC_GLOBAL.LTC_AUDIT--58309887
CREATE UNIQUE INDEX LTC_GLOBAL.LTC_SKU_LEAD_TIME_PK ON LTC_GLOBAL.LTC_SKU_LEAD_TIME(VK_UNIT, MODEL, CLASS, GEO)
CREATE INDEX LTC_GLOBAL.LTC_AUDIT_LEAD_TIME ON LTC_GLOBAL.LTC_AUDIT(ACTION_TYPE)
CREATE INDEX LTC_GLOBAL.LTC_AUDIT_LEAD_TIME_DOM ON LTC_GLOBAL.LTC_AUDIT(NOTE, NOTE2, ACTION_TYPE)
CREATE INDEX LTC_GLOBAL.LTC_AUDIT_LEAD_TIME_DOM1 ON LTC_GLOBAL.LTC_AUDIT("CREATION_DATE" DESC)
Please help me.
Thanks in advance.Thanks for your response.
Sorry for violating formatting. Since I am not aware of the format options in new environment.
I have created functional based index on SUBSTR(ACTION_TYPE, 1, 8).
The cost got reduced some what.But still the query is taking 40 minutes.
The following predicate it is returning 58296618 rows.
NOTE is not null
and NOTE2 is not null
and ACTION_TYPE is not null
LTC_SKU_UNIT is a view.
The following query is used for creating this view.
SELECT unit.VK_UNIT,
unit.MODEL,
unit.CLASS,
unit.LOB,
unit.LAST_UPDATE_DATE,
unit.DESCRIPTION
FROM LTC_GLOBAL.LTC_SKU_UNIT unit;
The following indexes are created on the LTC_GLOBAL.LTC_SKU_UNIT table.
CREATE INDEX LTC_GLOBAL.LTC_SKU_UNIT_IDX_CLASS ON LTC_GLOBAL.LTC_SKU_UNIT(CLASS)
CREATE INDEX LTC_GLOBAL.LTC_SKU_UNIT_IDX_MODEL ON LTC_GLOBAL.LTC_SKU_UNIT(MODEL)
CREATE INDEX LTC_GLOBAL.LTC_SKU_UNIT_IDX_UPDATE_DATE ON LTC_GLOBAL.LTC_SKU_UNIT(LAST_UPDATE_DATE)
CREATE UNIQUE INDEX LTC_GLOBAL.LTC_SKU_UNIT_PK ON LTC_GLOBAL.LTC_SKU_UNIT(VK_UNIT, MODEL, CLASS)
Is there any way to rewrite the query to improve the performance. Any suggestions to improve the performance.
Please help me.
Thanks in advance. -
solved need help in tuning this Query
hi frs,
i have created a query like this
pls help
Regards
Rajesh
Message was edited by:
Rajesh.mani
Message was edited by:
Rajesh.maniCode and explain plan should be between [pre] and [/pre] or [code] and [/code] tags like this.
[pre]Code[/pre]An now explain plan
[code]Execution plan
[/code]
Cheers
Sarma. -
Need solution to solve this query
i want solution for shape & append query as run in access for oracle
RS.Open "SHAPE {select ID,MAX(Module_Name) AS MainMenu from USER_MODULE GROUP BY ID} APPEND ({select ID,NAME,USER_module.srno,iif(right(param_str,1)='P','ü','') as Allow,iif(left(param_str,1)='A','ü','') as Ins,iif(MID(param_str,2,1)='E','ü','') as Edit,iif(MID(param_str,3,1) = 'D','ü','') as Del,flag,CODE,NAME from USER_MODULE left join user1 on user1.srno=USER_module.srno where user_name='" & Master_Rst!USER_NAME & "' or user_name is null} RELATE ID TO ID) AS AA", G_CompCn, adOpenDynamic, adLockOptimisticThis forum is for JHeadstart related questions/suggestions. This problem seems to be related to other products. Please ask this question in the appropriate discussion forum.
kind regards,
Sandra Muller
JHeadstart Team
Oracle Consulting -
Better to write this query -- the UNION kills the query
Is there a better way to write this qery to avoid the union?
CREATE TABLE EMP
EMP_ID NUMBER,
LAST_NAME VARCHAR2(20),
FIRST_NAME VARCHAR2(20),
MID_NAME VARCHAR2(20)
CREATE TABLE EMP_NM
EMP_ID NUMBER,
LAST_NAME VARCHAR2(20),
FIRST_NAME VARCHAR2(20),
MID_NAME VARCHAR2(20)
INSERT INTO EMP
VALUES(
1, 'ANDERSON', 'SCOTT', NULL)
INSERT INTO EMP
VALUES
(2, 'KEVINSKY', 'KEVIN', NULL
INSERT INTO EMP_NM
VALUES(
1, 'ANDERSON', 'SCOTT', NULL)
INSERT INTO EMP_NM
VALUES(
1, 'LEE', 'SCOTT', 'K')
INSERT INTO EMP_NM
VALUES
(2, 'KEVINSKY', 'KEVIN', NULL )
INSERT INTO EMP_NM
VALUES
(2, 'ANDERSON', 'KEVIN', NULL )
SELECT
E.EMP_ID ,
E.LAST_NAME ,
E.FIRST_NAME ,
E.MID_NAME FROM
EMP E
WHERE
E.LAST_NAME =:LAST_NAME
UNION
SELECT
E.EMP_ID ,
E.LAST_NAME ,
E.FIRST_NAME ,
E.MID_NAME
FROM
SELECT EN.EMP_ID
FROM
EMP_NM EN
WHERE
EN.LAST_NAME =:LAST_NAME ) EN1 ,
EMP E
WHERE
E.EMP_ID = EN1.EMP_IDEXPLAIN PLAN without sort
SELECT STATEMENT Optimizer Mode=CHOOSE 171 K 6717
FILTER
TABLE ACCESS FULL EMP 171 K 5 M 6717
TABLE ACCESS BY INDEX ROWID EMP_NM 1 14 1
INDEX RANGE SCAN IDXEMP_ID 1 3
EXPLIAN PLAN WITH SORT
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
SELECT STATEMENT Optimizer Mode=CHOOSE 171 K 7658
SORT ORDER BY 171 K 5 M 7658
FILTER
TABLE ACCESS FULL EMP 171 K 5 M 6717
TABLE ACCESS BY INDEX ROWID EMP_NM 1 14 1
INDEX RANGE SCAN IDXEMP_ID 1 3 -
Need Help in tuning this query
select CO_PROFILE.CO_NO AS "UEN No.",
CO_PROFILE.CO_NAME AS "Entity Name",
DECODE(CO_PROFILE.CO_TYPE,'A1','PUBLIC COMPANY LIMITED BY SHARES',
'A3','COMPANY LIMITED BY GUARANTEE',
'A4','UNLIMITED PUBLIC COMPANY',
'B1','LIMITED PRIVATE COMPANY',
'B2','LIMITED EXEMPT PRIVATE COMPANY',
'B3','UNLIMITED PRIVATE COMPANY',
'B4','UNLIMITED EXEMPT PRIVATE COMPANY',
'F1','FOREIGN COMPANY REGISTERED IN SINGAPORE') AS "Entity Type",
M_STATUS.STATUS_DESC AS "Entity Status",
PAYMENT_DETAIL.SERVICE_CODE AS "Service Code",
PAYMENT_DETAIL.PAYMENT_CODE AS "Payment Code",
CO_TRANS_MAST.CO_TRANS_ID AS "Transaction Type",
M_PAYMENT_CODE.PAYMENT_DESC AS "Payment Description",
M_PAYMENT_CODE.REVENUE_CODE AS "Revenue Account",
CO_TRANS_MAST.NUM AS "Number Of Transactions",
PAY_NEW.UNIT_AMT AS "Revenue Amount1",
PAY_NEW.FILING_AMT AS "Revenue Amount2",
PAYMENT_DETAIL.UNIT_FEE AS "Unit Cost"
from CO_PROFILE,
M_STATUS,
PAYMENT_DETAIL,
CO_TRANS_MASTER,
(Select COUNT(CO_NO) AS "NUM",CO_TRANS_ID,CO_NO
from CO_TRANS_MASTER
group by CO_NO,CO_TRANS_ID
)CO_TRANS_MAST,
(Select Sum(UNIT_FEE) AS UNIT_AMT,
SUM(FILING_FEE) AS FILING_AMT,
TRANS_NO AS TRANS_NO
from
PAYMENT_DETAIL
group by
TRANS_NO)
PAY_NEW,
M_PAYMENT_CODE
where rownum=1
and CO_PROFILE.CO_STATUS=M_STATUS.STATUS_CODE
and M_STATUS.TRANS_ID='COMP'
and CO_TRANS_MASTER.CO_TRANS_ID=CO_TRANS_MAST.CO_TRANS_ID
and CO_TRANS_MASTER.CO_NO=CO_TRANS_MAST.CO_NO
and PAYMENT_DETAIL.TRANS_NO=CO_TRANS_MASTER.CO_TRANS_NO
and PAY_NEW.TRANS_NO=PAYMENT_DETAIL.TRANS_NO
and CO_TRANS_MAST.CO_NO= CO_PROFILE.CO_NO
and M_PAYMENT_CODE.PAYMENT_CODE=PAYMENT_DETAIL.PAYMENT_CODESomething seems wrong to me with the logical structure of the select.
1) You only get 1 row of output
but you
2) build sums for each trans_no
3) You join the table co_trans_master but at the same time you count over that one. Might be ok to do so, but it seems to be double the work.
Suggestion.
a) Build a select that joins the payment detail table. Then group this select and build the sums.
b) Add the count for the number of transactions to the select clause instead of and extra inline view in the from clause. Maybe as an analytical function if possible. -
Hi need help in writing this query
A table has three columns - id (primary key), categoryID (numeric) and
amount (numeric). The goal is to provide a query that would show categoryID
and sum of amounts within that category where categoryID is an odd number
and sum of amounts is greater than 100,000select categoryid,sum(amount) from table where mod(categoryid,2)=1
group by categoryid
having sum(amount) > 100000
Regards,
Yuri
[http://it.toolbox.com/blogs/living-happy-oracle] -
This query is taking a long time:
Hi All,
I need help in tuning this query. The stats are as below:
SQL> show parameter user_dump_dest
NAME TYPE VALUE
user_dump_dest string /opt/app/oracle/diag/rdbms/ebi
zfile/EBIZFILE/trace
SQL> show parameter optimizer
NAME TYPE VALUE
optimizer_capture_sql_plan_baselines boolean FALSE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 11.2.0.2
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
optimizer_use_invisible_indexes boolean FALSE
optimizer_use_pending_statistics boolean FALSE
optimizer_use_sql_plan_baselines boolean TRUE
SQL> show parameter db_file_multi
NAME TYPE VALUE
db_file_multiblock_read_count integer 128
SQL> show parameter db_block_size
NAME TYPE VALUE
db_block_size integer 8192
SQL> show parameter cursor_sharing
NAME TYPE VALUE
cursor_sharing string EXACT
SQL>
SQL> column sname format a20
SQL> column pname format a20
SQL> column pval2 format a20
SQL>
SQL> select
2 sname, pname, pval1, pval2
3 from
4 sys.aux_stats$;
SNAME PNAME PVAL1 PVAL2
SYSSTATS_INFO STATUS COMPLETED
SYSSTATS_INFO DSTART 11-03-2009 02:33
SYSSTATS_INFO DSTOP 11-03-2009 02:33
SYSSTATS_INFO FLAGS 1
SYSSTATS_MAIN CPUSPEEDNW 714.19791
SYSSTATS_MAIN IOSEEKTIM 10
SYSSTATS_MAIN IOTFRSPEED 4096
SYSSTATS_MAIN SREADTIM
SYSSTATS_MAIN MREADTIM
SYSSTATS_MAIN CPUSPEED
SYSSTATS_MAIN MBRC
SYSSTATS_MAIN MAXTHR
SYSSTATS_MAIN SLAVETHR
13 rows selected.
Elapsed: 00:00:00.03
SQL>
SQL> explain plan for
2 SELECT A.TRANS_NO,
3 A.TRANS_ID,
4 A.REQUEST_IND,
5 A.TRANS_STATUS_IND,
6 A.TRANS_STATUS_DATE,
7 A.DELIVERY_DATE,
8 C.EMAIL_ADDR
9 FROM IIS_TRANS_MASTER A, M_TRANS B, IIS_REQUEST_TRANS C
10 WHERE
11 C.TRANS_NO = A.TRANS_NO
12 AND A.TRANS_STATUS_IND = 'P'
13 AND A.TRANS_ID = B.TRANS_ID
14 AND A.TRANS_ID <> 'I009'
15 AND A.TRANS_ID <> 'NPKG'
16 AND B.TRANS_CO_TYPE = 'I'
17 AND A.TRANS_ID NOT IN
18 ('P012', 'P13B', 'P13C', 'P14B', 'P14C', 'P015')
19 AND B.DEPT = 'IRD'
20 ORDER BY A.CREATED_DATE;
Explained.
Elapsed: 00:00:00.01
SQL>
SQL> set pagesize 1000;
SQL> set linesize 170;
SQL> @/opt/app/oracle/product/11.2.0/rdbms/admin/utlxplp.sql
SQL> Rem
SQL> Rem $Header: utlxplp.sql 23-jan-2002.08:55:23 bdagevil Exp $
SQL> Rem
SQL> Rem utlxplp.sql
SQL> Rem
SQL> Rem Copyright (c) 1998, 2002, Oracle Corporation. All rights reserved.
SQL> Rem
SQL> Rem NAME
SQL> Rem utlxplp.sql - UTiLity eXPLain Parallel plans
SQL> Rem
SQL> Rem DESCRIPTION
SQL> Rem script utility to display the explain plan of the last explain plan
SQL> Rem command. Display also Parallel Query information if the plan happens to
SQL> Rem run parallel
SQL> Rem
SQL> Rem NOTES
SQL> Rem Assume that the table PLAN_TABLE has been created. The script
SQL> Rem utlxplan.sql should be used to create that table
SQL> Rem
SQL> Rem With SQL*plus, it is recomended to set linesize and pagesize before
SQL> Rem running this script. For example:
SQL> Rem set linesize 130
SQL> Rem set pagesize 0
SQL> Rem
SQL> Rem MODIFIED (MM/DD/YY)
SQL> Rem bdagevil 01/23/02 - rewrite with new dbms_xplan package
SQL> Rem bdagevil 04/05/01 - include CPU cost
SQL> Rem bdagevil 02/27/01 - increase Name column
SQL> Rem jihuang 06/14/00 - change order by to order siblings by.
SQL> Rem jihuang 05/10/00 - include plan info for recursive SQL in LE row source
SQL> Rem bdagevil 01/05/00 - make deterministic with order-by
SQL> Rem bdagevil 05/07/98 - Explain plan script for parallel plans
SQL> Rem bdagevil 05/07/98 - Created
SQL> Rem
SQL>
SQL> set markup html preformat on
SQL>
SQL> Rem
SQL> Rem Use the display table function from the dbms_xplan package to display the last
SQL> Rem explain plan. Use default mode which will display only relevant information
SQL> Rem
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
Plan hash value: 3822676895
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 38075 | 3123K| | 22550 (2)| 00:04:31 |
| 1 | SORT ORDER BY | | 38075 | 3123K| 3472K| 22550 (2)| 00:04:31 |
|* 2 | HASH JOIN | | 38075 | 3123K| 2120K| 21801 (2)| 00:04:22 |
| 3 | NESTED LOOPS | | | | | | |
| 4 | NESTED LOOPS | | 38075 | 1673K| | 4177 (1)| 00:00:51 |
|* 5 | TABLE ACCESS FULL | M_TRANS | 10 | 80 | | 7 (0)| 00:00:01 |
|* 6 | INDEX RANGE SCAN | IDX_IIS_TRANS_ID | 39401 | | | 109 (3)| 00:00:02 |
|* 7 | TABLE ACCESS BY INDEX ROWID| IIS_TRANS_MASTER | 3940 | 142K| | 3186 (1)| 00:00:39 |
| 8 | TABLE ACCESS FULL | IIS_REQUEST_TRANS | 2114K| 78M| | 12368 (2)| 00:02:29 |
Predicate Information (identified by operation id):
2 - access("C"."TRANS_NO"="A"."TRANS_NO")
5 - filter("B"."DEPT"='IRD' AND "B"."TRANS_CO_TYPE"='I' AND "B"."TRANS_ID"<>'I009' AND
"B"."TRANS_ID"<>'NPKG' AND "B"."TRANS_ID"<>'P012' AND "B"."TRANS_ID"<>'P13B' AND
"B"."TRANS_ID"<>'P13C' AND "B"."TRANS_ID"<>'P14B' AND "B"."TRANS_ID"<>'P14C' AND
"B"."TRANS_ID"<>'P015')
6 - access("A"."TRANS_ID"="B"."TRANS_ID")
filter("A"."TRANS_ID"<>'I009' AND "A"."TRANS_ID"<>'NPKG' AND "A"."TRANS_ID"<>'P012' AND
"A"."TRANS_ID"<>'P13B' AND "A"."TRANS_ID"<>'P13C' AND "A"."TRANS_ID"<>'P14B' AND
"A"."TRANS_ID"<>'P14C' AND "A"."TRANS_ID"<>'P015')
7 - filter("A"."TRANS_STATUS_IND"='P')
29 rows selected.
Elapsed: 00:00:00.02
SQL>
SQL> rollback;
Rollback complete.
Elapsed: 00:00:00.00
SQL>
SQL> rem Set the ARRAYSIZE according to your application
SQL> set autotrace traceonly arraysize 100
SQL>
SQL> alter session set tracefile_identifier = 'mytrace1';
Session altered.
Elapsed: 00:00:00.00
SQL>
SQL> rem if you're using bind variables
SQL> rem define them here
SQL>
SQL> rem variable b_var1 number
SQL> rem variable b_var2 varchar2(20)
SQL>
SQL> rem and initialize them
SQL>
SQL> rem exec :b_var1 := 1
SQL> rem exec :b_var2 := 'DIAG'
SQL> set pagesize 1000;
SQL> set linesize 170;
SQL> alter session set events '10046 trace name context forever, level 8';
Session altered.
Elapsed: 00:00:00.00
SQL> SELECT A.TRANS_NO,
2 A.TRANS_ID,
3 A.REQUEST_IND,
4 A.TRANS_STATUS_IND,
5 A.TRANS_STATUS_DATE,
6 A.DELIVERY_DATE,
7 C.EMAIL_ADDR
8 FROM IIS_TRANS_MASTER A, M_TRANS B, IIS_REQUEST_TRANS C
9 WHERE
10 C.TRANS_NO = A.TRANS_NO
11 AND A.TRANS_STATUS_IND = 'P'
12 AND A.TRANS_ID = B.TRANS_ID
13 AND A.TRANS_ID <> 'I009'
14 AND A.TRANS_ID <> 'NPKG'
15 AND B.TRANS_CO_TYPE = 'I'
16 AND A.TRANS_ID NOT IN
17 ('P012', 'P13B', 'P13C', 'P14B', 'P14C', 'P015')
18 AND B.DEPT = 'IRD'
19 ORDER BY A.CREATED_DATE;
19 rows selected.
Elapsed: 00:00:15.44
Execution Plan
Plan hash value: 3822676895
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 38075 | 3123K| | 22550 (2)| 00:04:31 |
| 1 | SORT ORDER BY | | 38075 | 3123K| 3472K| 22550 (2)| 00:04:31 |
|* 2 | HASH JOIN | | 38075 | 3123K| 2120K| 21801 (2)| 00:04:22 |
| 3 | NESTED LOOPS | | | | | | |
| 4 | NESTED LOOPS | | 38075 | 1673K| | 4177 (1)| 00:00:51 |
|* 5 | TABLE ACCESS FULL | M_TRANS | 10 | 80 | | 7 (0)| 00:00:01 |
|* 6 | INDEX RANGE SCAN | IDX_IIS_TRANS_ID | 39401 | | | 109 (3)| 00:00:02 |
|* 7 | TABLE ACCESS BY INDEX ROWID| IIS_TRANS_MASTER | 3940 | 142K| | 3186 (1)| 00:00:39 |
| 8 | TABLE ACCESS FULL | IIS_REQUEST_TRANS | 2114K| 78M| | 12368 (2)| 00:02:29 |
Predicate Information (identified by operation id):
2 - access("C"."TRANS_NO"="A"."TRANS_NO")
5 - filter("B"."DEPT"='IRD' AND "B"."TRANS_CO_TYPE"='I' AND "B"."TRANS_ID"<>'I009' AND
"B"."TRANS_ID"<>'NPKG' AND "B"."TRANS_ID"<>'P012' AND "B"."TRANS_ID"<>'P13B' AND
"B"."TRANS_ID"<>'P13C' AND "B"."TRANS_ID"<>'P14B' AND "B"."TRANS_ID"<>'P14C' AND
"B"."TRANS_ID"<>'P015')
6 - access("A"."TRANS_ID"="B"."TRANS_ID")
filter("A"."TRANS_ID"<>'I009' AND "A"."TRANS_ID"<>'NPKG' AND "A"."TRANS_ID"<>'P012' AND
"A"."TRANS_ID"<>'P13B' AND "A"."TRANS_ID"<>'P13C' AND "A"."TRANS_ID"<>'P14B' AND
"A"."TRANS_ID"<>'P14C' AND "A"."TRANS_ID"<>'P015')
7 - filter("A"."TRANS_STATUS_IND"='P')
Statistics
23 recursive calls
0 db block gets
164826 consistent gets
74235 physical reads
0 redo size
1839 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
19 rows processed
SQL>
SQL> disconnect
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing optionsHi Manik,
1) Not really. Order by may not be required.
2) After gathering the stats, below is the result:
NAME_COL_PLUS_SHOW_PARAM TYPE
VALUE_COL_PLUS_SHOW_PARAM
user_dump_dest string
/opt/app/oracle/diag/rdbms/ebizfile/EBIZFILE/trace
SQL> show parameter optimizer
NAME_COL_PLUS_SHOW_PARAM TYPE
VALUE_COL_PLUS_SHOW_PARAM
Elapsed: 00:00:00.05
SQL> SELECT A.TRANS_NO,
2 A.TRANS_ID,
3 A.REQUEST_IND,
4 A.TRANS_STATUS_IND,
5 A.TRANS_STATUS_DATE,
6 A.DELIVERY_DATE,
7 C.EMAIL_ADDR
8 FROM IIS_TRANS_MASTER A, M_TRANS B, IIS_REQUEST_TRANS C
9 WHERE
10 C.TRANS_NO = A.TRANS_NO
11 AND A.TRANS_STATUS_IND = 'P'
12 AND A.TRANS_ID = B.TRANS_ID
13 AND A.TRANS_ID <> 'I009'
14 AND A.TRANS_ID <> 'NPKG'
15 AND B.TRANS_CO_TYPE = 'I'
16 AND A.TRANS_ID NOT IN
17 ('P012', 'P13B', 'P13C', 'P14B', 'P14C', 'P015')
18 AND B.DEPT = 'IRD'
19 ORDER BY A.CREATED_DATE;
20 rows selected.
Elapsed: 00:00:06.58
Execution Plan
Plan hash value: 3822676895
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 38091 | 3124K| | 22553 (2)| 00:04:31 |
| 1 | SORT ORDER BY | | 38091 | 3124K| 3472K| 22553 (2)| 00:04:31 |
|* 2 | HASH JOIN | | 38091 | 3124K| 2128K| 21804 (2)| 00:04:22 |
| 3 | NESTED LOOPS | | | | | | |
| 4 | NESTED LOOPS | | 38091 | 1673K| | 4180 (1)| 00:00:51 |
|* 5 | TABLE ACCESS FULL | M_TRANS | 10 | 80 | | 7 (0)| 00:00:01 |
|* 6 | INDEX RANGE SCAN | IDX_IIS_TRANS_ID | 39418 | | | 109 (3)| 00:00:02 |
|* 7 | TABLE ACCESS BY INDEX ROWID| IIS_TRANS_MASTER | 3942 | 142K| | 3189 (1)| 00:00:39 |
| 8 | TABLE ACCESS FULL | IIS_REQUEST_TRANS | 2114K| 78M| | 12368 (2)| 00:02:29 |
Predicate Information (identified by operation id):
2 - access("C"."TRANS_NO"="A"."TRANS_NO")
5 - filter("B"."DEPT"='IRD' AND "B"."TRANS_CO_TYPE"='I' AND "B"."TRANS_ID"<>'I009' AND
"B"."TRANS_ID"<>'NPKG' AND "B"."TRANS_ID"<>'P012' AND "B"."TRANS_ID"<>'P13B' AND
"B"."TRANS_ID"<>'P13C' AND "B"."TRANS_ID"<>'P14B' AND "B"."TRANS_ID"<>'P14C' AND
"B"."TRANS_ID"<>'P015')
6 - access("A"."TRANS_ID"="B"."TRANS_ID")
filter("A"."TRANS_ID"<>'I009' AND "A"."TRANS_ID"<>'NPKG' AND "A"."TRANS_ID"<>'P012' AND
"A"."TRANS_ID"<>'P13B' AND "A"."TRANS_ID"<>'P13C' AND "A"."TRANS_ID"<>'P14B' AND
"A"."TRANS_ID"<>'P14C' AND "A"."TRANS_ID"<>'P015')
7 - filter("A"."TRANS_STATUS_IND"='P')
Statistics
17 recursive calls
0 db block gets
158643 consistent gets
49083 physical reads
0 redo size
1917 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
20 rows processedI am yet to try the DBMS_SQLTUNE.
Are you able to give me in simplified form the steps in executing this query for the DBMS_SQLTUNE? Thanks! -
Need help to get alternate or better way to write query
Hi,
I am on Oracle 11.2
DDL and sample data
create table tab1 -- 1 millions rows at any given time
id number not null,
ref_cd varchar2(64) not null,
key varchar2(44) not null,
ctrl_flg varchar2(1),
ins_date date
create table tab2 -- close to 100 million rows
id number not null,
ref_cd varchar2(64) not null,
key varchar2(44) not null,
ctrl_flg varchar2(1),
ins_date date,
upd_date date
insert into tab1 values (1,'ABCDEFG', 'XYZ','Y',sysdate);
insert into tab1 values (2,'XYZABC', 'DEF','Y',sysdate);
insert into tab1 values (3,'PORSTUVW', 'ABC','Y',sysdate);
insert into tab2 values (1,'ABCDEFG', 'WYZ','Y',sysdate);
insert into tab2 values (2,'tbVCCmphEbOEUWbxRKczvsgmzjhROXOwNkkdxWiPqDgPXtJhVl', 'ABLIOWNdj','Y',sysdate);
insert into tab2 values (3,'tbBCFkphEbOEUWbxATczvsgmzjhRQWOwNkkdxWiPqDgPXtJhVl', 'MQLIOWNdj','Y',sysdate);I need to get all rows from tab1 that does not match tab2 and any row from tab1 that matches ref_cd in tab2 but key is different.
Expected Query output
'ABCDEFG', 'WYZ'
'XYZABC', 'DEF'
'PORSTUVW', 'ABC'Existing Query
select
ref_cd,
key
from
select
ref_cd,
key
from
tab1, tab2
where
tab1.ref_cd = tab2.ref_cd and
tab1.key <> tab2.key
union
select
ref_cd,
key
from
tab1
where
not exists
select 1
from
tab2
where
tab2.ref_cd = tab1.ref_cd
);I am sure there will be an alternate way to write this query in better way. Appreciate if any of you gurus suggest alternative solution.
Thanks in advance.Hi,
user572194 wrote:
... DDL and sample data ...
create table tab2 -- close to 100 million rows
id number not null,
ref_cd varchar2(64) not null,
key varchar2(44) not null,
ctrl_flg varchar2(1),
ins_date date,
upd_date date
insert into tab2 values (1,'ABCDEFG', 'WYZ','Y',sysdate);
insert into tab2 values (2,'tbVCCmphEbOEUWbxRKczvsgmzjhROXOwNkkdxWiPqDgPXtJhVl', 'ABLIOWNdj','Y',sysdate);
insert into tab2 values (3,'tbBCFkphEbOEUWbxATczvsgmzjhRQWOwNkkdxWiPqDgPXtJhVl', 'MQLIOWNdj','Y',sysdate);
Thanks for posting the CREATE TABLE and INSERT statments. Remember why you go to all that trouble: so the people whop want to help you can re-create the problem and test their ideas. When you post statemets that don't work, it's just a waste of time.
None of the INSERT statements for tab2 work. Tab2 has 6 columns, but the INSERT statements only have 5 values.
Please test your code before you post it.
I need to get all rows from tab1 that does not match tab2 WHat does "match" mean in this case? Does it mean that tab1.ref_cd = tab2.ref_cd?
and any row from tab1 that matches ref_cd in tab2 but key is different.
Existing Query
select
ref_cd,
key
from
select
ref_cd,
key
from
tab1, tab2
where
tab1.ref_cd = tab2.ref_cd and
tab1.key <> tab2.key
union
select
ref_cd,
key
from
tab1
where
not exists
select 1
from
tab2
where
tab2.ref_cd = tab1.ref_cd
Does that really work? In the first branch of the UNION, you're referencing a column called key, but both tables involved have columns called key. I would expect that to cause an error.
Please test your code before you post it.
Right before UNION, did you mean
tab1.key != tab2.key? As you may have noticed, this site doesn't like to display the <> inequality operator. Always use the other (equivalent) inequality operator, !=, when posting here.
I am sure there will be an alternate way to write this query in better way. Appreciate if any of you gurus suggest alternative solution.Avoid UNION; it can be very inefficient.
Maybe you want something like this:
SELECT tab1.ref_cd
, tab1.key
FROM tab1
LEFT OUTER JOIN tab2 ON tab2.ref_cd = tab1.ref_cd
WHERE tab2.ref_cd IS NULL
OR tab2.key != tab1.key
; -
I need to clarify how I can use adobe as a host for my site for free. I see where business catalyst is supposed to be temporary as well as it is recommended to use as the better alternative to launch my muse site. But then I have to use the long extension of "businesscatalyst" in addition to the domain name I'd prefer. How exactly can I take it live? do I have to use a third party hosting?
Hi,
Once you are done with your sitet, Click on Publish in Muse, select New Site from the drop down, It will ask you a name for your site, which will be used for site url, you will get a url like mysite.businesscatalyst.com, then go to the browser and login to the admin panel, mysite.businesscatalyst.com/admin and on Dashboard, click Launch site. This will push your site live, and you can then add your custom domain.
Also make sure that you have completed all these actions mentioned here
User manual
Do let me know if you have any question. -
Is there any better option than this slow query?
Hi all,
i want to find out lets say Ticekt no range from Variable1 - Variable 2, are all ready existed or missing from my ticket master table which is having a million records and the no grows timely.
For example i want to find out in range 30000 - 50000
if any missings it should give missing number are
34567
45678 etc . etc.
i wrote a for.. loop and im checking one bye one from ticket master table using select count(*) from ticket_master where ticket_no = var, which is time consuming and server becoming slow when i issue this query. my ticket master ticket_no is indexed.
any better idea advise please..I am not sure I understand your problem correctly.
Here are some test datas:
create table ticket_masters ( ticket_no number) ;
exec for i in 1..1000 loop insert into ticket_masters values (round(i/0.97)); end loop
select 200-1+rownum missing from ticket_masters where rownum<=300-200
minus
select ticket_no from ticket_masters where ticket_no between 200 and 300
MISSING
217
250
283i am select rownum from ticket_masters, but I could select from anything actually, a pl/sql table, dual group by cube(1,1,1,1,1,1,1,1,1,1), all_objects, ...
Could you please do a desc ticket_masters to show me your datatype and also select a few ticket_no
Regards
Laurent -
Please need help with this query
Hi !
Please need help with this query:
Needs to show (in cases of more than 1 loan offer) the latest create_date one time.
Meaning, In cases the USER_ID, LOAN_ID, CREATE_DATE are the same need to show only the latest, Thanks!!!
select distinct a.id,
create_date,
a.loanid,
a.rate,
a.pays,
a.gracetime,
a.emailtosend,
d.first_name,
d.last_name,
a.user_id
from CLAL_LOANCALC_DET a,
loan_Calculator b,
bv_user_profile c,
bv_mr_user_profile d
where b.loanid = a.loanid
and c.NET_USER_NO = a.resp_id
and d.user_id = c.user_id
and a.is_partner is null
and a.create_date between
TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
order by a.create_datePerhaps something like this...
select id, create_date, loanid, rate, pays, gracetime, emailtosend, first_name, last_name, user_id
from (
select distinct a.id,
create_date,
a.loanid,
a.rate,
a.pays,
a.gracetime,
a.emailtosend,
d.first_name,
d.last_name,
a.user_id,
max(create_date) over (partition by a.user_id, a.loadid) as max_create_date
from CLAL_LOANCALC_DET a,
loan_Calculator b,
bv_user_profile c,
bv_mr_user_profile d
where b.loanid = a.loanid
and c.NET_USER_NO = a.resp_id
and d.user_id = c.user_id
and a.is_partner is null
and a.create_date between
TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
where create_date = max_create_date
order by create_date -
Please help to modifiy this query for better performance
Please help to rewrite this query for better performance. This is taking long time to execute.
Table t_t_bil_bil_cycle_change contains 1200000 rows and table t_acctnumberTab countains 200000 rows.
I have created index on ACCOUNT_ID
Query is shown below
update rbabu.t_t_bil_bil_cycle_change a
set account_number =
( select distinct b.account_number
from rbabu.t_acctnumberTab b
where a.account_id = b.account_id
Table structure is shown below
SQL> DESC t_acctnumberTab;
Name Type Nullable Default Comments
ACCOUNT_ID NUMBER(10)
ACCOUNT_NUMBER VARCHAR2(24)
SQL> DESC t_t_bil_bil_cycle_change;
Name Type Nullable Default Comments
ACCOUNT_ID NUMBER(10)
ACCOUNT_NUMBER VARCHAR2(24) YIshan's solution is good. I would avoid updating rows which already have the right value - it's a waste of time.
You should have a UNIQUE or PRIMARY KEY constraint on t_acctnumberTab.account_id
merge rbabu.t_t_bil_bil_cycle_change a
using
( select distinct account_number, account_id
from rbabu.t_acctnumberTab
) t
on ( a.account_id = b.account_id
and decode(a.account_number, b.account_number, 0, 1) = 1
when matched then
update set a.account_number = b.account_number -
I need that this query return only one value
Hi, please. I need your help. I have this query:
SELECT c.charvalue "Comentario", max(pi.id) as "id" --into :gcpe_last_comment
FROM twflprocessinstances pi, twfliprocessparameters c
WHERE pi.id = c.iprocess_id
AND c.param_id = 1002286
AND c.charvalue IS NOT NULL
AND pi.processdef_id = 1600
AND to_number(pi.id) <> 3817940
AND to_number(pi.seeparameter1) =80137377
group by c.charvalue
having max(pi.id)
This query return 3 rows, but I need that this query return only one row. The row that this query should return is the row before at the max id. ThanksMmmm...I don't get it.
You might need to post some sample data and expected results.
Maybe you are looking for
-
Need to upgrade sound driver in HP dx2390 OS: Windows 7 Home Premium 32 BIT
Hi ! I have just installed windows 7 on my desktop pc model: dx2390 Microtower hp s/n: 3cb91022f4 i download the sound the sound driver from hp drivers support but its not working. I update windows and realtek sound driver has been installed but i go
-
Bpartner - Link between customer and vendor if its the same face
Hello As I understood the primary idea to keep all business partners together is to make a link between differant roles of the same partner (like link customer and vendor if its the same face). Please correct me if I am wrong. The questions is : how
-
does anyone know how to fix this? it's driving me insane idk what to do!!! It hasn't been working for three days now, and i really need it to! I also tried taking off my iMessage but nothing changed. HELP!!
-
Smart form dynamic tray selection on printing
Hi Experts, I have a requirement in smart form that need to output the a particular invoice to a particular tray a printer. For e.g. tray 2. I have added TRY02 to the resource name of the pages in the smartform, but still the invoice is being printed
-
I'm so excited! This is the first time I have posted a question. I hope I know how to do it right. Yes, I have read related articles. Here is my question. After having received my daily podcast for several months, I accidentally discovered that the l