Tune hierarchy query
Hi,
I have a table which holds geographical data in a hierrachical format. I need to retriev all the parent-information in a single query.
The table is called CX_GEO_DATA, which stores hierrarchy relations .
eg of data
row_id type name parent_id start_dt end_dt
1 Zip 400 2 1/2/2009 1/1/2020
2 City San
I need to extract all the parent information from the table, i.e. given a row_id, find its parents.
Since it is a part of UI requiremnt a performence of 5 secs is desired.
SELECT A.type,
a.name,
A.ALT_NAME,
LEVEL,
a.start_dt,
a.end_dt,
a.par_geo_data_id,
a.row_id
FROM cx_geo_data A
WHERE TRUNC(SYSDATE) BETWEEN START_DT AND NVL(END_DT,SYSDATE+1)
START WITH row_id = :p_row_id
CONNECT BY PRIOR par_geo_data_id = row_id
There are indexes in table on columns:
Non unique par_geo_data_id
Non unique name
Unique Row_id (Primary key)
I need result in the below form:
i.e. given a row_id find all the parents for that record.
Say if I get a Zip, get all its parents, i.e. Country, state, City, Zip etc
To achieve that I have written a function:
Which uses the query listed on top. i.e. a connect by query and returns a given type of parent.
Below is the function code:
FUNCTION get_par_at_a_level_info
p_row_id varchar2,
p_type_of_Parent varchar2
RETURN VARCHAR2
IS
vParent_Name cx_geo_data.alt_name%type;
BEGIN
SELECT alt_name
INTO vParent_Name
FROM (
SELECT A.type,
a.name,
A.ALT_NAME,
LEVEL,
a.row_id
FROM cx_geo_data A
WHERE TRUNC(SYSDATE) BETWEEN START_DT AND NVL(END_DT,SYSDATE+1)
START WITH row_id = p_row_id
CONNECT BY PRIOR par_geo_data_id = row_id
)hier_tab
WHERE hier_tab.type=p_type_of_Parent;
return(initCap(vParent_Name));
EXCEPTION
WHEN no_data_found
THEN RETURN NULL;
WHEN OTHERS
THEN RAISE;
END get_par_at_a_level_info;
So, if I need type of parent as Country I pass country to it, if I need City I pass City to the function.
So, my final query is like:
SELECT GEO_TYPE,
GEO_NAME,
geoElementId GEO_ELEMENT_ID,
xxfdev_geo_bndary_pkg.Get_Par_at_a_level_info(geoElementId,'Country') COUNTRY,
xxfdev_geo_bndary_pkg.Get_Par_at_a_level_info(geoElementId,'State') STATE,
--- xxfdev_geo_bndary_pkg.Get_Par_at_a_level_info(geoElementId,'City') CITY,
xxfdev_geo_bndary_pkg.Get_Par_at_a_level_info(geoElementId,'Zip') ZIP
FROM ( SELECT
---------restirction by user ideally nt reqd
terr_gb.name NAME,
INITCAP(geo.alt_name) GEO_NAME,
geo.geoElementId,
geo.TYPE GEO_TYPE,
from cx_geo_data
where row_id=p_row_id
);
let me know on how to tune this query or if there is any option to re-write it in any other form.
Similar Messages
-
Hi,
I'm using below query in procedure.It's taking more more time can some one help to tune this query or advice to rewrite the query.
Databse :10.1
SELECT 'Reading Comprehension' TEST_NAME,T.TEST_END_DATE TEST_SESSION_DATE,
C.POOL_VERSION_ID, I.CREATED_ON POOL_CREATED_DT,
C.ITEM_ID, C.ITEM_RESPONSE_ID, S.STUDENT_ID_PK, C.RESPONSE_KEY, C.IS_CORRECT RESPONSE_IS_CORRECT,
T.SCORE SCALE_SCORE, C.RESPONSE_DURATION, P.ITEM_KEY,
T.TEST_SESSION_DETAIL_ID, SYSDATE CREATED_ON
-- BULK COLLECT INTO TV_PSYCHO_DET
FROM
CAT_ITEM_PARAMETER P, CAT_ITEM_USER_RESPONSE C, TEST_SESSION_DETAIL T,
TEST_SESSION S, ITEM_POOL_VERSION I, TEST_DETAIL D
,INSTITUTION E
WHERE TRUNC(T.TEST_END_DATE) BETWEEN TO_DATE('01-11-09','dd-mm-yy') AND TO_DATE('30-11-09','dd-mm-yy')
AND D.TEST_NAME = 'Reading Comprehension'
AND T.TEST_SESSION_STATUS_ID = 3
AND I.POOL_AVAILABILITY='Y'
AND P.PRETEST=0 AND C.RESTART_FLAG=0
AND T.TEST_DETAIL_ID = D.TEST_DETAIL_ID
AND S.TEST_SESSION_ID = T.TEST_SESSION_ID
AND C.TEST_SESSION_DETAIL_ID = T.TEST_SESSION_DETAIL_ID
AND S.INSTITUTION_ID=E.INSTITUTION_ID
AND SUBSTR(E.INSTITUTION_ID_DISPLAY,8,3) <> '000'
AND I.ITEM_ID = C.ITEM_ID
AND P.ITEM_ID = I.ITEM_ID;expln plan
Plan hash value: 3712814491
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart|
Pstop |
| 0 | SELECT STATEMENT | | 50857 | 7151K| 93382 (1)| 00:18:41 | |
|
|* 1 | FILTER | | | | | | |
|
|* 2 | HASH JOIN | | 50857 | 7151K| 93382 (1)| 00:18:41 | |
|
| 3 | PARTITION HASH ALL | | 2312 | 23120 | 25 (0)| 00:00:01 | 1 |
5 |
|* 4 | TABLE ACCESS FULL | CAT_ITEM_PARAMETER | 2312 | 23120 | 25 (0)| 00:00:01 | 1 |
5 |
|* 5 | HASH JOIN | | 94938 | 12M| 93356 (1)| 00:18:41 | |
|
|* 6 | TABLE ACCESS FULL | ITEM_POOL_VERSION | 9036 | 132K| 30 (0)| 00:00:01 | |
|
|* 7 | TABLE ACCESS BY GLOBAL INDEX ROWID | CAT_ITEM_USER_RESPONSE | 9 | 279 | 18 (0)| 00:00:01 | ROWID |
ROWID |
| 8 | NESTED LOOPS | | 45349 | 5270K| 93325 (1)| 00:18:40 | |
|
|* 9 | HASH JOIN | | 4923 | 423K| 11377 (1)| 00:02:17 | |
|
|* 10 | INDEX FAST FULL SCAN | INSTI_ID_NAME_COUN_DISP_IDX | 8165 | 111K| 18 (0)| 00:00:01 | |
|
|* 11 | HASH JOIN | | 4923 | 355K| 11359 (1)| 00:02:17 | |
|
|* 12 | TABLE ACCESS BY GLOBAL INDEX ROWID| TEST_SESSION_DETAIL | 4107 | 148K| 6804 (1)| 00:01:22 | ROWID |
ROWID |
| 13 | NESTED LOOPS | | 4923 | 278K| 6806 (1)| 00:01:22 | |
|
|* 14 | INDEX RANGE SCAN | TEST_DETAIL_AK_1 | 1 | 21 | 2 (0)| 00:00:01 | |
|
|* 15 | INDEX RANGE SCAN | TEST_SESSION_DETAIL_FK2_I | 39737 | | 102 (0)| 00:00:02 | |
|
| 16 | PARTITION HASH ALL | | 1672K| 25M| 4546 (1)| 00:00:55 | 1 |
5 |
| 17 | TABLE ACCESS FULL | TEST_SESSION | 1672K| 25M| 4546 (1)| 00:00:55 | 1 |
5 |
|* 18 | INDEX RANGE SCAN | CAT_ITEM_USER_RESP_IDX1 | 18 | | 3 (0)| 00:00:01 | |
|
Predicate Information (identified by operation id):
1 - filter(TO_DATE('01-11-09','dd-mm-yy')<=TO_DATE('30-11-09','dd-mm-yy'))
2 - access("P"."ITEM_ID"="I"."ITEM_ID")
4 - filter("P"."PRETEST"=0)
5 - access("I"."ITEM_ID"="C"."ITEM_ID")
6 - filter("I"."POOL_AVAILABILITY"='Y')
7 - filter(TO_NUMBER("C"."RESTART_FLAG")=0)
9 - access("S"."INSTITUTION_ID"="E"."INSTITUTION_ID")
10 - filter(SUBSTR("E"."INSTITUTION_ID_DISPLAY",8,3)<>'000')
11 - access("S"."TEST_SESSION_ID"="T"."TEST_SESSION_ID")
12 - filter(TRUNC(INTERNAL_FUNCTION("T"."TEST_END_DATE"))>=TO_DATE('01-11-09','dd-mm-yy') AND "T"."TEST_SESSION_STATUS_ID"=3
AND TRUNC(INTERNAL_FUNCTION("T"."TEST_END_DATE"))<=TO_DATE('30-11-09','dd-mm-yy'))
14 - access("D"."TEST_NAME"='Reading Comprehension')
15 - access("T"."TEST_DETAIL_ID"="D"."TEST_DETAIL_ID")
18 - access("C"."TEST_SESSION_DETAIL_ID"="T"."TEST_SESSION_DETAIL_ID")
43 rows selected.Edited by: user575115 on Dec 18, 2009 12:31 AMWhen you see something like ...
7 - filter(TO_NUMBER("C"."RESTART_FLAG")=0) It means that Oracle had to do a conversion for you since you aren't using the proper data type in your query.
That would mean IF there is an index on that column, it won't be useable... -
Sql Query Tuning. Please help me to tune this query
Hi All ,
I have this problematic Sql . It is taking huge time to execute. It contains a view CIDV, which i think is the bottleneck.
I have pasted the query below. I will be pasting TKPROF and explain plan for the same. Please advice me to tune this query.
SELECT GCC.SEGMENT1 || '.' || GCC.SEGMENT2 || '.' || GCC.SEGMENT3 || '.' ||
GCC.SEGMENT4 || '.' || GCC.SEGMENT5 || '.' || GCC.SEGMENT6 || '.' ||
GCC.SEGMENT7 || '.' || GCC.SEGMENT8 || '.' || GCC.SEGMENT9 OFFSET_ACCOUNT,
OOD.ORGANIZATION_CODE,
CIDV.SUBINVENTORY_CODE OFFSET_SUBINV,
MIL.SEGMENT1 || '.' || MIL.SEGMENT2 || '.' || MIL.SEGMENT3 || '.' ||
MIL.SEGMENT4 || '.' || MIL.SEGMENT5 OFFSET_LOCATOR,
CIDV.LAST_UPDATE_LOGIN
FROM APPS.CST_INV_DISTRIBUTION_V CIDV,
APPS.GL_CODE_COMBINATIONS GCC,
APPS.MTL_ITEM_LOCATIONS MIL,
APPS.ORG_ORGANIZATION_DEFINITIONS OOD
WHERE CIDV.TRANSACTION_ID = :B2
AND CIDV.PRIMARY_QUANTITY = (-1) * :B1
AND CIDV.REFERENCE_ACCOUNT = GCC.CODE_COMBINATION_ID
AND OOD.ORGANIZATION_ID = CIDV.ORGANIZATION_ID
AND MIL.INVENTORY_LOCATION_ID = CIDV.LOCATOR_ID
AND GCC.ACCOUNT_TYPE = 'A'****************
TKPROF
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 68337 10.32 10.32 0 0 0 0
Fetch 68337 229.75 936.36 58819 6743323 1121 68232
total 136675 240.07 946.69 58819 6743323 1121 68232
Misses in library cache during parse: 1
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 203 (recursive depth: 1)
Number of plan statistics captured: 1
Rows (1st) Rows (avg) Rows (max) Row Source Operation
1 1 1 MERGE JOIN CARTESIAN (cr=102 pr=15 pw=0 time=193608 us cost=56 size=219 card=1)
1 1 1 NESTED LOOPS (cr=100 pr=15 pw=0 time=193483 us cost=53 size=219 card=1)
1 1 1 NESTED LOOPS (cr=99 pr=15 pw=0 time=193407 us cost=52 size=215 card=1)
1 1 1 NESTED LOOPS (cr=96 pr=15 pw=0 time=193378 us cost=51 size=190 card=1)
1 1 1 NESTED LOOPS (cr=93 pr=15 pw=0 time=193284 us cost=49 size=162 card=1)
1 1 1 NESTED LOOPS (cr=89 pr=14 pw=0 time=185515 us cost=46 size=138 card=1)
1 1 1 NESTED LOOPS (cr=85 pr=12 pw=0 time=157975 us cost=44 size=81 card=1)
1 1 1 NESTED LOOPS (cr=83 pr=12 pw=0 time=157925 us cost=43 size=73 card=1)
1 1 1 NESTED LOOPS (cr=81 pr=12 pw=0 time=157641 us cost=43 size=132 card=2)
1 1 1 VIEW CST_INV_DISTRIBUTION_V (cr=78 pr=12 pw=0 time=156386 us cost=41 size=118 card=2)
1 1 1 UNION-ALL (cr=78 pr=12 pw=0 time=156378 us)
0 0 0 NESTED LOOPS OUTER (cr=44 pr=9 pw=0 time=124997 us cost=20 size=291 card=1)
0 0 0 NESTED LOOPS (cr=44 pr=9 pw=0 time=124993 us cost=18 size=255 card=1)
0 0 0 NESTED LOOPS (cr=44 pr=9 pw=0 time=124990 us cost=18 size=251 card=1)
33 33 33 MERGE JOIN CARTESIAN (cr=25 pr=6 pw=0 time=98544 us cost=14 size=192 card=1)
1 1 1 NESTED LOOPS OUTER (cr=22 pr=5 pw=0 time=85754 us cost=12 size=156 card=1)
1 1 1 NESTED LOOPS (cr=19 pr=4 pw=0 time=79830 us cost=10 size=120 card=1)
1 1 1 NESTED LOOPS OUTER (cr=17 pr=4 pw=0 time=79813 us cost=9 size=113 card=1)
1 1 1 NESTED LOOPS (cr=15 pr=4 pw=0 time=79752 us cost=8 size=106 card=1)
1 1 1 NESTED LOOPS (cr=11 pr=2 pw=0 time=43120 us cost=6 size=93 card=1)
1 1 1 NESTED LOOPS (cr=7 pr=2 pw=0 time=43087 us cost=4 size=83 card=1)
1 1 1 NESTED LOOPS (cr=6 pr=2 pw=0 time=43072 us cost=4 size=80 card=1)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_MATERIAL_TRANSACTIONS (cr=5 pr=2 pw=0 time=43042 us cost=4 size=76 card=1)
1 1 1 INDEX UNIQUE SCAN MTL_MATERIAL_TRANSACTIONS_U1 (cr=4 pr=2 pw=0 time=43011 us cost=3 size=0 card=1)(object id 12484094)
1 1 1 INDEX UNIQUE SCAN MTL_TRANSACTION_TYPES_U1 (cr=1 pr=0 pw=0 time=20 us cost=0 size=764 card=191)(object id 9983)
1 1 1 INDEX UNIQUE SCAN MTL_TXN_SOURCE_TYPES_U1 (cr=1 pr=0 pw=0 time=7 us cost=0 size=54 card=18)(object id 9987)
1 1 1 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=4 pr=0 pw=0 time=27 us cost=2 size=736324450 card=73632445)(object id 12484155)
1 1 1 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_TL_U1 (cr=4 pr=2 pw=0 time=36626 us cost=2 size=957481070 card=73652390)(object id 12484137)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=42 us cost=1 size=3290 card=470)
1 1 1 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=28 us cost=0 size=0 card=1)(object id 9847)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=12 us cost=1 size=3290 card=470)
1 1 1 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=7 us cost=0 size=0 card=1)(object id 9847)
0 0 0 INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=1 pw=0 time=5915 us cost=2 size=36 card=1)(object id 705891)
33 33 33 BUFFER SORT (cr=3 pr=1 pw=0 time=12713 us cost=12 size=36 card=1)
33 33 33 INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=1 pw=0 time=12582 us cost=2 size=36 card=1)(object id 705891)
0 0 0 TABLE ACCESS BY INDEX ROWID MTL_TRANSACTION_ACCOUNTS (cr=19 pr=3 pw=0 time=26591 us cost=4 size=59 card=1)
66 66 66 INDEX RANGE SCAN MTL_TRANSACTION_ACCOUNTS_N1 (cr=18 pr=2 pw=0 time=13607 us cost=3 size=0 card=3)(object id 12484127)
0 0 0 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=0 pr=0 pw=0 time=0 us cost=0 size=4 card=1)(object id 9847)
0 0 0 INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=0 pr=0 pw=0 time=0 us cost=2 size=36 card=1)(object id 705891)
1 1 1 NESTED LOOPS (cr=34 pr=3 pw=0 time=31269 us cost=21 size=288 card=1)
1 1 1 NESTED LOOPS (cr=30 pr=3 pw=0 time=31161 us cost=19 size=275 card=1)
1 1 1 NESTED LOOPS (cr=26 pr=3 pw=0 time=31105 us cost=17 size=265 card=1)
1 1 1 NESTED LOOPS (cr=25 pr=3 pw=0 time=31082 us cost=17 size=261 card=1)
1 1 1 NESTED LOOPS OUTER (cr=23 pr=3 pw=0 time=31027 us cost=16 size=254 card=1)
1 1 1 NESTED LOOPS (cr=21 pr=3 pw=0 time=30980 us cost=15 size=247 card=1)
1 1 1 NESTED LOOPS (cr=20 pr=3 pw=0 time=30957 us cost=15 size=243 card=1)
1 1 1 NESTED LOOPS OUTER (cr=19 pr=3 pw=0 time=30926 us cost=15 size=240 card=1)
1 1 1 NESTED LOOPS (cr=16 pr=3 pw=0 time=30389 us cost=13 size=204 card=1)
1 1 1 NESTED LOOPS (cr=11 pr=0 pw=0 time=665 us cost=9 size=131 card=1)
1 1 1 NESTED LOOPS OUTER (cr=8 pr=0 pw=0 time=306 us cost=7 size=95 card=1)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_TRANSACTION_ACCOUNTS (cr=5 pr=0 pw=0 time=37 us cost=5 size=59 card=1)
2 2 2 INDEX RANGE SCAN MTL_TRANSACTION_ACCOUNTS_N1 (cr=4 pr=0 pw=0 time=17 us cost=4 size=0 card=3)(object id 12484127)
1 1 1 INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=0 pw=0 time=216 us cost=2 size=36 card=1)(object id 705891)
1 1 1 INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=0 pw=0 time=352 us cost=2 size=36 card=1)(object id 705891)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_MATERIAL_TRANSACTIONS (cr=5 pr=3 pw=0 time=29716 us cost=4 size=73 card=1)
1 1 1 INDEX RANGE SCAN MTL_MATERIAL_TRANSACTIONS_N23 (cr=4 pr=3 pw=0 time=29588 us cost=3 size=0 card=1)(object id 12484133)
0 0 0 INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=0 pw=0 time=520 us cost=2 size=36 card=1)(object id 705891)
1 1 1 INDEX UNIQUE SCAN MTL_TXN_SOURCE_TYPES_U1 (cr=1 pr=0 pw=0 time=22 us cost=0 size=3 card=1)(object id 9987)
1 1 1 INDEX UNIQUE SCAN MTL_TRANSACTION_TYPES_U1 (cr=1 pr=0 pw=0 time=16 us cost=0 size=4 card=1)(object id 9983)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=34 us cost=1 size=7 card=1)
1 1 1 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=19 us cost=0 size=0 card=1)(object id 9847)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=44 us cost=1 size=7 card=1)
1 1 1 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=14 us cost=0 size=0 card=1)(object id 9847)
1 1 1 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=13 us cost=0 size=4 card=1)(object id 9847)
1 1 1 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=4 pr=0 pw=0 time=49 us cost=2 size=10 card=1)(object id 12484155)
1 1 1 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_TL_U1 (cr=4 pr=0 pw=0 time=96 us cost=2 size=13 card=1)(object id 12484137)
1 1 1 TABLE ACCESS BY INDEX ROWID HR_ALL_ORGANIZATION_UNITS (cr=3 pr=0 pw=0 time=1246 us cost=1 size=7 card=1)
1 1 1 INDEX UNIQUE SCAN HR_ORGANIZATION_UNITS_PK (cr=2 pr=0 pw=0 time=24 us cost=0 size=0 card=1)(object id 250158)
1 1 1 INDEX UNIQUE SCAN HR_ALL_ORGANIZATION_UNTS_TL_PK (cr=2 pr=0 pw=0 time=275 us cost=0 size=7 card=1)(object id 689101)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=38 us cost=1 size=8 card=1)
1 1 1 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=15 us cost=0 size=0 card=1)(object id 9847)
1 1 1 TABLE ACCESS BY INDEX ROWID GL_CODE_COMBINATIONS (cr=4 pr=2 pw=0 time=27531 us cost=2 size=57 card=1)
1 1 1 INDEX UNIQUE SCAN GL_CODE_COMBINATIONS_U1 (cr=3 pr=1 pw=0 time=19925 us cost=1 size=0 card=1)(object id 51426)
1 1 1 TABLE ACCESS BY INDEX ROWID MTL_ITEM_LOCATIONS (cr=4 pr=1 pw=0 time=7758 us cost=3 size=24 card=1)
1 1 1 INDEX RANGE SCAN MTL_ITEM_LOCATIONS_U1 (cr=3 pr=0 pw=0 time=51 us cost=2 size=0 card=1)(object id 9761)
1 1 1 TABLE ACCESS BY INDEX ROWID HR_ORGANIZATION_INFORMATION (cr=3 pr=0 pw=0 time=85 us cost=2 size=28 card=1)
1 1 1 INDEX RANGE SCAN HR_ORGANIZATION_INFORMATIO_FK2 (cr=2 pr=0 pw=0 time=29 us cost=1 size=0 card=2)(object id 5379798)
1 1 1 TABLE ACCESS BY INDEX ROWID HR_ORGANIZATION_INFORMATION (cr=3 pr=0 pw=0 time=25 us cost=1 size=25 card=1)
1 1 1 INDEX RANGE SCAN HR_ORGANIZATION_INFORMATIO_FK2 (cr=2 pr=0 pw=0 time=11 us cost=1 size=0 card=1)(object id 5379798)
1 1 1 INDEX FULL SCAN GL_SETS_OF_BOOKS_U2 (cr=1 pr=0 pw=0 time=69 us cost=1 size=4 card=1)(object id 1380842)
1 1 1 BUFFER SORT (cr=2 pr=0 pw=0 time=110 us cost=55 size=0 card=1)
1 1 1 TABLE ACCESS FULL FND_PRODUCT_GROUPS (cr=2 pr=0 pw=0 time=59 us cost=3 size=0 card=1)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
library cache lock 2 0.00 0.00
library cache pin 2 0.00 0.00
Disk file operations I/O 249 0.00 0.00
db file sequential read 58819 2.61 714.28
gc cr grant 2-way 5198 0.16 4.52
gc current grant busy 1 0.00 0.00
KJC: Wait for msg sends to complete 517 0.00 0.05
library cache: mutex X 433 0.01 0.04
gc cr grant congested 28 0.08 0.18
latch: ges resource hash list 5 0.00 0.00
gc current block 2-way 513 0.11 0.61
gc current block congested 2 0.00 0.00
latch: gc element 16 0.00 0.01
latch: cache buffers chains 4 0.00 0.00
latch: object queue header operation 3 0.00 0.00
********************************************************************************Explain Plan for the query
SELECT STATEMENT, GOAL = ALL_ROWS Cost=56 Cardinality=1 Bytes=219
MERGE JOIN CARTESIAN Cost=56 Cardinality=1 Bytes=219
NESTED LOOPS Cost=53 Cardinality=1 Bytes=219
NESTED LOOPS Cost=52 Cardinality=1 Bytes=215
NESTED LOOPS Cost=51 Cardinality=1 Bytes=190
NESTED LOOPS Cost=49 Cardinality=1 Bytes=162
NESTED LOOPS Cost=46 Cardinality=1 Bytes=138
NESTED LOOPS Cost=44 Cardinality=1 Bytes=81
NESTED LOOPS Cost=43 Cardinality=1 Bytes=73
NESTED LOOPS Cost=43 Cardinality=2 Bytes=132
VIEW Object owner=APPS Object name=CST_INV_DISTRIBUTION_V Cost=41 Cardinality=2 Bytes=118
UNION-ALL
NESTED LOOPS OUTER Cost=20 Cardinality=1 Bytes=291
NESTED LOOPS Cost=18 Cardinality=1 Bytes=255
NESTED LOOPS Cost=18 Cardinality=1 Bytes=251
MERGE JOIN CARTESIAN Cost=14 Cardinality=1 Bytes=192
NESTED LOOPS OUTER Cost=12 Cardinality=1 Bytes=156
NESTED LOOPS Cost=10 Cardinality=1 Bytes=120
NESTED LOOPS OUTER Cost=9 Cardinality=1 Bytes=113
NESTED LOOPS Cost=8 Cardinality=1 Bytes=106
NESTED LOOPS Cost=6 Cardinality=1 Bytes=93
NESTED LOOPS Cost=4 Cardinality=1 Bytes=83
NESTED LOOPS Cost=4 Cardinality=1 Bytes=80
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_MATERIAL_TRANSACTIONS Cost=4 Cardinality=1 Bytes=76
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_MATERIAL_TRANSACTIONS_U1 Cost=3 Cardinality=1
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_TRANSACTION_TYPES_U1 Cost=0 Cardinality=191 Bytes=764
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_TXN_SOURCE_TYPES_U1 Cost=0 Cardinality=18 Bytes=54
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_SYSTEM_ITEMS_B_U1 Cost=2 Cardinality=73632445 Bytes=736324450
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_SYSTEM_ITEMS_TL_U1 Cost=2 Cardinality=73652390 Bytes=957481070
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_PARAMETERS Cost=1 Cardinality=470 Bytes=3290
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_PARAMETERS_U1 Cost=0 Cardinality=1
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_PARAMETERS Cost=1 Cardinality=470 Bytes=3290
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_PARAMETERS_U1 Cost=0 Cardinality=1
INDEX RANGE SCAN Object owner=APPLSYS Object name=FND_LOOKUP_VALUES_U1 Cost=2 Cardinality=1 Bytes=36
BUFFER SORT Cost=12 Cardinality=1 Bytes=36
INDEX RANGE SCAN Object owner=APPLSYS Object name=FND_LOOKUP_VALUES_U1 Cost=2 Cardinality=1 Bytes=36
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_TRANSACTION_ACCOUNTS Cost=4 Cardinality=1 Bytes=59
INDEX RANGE SCAN Object owner=INV Object name=MTL_TRANSACTION_ACCOUNTS_N1 Cost=3 Cardinality=3
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_PARAMETERS_U1 Cost=0 Cardinality=1 Bytes=4
INDEX RANGE SCAN Object owner=APPLSYS Object name=FND_LOOKUP_VALUES_U1 Cost=2 Cardinality=1 Bytes=36
NESTED LOOPS Cost=21 Cardinality=1 Bytes=288
NESTED LOOPS Cost=19 Cardinality=1 Bytes=275
NESTED LOOPS Cost=17 Cardinality=1 Bytes=265
NESTED LOOPS Cost=17 Cardinality=1 Bytes=261
NESTED LOOPS OUTER Cost=16 Cardinality=1 Bytes=254
NESTED LOOPS Cost=15 Cardinality=1 Bytes=247
NESTED LOOPS Cost=15 Cardinality=1 Bytes=243
NESTED LOOPS OUTER Cost=15 Cardinality=1 Bytes=240
NESTED LOOPS Cost=13 Cardinality=1 Bytes=204
NESTED LOOPS Cost=9 Cardinality=1 Bytes=131
NESTED LOOPS OUTER Cost=7 Cardinality=1 Bytes=95
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_TRANSACTION_ACCOUNTS Cost=5 Cardinality=1 Bytes=59
INDEX RANGE SCAN Object owner=INV Object name=MTL_TRANSACTION_ACCOUNTS_N1 Cost=4 Cardinality=3
INDEX RANGE SCAN Object owner=APPLSYS Object name=FND_LOOKUP_VALUES_U1 Cost=2 Cardinality=1 Bytes=36
INDEX RANGE SCAN Object owner=APPLSYS Object name=FND_LOOKUP_VALUES_U1 Cost=2 Cardinality=1 Bytes=36
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_MATERIAL_TRANSACTIONS Cost=4 Cardinality=1 Bytes=73
INDEX RANGE SCAN Object owner=INV Object name=MTL_MATERIAL_TRANSACTIONS_N23 Cost=3 Cardinality=1
INDEX RANGE SCAN Object owner=APPLSYS Object name=FND_LOOKUP_VALUES_U1 Cost=2 Cardinality=1 Bytes=36
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_TXN_SOURCE_TYPES_U1 Cost=0 Cardinality=1 Bytes=3
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_TRANSACTION_TYPES_U1 Cost=0 Cardinality=1 Bytes=4
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_PARAMETERS Cost=1 Cardinality=1 Bytes=7
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_PARAMETERS_U1 Cost=0 Cardinality=1
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_PARAMETERS Cost=1 Cardinality=1 Bytes=7
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_PARAMETERS_U1 Cost=0 Cardinality=1
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_PARAMETERS_U1 Cost=0 Cardinality=1 Bytes=4
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_SYSTEM_ITEMS_B_U1 Cost=2 Cardinality=1 Bytes=10
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_SYSTEM_ITEMS_TL_U1 Cost=2 Cardinality=1 Bytes=13
TABLE ACCESS BY INDEX ROWID Object owner=HR Object name=HR_ALL_ORGANIZATION_UNITS Cost=1 Cardinality=1 Bytes=7
INDEX UNIQUE SCAN Object owner=HR Object name=HR_ORGANIZATION_UNITS_PK Cost=0 Cardinality=1
INDEX UNIQUE SCAN Object owner=HR Object name=HR_ALL_ORGANIZATION_UNTS_TL_PK Cost=0 Cardinality=1 Bytes=7
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_PARAMETERS Cost=1 Cardinality=1 Bytes=8
INDEX UNIQUE SCAN Object owner=INV Object name=MTL_PARAMETERS_U1 Cost=0 Cardinality=1
TABLE ACCESS BY INDEX ROWID Object owner=GL Object name=GL_CODE_COMBINATIONS Cost=2 Cardinality=1 Bytes=57
INDEX UNIQUE SCAN Object owner=GL Object name=GL_CODE_COMBINATIONS_U1 Cost=1 Cardinality=1
TABLE ACCESS BY INDEX ROWID Object owner=INV Object name=MTL_ITEM_LOCATIONS Cost=3 Cardinality=1 Bytes=24
INDEX RANGE SCAN Object owner=INV Object name=MTL_ITEM_LOCATIONS_U1 Cost=2 Cardinality=1
TABLE ACCESS BY INDEX ROWID Object owner=HR Object name=HR_ORGANIZATION_INFORMATION Cost=2 Cardinality=1 Bytes=28
INDEX RANGE SCAN Object owner=HR Object name=HR_ORGANIZATION_INFORMATIO_FK2 Cost=1 Cardinality=2
TABLE ACCESS BY INDEX ROWID Object owner=HR Object name=HR_ORGANIZATION_INFORMATION Cost=1 Cardinality=1 Bytes=25
INDEX RANGE SCAN Object owner=HR Object name=HR_ORGANIZATION_INFORMATIO_FK2 Cost=1 Cardinality=1
INDEX FULL SCAN Object owner=GL Object name=GL_SETS_OF_BOOKS_U2 Cost=1 Cardinality=1 Bytes=4
BUFFER SORT Cost=55 Cardinality=1
TABLE ACCESS FULL Object owner=APPLSYS Object name=FND_PRODUCT_GROUPS Cost=3 Cardinality=1 -
Help needed to tune the Query:Statistics added
Can someone DBA please help me to tune this query:
SELECT DISTINCT K.ATTRIBUTE_VALUE AGENCY_ID,B.PROFILE_NM ,NVL(G.OFFICE_DESC,'--') OFFICE_DESC,f.OFFICE_ID,B.PROFILE_ID,'%' ROLE,'%' LAYOUT,
CASE
WHEN 'flagB' = '%' THEN
NVL(J.ISS_GRP_DESC,'BILLING')
WHEN 'flagO' = '%' THEN
NVL(J.ISS_GRP_DESC,'ORDERING')
WHEN 'flag' = '%' THEN
NVL(J.ISS_GRP_DESC,'BILLING/ORDERING')
ELSE
NVL(J.ISS_GRP_DESC,' ')
END ISS_GRP_DESC,
DECODE(NVL(H.USERID,' ') ,' ','--','<a sbcuid_in=' || H.USERID || ' target=NEW >'||H.FIRSTNAME || ' ' || H.LASTNAME || '( ' || H.USERID || ' )</a>' ) USER_NAME
FROM
PROFILE_PORTAL B ,
TBL_BDA_AGENCY_RESP_REP C ,
TBL_BDA_AGENCY_OFFICE F,
TBL_BDA_OFFICE G,
USERS_PORTAL H,
TBL_BDA_USR_ISS_GRP I ,
TBL_BDA_ISS_GROUP J,
ATTRIBUTE_VALUES_PORTAL K,
PROFILE_TYPE_PORTAL L
WHERE
B.PROFILE_ID = F.AGENCY_ID (+)
AND B.PROFILE_ID = C.AGENCY_ID (+)
AND G.OFFICE_ID (+)= F.OFFICE_ID
AND H.USERID (+)= C.RESP_USR_ID
AND C.ISS_GRP_ID = I.ISS_GRP_ID (+)
AND I.ISS_GRP_ID = J.ISS_GRP_ID(+)
AND 'PROFILE.'||B.PROFILE_ID = K.ENTITY_ID(+)
AND K.ATTRIBUTE_VALUE IS NOT NULL
AND L.PROFILE_TYPE_ID = B.PROFILE_TYPE_ID
AND L.APPLICATION_CD='BDA'
AND NOT EXISTS (SELECT agency_id
FROM TBL_BDA_AGENCY_RESP_REP t
WHERE t.ISS_GRP_ID IN ('%')
AND t.AGENCY_ID = C.AGENCY_ID)
AND K.ATTRIBUTE_VALUE LIKE '%'
AND UPPER(B.PROFILE_NM) LIKE UPPER('%')
AND (to_char(NVL(B.PROFILE_ID,0)) LIKE '%' OR NVL(B.PROFILE_ID,0) IN ('a'))
AND NVL(G.OFFICE_ID,0) IN ('%')
AND (to_char(NVL(C.RESP_USR_ID,'0')) LIKE '%' OR NVL(C.RESP_USR_ID,'0') IN ('k'))
ORDER BY PROFILE_NM
The number of rows in these tables are as follows:
PROFILE_PORTAL -- 2392
TBL_BDA_AGENCY_RESP_REP 3508
TBL_BDA_AGENCY_OFFICE 2151
TBL_BDA_OFFICE 3
USERS_PORTAL 270500
TBL_BDA_USR_ISS_GRP 234
TBL_BDA_ISS_GROUP 2
ATTRIBUTE_VALUES_PORTAL 2790
PROFILE_TYPE_PORTAL 3
The Explain pal nhas given this o/p to me:
SQL> select * from table(dbms_xplan.display) dual;
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost |
| 0 | SELECT STATEMENT | | 807 | 102K| | 2533 |
| 1 | SORT UNIQUE | | 807 | 102K| 232K| 82 |
|* 2 | FILTER | | | | | |
|* 3 | HASH JOIN OUTER | | 807 | 102K| | 52 |
|* 4 | HASH JOIN OUTER | | 807 | 95226 | | 40 |
|* 5 | TABLE ACCESS BY INDEX ROWID | ATTRIBUTE_VALUES | 1 | 23 | | 2 |
| 6 | NESTED LOOPS | | 7 | 805 | | 37 |
| 7 | NESTED LOOPS OUTER | | 6 | 552 | | 25 |
|* 8 | FILTER | | | | | |
| 9 | NESTED LOOPS OUTER | | | | | |
|* 10 | FILTER | | | | | |
| 11 | NESTED LOOPS OUTER | | | | | |
| 12 | NESTED LOOPS OUTER | | 3 | 141 | | 10 |
|* 13 | HASH JOIN | | 3 | 120 | | 7 |
|* 14 | TABLE ACCESS FULL | PROFILE | 6 | 198 | | 4 |
|* 15 | TABLE ACCESS FULL | PROFILE_TYPE | 1 | 7 | | 2 |
|* 16 | INDEX RANGE SCAN | SYS_C0019777 | 1 | 7 | | 1 |
| 17 | TABLE ACCESS BY INDEX ROWID| TBL_BDA_OFFICE | 1 | 10 | | 1 |
|* 18 | INDEX UNIQUE SCAN | SYS_C0019800 | 1 | | | |
| 19 | TABLE ACCESS BY INDEX ROWID | TBL_BDA_AGENCY_RESP_REP | 2 | 26 | | 2 |
|* 20 | INDEX RANGE SCAN | IDX_AGECYRESP_AGNCYID | 2 | | | 1 |
| 21 | TABLE ACCESS BY INDEX ROWID | USER_ | 1 | 22 | | 1 |
|* 22 | INDEX UNIQUE SCAN | USER_PK | 1 | | | |
|* 23 | INDEX RANGE SCAN | IDX_ATTVAL_ENTATTID | 1 | | | 1 |
| 24 | TABLE ACCESS FULL | TBL_BDA_USR_ISS_GRP | 234 | 702 | | 2 |
| 25 | TABLE ACCESS FULL | TBL_BDA_ISS_GROUP | 2 | 24 | | 2 |
|* 26 | TABLE ACCESS BY INDEX ROWID | TBL_BDA_AGENCY_RESP_REP | 1 | 7 | | 3 |
|* 27 | INDEX RANGE SCAN | IDX_AGECYRESP_AGNCYID | 2 | | | 1 |
Predicate Information (identified by operation id):
2 - filter( NOT EXISTS (SELECT /*+ */ 0 FROM "TBL_BDA_AGENCY_RESP_REP" "T" WHERE "T"."AGENCY_ID"=:B1
AND "T"."ISS_GRP_ID"=TO_NUMBER('%')))
3 - access("I"."ISS_GRP_ID"="J"."ISS_GRP_ID"(+))
4 - access("SYS_ALIAS_1"."ISS_GRP_ID"="I"."ISS_GRP_ID"(+))
5 - filter("K"."ATTRIBUTE_VALUE" IS NOT NULL AND "K"."ATTRIBUTE_VALUE" LIKE '%')
8 - filter(NVL("SYS_ALIAS_1"."RESP_USR_ID",'0') LIKE '%' OR NVL("SYS_ALIAS_1"."RESP_USR_ID",'0')='k')
10 - filter(NVL("G"."OFFICE_ID",0)=TO_NUMBER('%'))
13 - access("L"."PROFILE_TYPE_ID"="B"."PROFILE_TYPE_ID")
14 - filter(UPPER("B"."PROFILE_NM") LIKE '%' AND (TO_CHAR(NVL("B"."PROFILE_ID",0)) LIKE '%' OR
NVL("B"."PROFILE_ID",0)=TO_NUMBER('a')))
15 - filter("L"."APPLICATION_CD"='BDA')
16 - access("B"."PROFILE_ID"="F"."AGENCY_ID"(+))
18 - access("G"."OFFICE_ID"(+)="F"."OFFICE_ID")
20 - access("B"."PROFILE_ID"="SYS_ALIAS_1"."AGENCY_ID"(+))
22 - access("H"."USERID"(+)="SYS_ALIAS_1"."RESP_USR_ID")
23 - access("K"."ENTITY_ID"='PROFILE.'||TO_CHAR("B"."PROFILE_ID"))
26 - filter("T"."ISS_GRP_ID"=TO_NUMBER('%'))
27 - access("T"."AGENCY_ID"=:B1)
Note: cpu costing is off
57 rows selected.
Elapsed: 00:00:01.08
Please help me.
Aashish S.Hello Eric,
Here is the code:
SELECT DISTINCT
K.ATTRIBUTE_VALUE AGENCY_ID,
B.PROFILE_NM ,
NVL(G.OFFICE_DESC,'--') OFFICE_DESC,
f.OFFICE_ID,
B.PROFILE_ID,
'%' ROLE,
'%' LAYOUT,
case
WHEN 'flagB' = '%' THEN
NVL(J.ISS_GRP_DESC,'BILLING')
WHEN 'flagO' = '%' THEN
NVL(J.ISS_GRP_DESC,'ORDERING')
WHEN 'flag' = '%' THEN
NVL(J.ISS_GRP_DESC,'BILLING/ORDERING')
else
NVL(J.ISS_GRP_DESC,' ')
END ISS_GRP_DESC,
DECODE(NVL(H.USERID,' ') ,' ','--','<a sbcuid_in=' || H.USERID || ' target=NEW >'||H.FIRSTNAME || ' ' || H.LASTNAME ||
'( ' || H.USERID || ' )</a>' ) USER_NAME
from
PROFILE_PORTAL B ,
TBL_BDA_AGENCY_RESP_REP C ,
TBL_BDA_AGENCY_OFFICE F,
TBL_BDA_OFFICE G,
USERS_PORTAL H,
TBL_BDA_USR_ISS_GRP I ,
TBL_BDA_ISS_GROUP J,
ATTRIBUTE_VALUES_PORTAL K,
PROFILE_TYPE_PORTAL L
WHERE
B.PROFILE_ID = F.AGENCY_ID (+)
AND B.PROFILE_ID = C.AGENCY_ID (+)
AND G.OFFICE_ID (+)= F.OFFICE_ID
AND H.USERID (+)= C.RESP_USR_ID
AND C.ISS_GRP_ID = I.ISS_GRP_ID (+)
AND I.ISS_GRP_ID = J.ISS_GRP_ID(+)
AND 'PROFILE.'||B.PROFILE_ID = K.ENTITY_ID(+)
AND K.ATTRIBUTE_VALUE IS NOT NULL
AND L.PROFILE_TYPE_ID = B.PROFILE_TYPE_ID
AND L.APPLICATION_CD='BDA'
AND NOT EXISTS
(SELECT agency_id
FROM TBL_BDA_AGENCY_RESP_REP t
WHERE t.ISS_GRP_ID IN (1)
AND t.AGENCY_ID = C.AGENCY_ID)
AND K.ATTRIBUTE_VALUE LIKE '%'
AND UPPER(B.PROFILE_NM) LIKE UPPER('%')
AND (to_char(NVL(B.PROFILE_ID,0))
LIKE '%'
OR NVL(B.PROFILE_ID,0) IN (1))
AND NVL(G.OFFICE_ID,0) IN (1)
AND (to_char(NVL(C.RESP_USR_ID,'0'))
LIKE '%'
OR NVL(C.RESP_USR_ID,'0') IN ('%'))
ORDER BY PROFILE_NM
This is the Query and the query takes some mins. to run in prod environment.
From the Query plan ,I am not able to get any idea for optimization.
Now,Can you tell me which steps I need to follow to run it faster and which all modifications should be made?
Thanks.
Aashish S. -
Is there any way to tune this query? EXPLAIN PLAN included
DB version:10gR2
The below query was taking more than 3 seconds. The statistics are up to date for these tables. Is there any other way i could tune this query?
SELECT COUNT(1)
FROM
INVN_SCOPE_DTL, ship_dtl WHERE ship_dtl.WHSE = INVN_SCOPE_DTL.WHSE (+)
AND 'QC' = INVN_SCOPE_DTL.FROM_WORK_GRP (+)
AND 'MQN' = INVN_SCOPE_DTL.FROM_WORK_AREA (+)
AND ship_dtl.START_CURR_WORK_GRP = INVN_SCOPE_DTL.TO_WORK_GRP (+)
AND ship_dtl.START_CURR_WORK_AREA = INVN_SCOPE_DTL.TO_WORK_AREA (+)
AND ship_dtl.WHSE = '930' AND ship_dtl.OWNER_USER_ID = 'CTZDM'
OR ship_dtl.OWNER_USER_ID = '*'
AND ship_dtl.STAT_CODE >= '10'
AND ship_dtl.STAT_CODE <= '20'
ORDER BY ship_dtl.OWNER_USER_ID DESC,
ship_dtl.CURR_TASK_PRTY ASC, INVN_SCOPE_DTL.DISTANCE ASC, ship_dtl.RLS_DATE_TIME ASC, ship_dtl.TASK_ID ASC;
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
| 0 | SELECT STATEMENT | | 1 | 86 | 86 (2)|
| 1 | SORT AGGREGATE | | 1 | 86 | |
| 2 | NESTED LOOPS OUTER | | 898 | 77228 | 86 (2)|
| 3 | INLIST ITERATOR | | | | |
|* 4 | TABLE ACCESS BY INDEX ROWID| ship_dtl | 898 | 31430 | 85 (2)|
|* 5 | INDEX RANGE SCAN | ship_dtl_IND_4 | 2876 | | 1 (0)|
| 6 | TABLE ACCESS BY INDEX ROWID | INVN_SCOPE_DTL | 1 | 51 | 2 (50)|
PLAN_TABLE_OUTPUT
|* 7 | INDEX UNIQUE SCAN | PK_INVN_SCOPE_DTL | 1 | | |
Predicate Information (identified by operation id):
4 - filter("ship_dtl"."WHSE"='930' AND "ship_dtl"."STAT_CODE">=10 AND
"ship_dtl"."STAT_CODE"<=20)
5 - access("ship_dtl"."OWNER_USER_ID"='*' OR "ship_dtl"."OWNER_USER_ID"='CTZDM')
7 - access("INVN_SCOPE_DTL"."WHSE"(+)='930' AND
"INVN_SCOPE_DTL"."FROM_WORK_GRP"(+)='QC' AND "INVN_SCOPE_DTL"."FROM_WORK_AREA"(+)='MQN'
PLAN_TABLE_OUTPUT
AND "ship_dtl"."START_CURR_WORK_GRP"="INVN_SCOPE_DTL"."TO_WORK_GRP"(+) AND
"ship_dtl"."START_CURR_WORK_AREA"="INVN_SCOPE_DTL"."TO_WORK_AREA"(+))
filter("ship_dtl"."WHSE"="INVN_SCOPE_DTL"."WHSE"(+))
25 rows selected.William Robertson wrote:
I notice an OR predicate in the middle of some AND predicates without explicit bracketing. Are you sure it does what you think it does?I underline this point.
A conjuction (AND expression) has a higher priority and will be executed (logically) before the disjunction (OR expression)! So your select looks like this
SELECT COUNT(1)
FROM INVN_SCOPE_DTL, ship_dtl
WHERE
( ship_dtl.WHSE = INVN_SCOPE_DTL.WHSE (+)
AND 'QC' = INVN_SCOPE_DTL.FROM_WORK_GRP (+)
AND 'MQN' = INVN_SCOPE_DTL.FROM_WORK_AREA (+)
AND ship_dtl.START_CURR_WORK_GRP = INVN_SCOPE_DTL.TO_WORK_GRP (+)
AND ship_dtl.START_CURR_WORK_AREA = INVN_SCOPE_DTL.TO_WORK_AREA (+)
AND ship_dtl.WHSE = '930'
AND ship_dtl.OWNER_USER_ID = 'CTZDM'
OR ( ship_dtl.OWNER_USER_ID = '*'
AND ship_dtl.STAT_CODE >= '10'
AND ship_dtl.STAT_CODE <= '20'
;This might be want you want, but I doubt it very much. Please add parenthesis', to get it working the way it should be.
Edited by: Sven W. on Oct 16, 2008 3:25 PM -
Hello All,
I have searched OTN and AskTom and saw many articles on hierarchial query but I just cannot seem to figure out how to apply it to my situation. Based on what I have read I do not believe CUBE or ROLLUP is the answer for this (maybe wrong..).
This data is only a small part of a much larger query used for auditing purposes, so i would need to incorporate the solution for this into the larger query.
Part of my problem is how to actual present this data in a format that would make sense to the end user, when included in a tabular (Excel) report.
I am trying to devise a way to verify that monthly payment is received for each product. In this case, some of the products are "created" under another product and then billed under a 3rd product.
To explain the table
Prod_1 - list all products
Prod_2 - lists only those products that are the parent of an item in the Prod_1 column.
Prod_3 - shows there is a relationship between an item in Prod_1 that is not in Prod_2.
There may be items in Prod_1 that have no relationship to Prod_2 or Prod_3 are those are just billed or *not getting billed BAD*
There are other cases where there is a item in Prod_2 that is the parent of one or more items in Prod_1 but not related to Prod_3 and those are billed.
There are other cases where there is a item in Prod_2 that is the parent of one or more items in Prod_1 but not related to Prod_3 and *not getting billed BAD*
For example:
+1-abcd-efgh, 3-qrst-uvwx and 5-ghij-klmn+ under Prod_1 is created under Prod_2 +1234-2f-maker-taker+ but billed under Prod_3 +87-test-789101+ at $139.11 MONTH_CHARGE.
CREATE TABLE PRODT ( design_id VARCHAR2(50), Prod_1 VARCHAR2(50), Prod_2 VARCHAR2(50), Prod_3 VARCHAR2(50), Month_Charge NUMBER );
INSERT INTO PRODT VALUES ( '8568','1-abcd-efgh', '1234-2f-maker-taker','', 0 );
INSERT INTO PRODT VALUES ( '8569','2-ijkl-mnop', '5678-3f-maker-taker','', 0 );
INSERT INTO PRODT VALUES ( '8570','3-qrst-uvwx', '1234-2f-maker-taker','', 0 );
INSERT INTO PRODT VALUES ( '8571','4-yzab-cdef', '5678-3f-maker-taker','', 0 );
INSERT INTO PRODT VALUES ( '8572','5-ghij-klmn', '1234-2f-maker-taker','', 0 );
INSERT INTO PRODT VALUES ( '9421','1234-2f-maker-taker','','87-test-789101', 0 );
INSERT INTO PRODT VALUES ( '9588','5678-3f-maker-taker','','88-test-123456', 0 );
INSERT INTO PRODT VALUES ( '2531','87-test-789101', '', '1234-2f-maker-taker',139.11 );
INSERT INTO PRODT VALUES ( '2532','88-test-123456', '','5678-3f-maker-taker', 159.45 );
INSERT INTO PRODT VALUES ( '4531','76-test-101568', '', '',145.00 );
INSERT INTO PRODT VALUES ( '3528','6-abcd-efgh', '2234-1f-maker-taker','', 0 );
INSERT INTO PRODT VALUES ( '3529','7-ijkl-mnop', '2234-1f-maker-taker','', 0 );
INSERT INTO PRODT VALUES ( '6261','2234-1f-maker-taker','','', 0 );
COMMIT; Desired Result:
Honestly - I am not sure of the best way to present it - definetly open for suggestions!
The table shows there is a relationship by Product Number, but the table does not make it clear that as in the example above that
all of the underlying products are being billed under +87-test-789101+ at $139.11 per month.
I must still show all of the Prod columns - so for my understanding Cube or Rollup is not a good fit(?).
That is what I am trying to accomplish - in other words I am getting paid for everything or not?
In my mind I see it something like this perhaps:
DESIGN_ID PROD_1 PROD_2 PROD_3 MONTH_CHARGE BILL_INDICATOR
8569 2-ijkl-mnop 5678-3f-maker-taker NULL 0 ? (Not sure how to indicate
8571 4-yzab-cdef 5678-3f-maker-taker NULL 0 what should be displayed
9588 5678-3f-maker-taker NULL 88-test-123456 0 in this new column to make
2532 88-test-123456 NULL 5678-3f-maker-taker 159.45 the Audit process simple *Help Needed*)Thanks for looking!
G
Edited by: GMoney on Aug 22, 2012 12:54 PM
Edited by: GMoney on Aug 22, 2012 12:57 PMFrank,
I was hoping you would cross paths with this post.
I am building on a TOP N query you helped me with in another post.
As I mentioned in my an initial post, I have products that may be in a hierarchical order (or stand alone) could be billed as primary or with secondary or tertiary products that are billed under the primary. Meaning the primary would have a dollar figure associated, and may or may not have secondary or tertiary products related to it.
To explain the table
Prod_1 - list all products
Prod_2 - lists only those products that are the parent of an item in the Prod_1 column.
Prod_3 - shows there is a relationship between an item in Prod_1 that is not in Prod_2.
There may be items in Prod_1 that have no relationship to Prod_2 or Prod_3 are those are just billed or not getting billed BAD
There are other cases where there is a item in Prod_2 that is the parent of one or more items in Prod_1 but not related to Prod_3 and those are billed.
There are other cases where there is a item in Prod_2 that is the parent of one or more items in Prod_1 but not related to Prod_3 and not getting billed BAD
My business requirement is to present all of the results from the initial query as well as adding in the dollar figures from an addition query against another financial table. I need to be able to make it perfectly clear to an end user auditor that each and every product is being billed, and clearly identify the secondary or tertiary items if there are any that fall under that primary product.
My real hung up here is the presentation of the data. I can easily see the correlation between them but it is not likely an end user would.
DESIGN_ID PROD_1 PROD_2 PROD_3 MONTH_CHARGE BILL_INDICATOR
8569 2-ijkl-mnop 5678-3f-maker-taker NULL 0 ? (Not sure how to indicate
8571 4-yzab-cdef 5678-3f-maker-taker NULL 0 what should be displayed
9588 5678-3f-maker-taker NULL 88-test-123456 0 in this new column to make
2532 88-test-123456 NULL 5678-3f-maker-taker 159.45 ; the Audit process simple *Help Needed*) Thanks for looking,
Greg -
Hi All..
I have a hierarchy query with description as below
SQL> desc manager_entity;
Name Null? Type
MANAGER_ENTITY_ID NOT NULL NUMBER
MANAGER_ENTITY_TYPE_ID NOT NULL NUMBER
MANAGER_ENTITY_PARENT_ID NUMBER
CREATE_USER NOT NULL VARCHAR2(50)
CREATE_DATETIME NOT NULL DATE
LAST_UPDATE_USER NOT NULL VARCHAR2(50)
LAST_UPDATE_DATETIME NOT NULL DATE
MANAGER_ENTITY_LINK_ID NOT NULL NUMBERI got the correct relation between the parent and child using the below query
select me.manager_entity_id
, me.manager_entity_type_id
, me.manager_entity_parent_id
, me.manager_entity_link_id
, level
from manager_entity me
start with me.manager_entity_id=:p_id
connect by prior me.manager_entity_id=me.manager_entity_parent_idWhen I try to join this table with other 3 tables I’m unable to retrieve data. Description of the other 3 tables
SQL> desc manager_product;
Name Null? Type
MANAGER_PRODUCT_ID NOT NULL NUMBER
MANAGER_PRODUCT_NAME NOT NULL VARCHAR2(50)
MANAGER_ROOF_ID NOT NULL NUMBER
ACT_STRATEGY VARCHAR2(50)
ACT_SUB_STRATEGY VARCHAR2(50)
ACT_DATE_ENTERED DATE
ACT_INCEPTION_DATE DATE
ACT_PEER_GROUP VARCHAR2(50)
BACK_OFFICE_RISK_ID NUMBER
AREA_ID NUMBER
ACT_CREATE_DATE DATE
PROCESS_STOP_DATE DATE
TARGET_COMPLETION_DATE DATE
REVISIT_DATE DATE
CREATE_USER VARCHAR2(50)
CREATE_DATETIME DATE
LAST_UPDATE_USER VARCHAR2(50)
LAST_UPDATE_DATETIME DATE
SQL> desc manager_roof;
Name Null? Type
MANAGER_ROOF_ID NOT NULL NUMBER
MANAGER_ROOF_NAME NOT NULL VARCHAR2(50)
ROOF_COMPANY_ID NOT NULL NUMBER
CREATE_USER VARCHAR2(50)
CREATE_DATETIME DATE
LAST_UPDATE_USER VARCHAR2(50)
LAST_UPDATE_DATETIME DATE
SQL> desc investment_vehicle;
Name Null? Type
INVESTMENT_VEHICLE_ID NOT NULL NUMBER
INVESTMENT_VEHICLE_NAME NOT NULL VARCHAR2(255)
INVESTMENT_VEHICLE_ARRT_NAME VARCHAR2(255)
INVESTIER_SYSID NUMBER
INVESTIER_ID VARCHAR2(100)
MANAGER_PRODUCT_ID NUMBER
TRADING_STRUCTURE_TYPE_ID NUMBER
LEGAL_DESIGNATION_ID NUMBER
ADDITIONAL_INVEST_FORM_TYPE_ID NUMBER
INVESTMENT_VEH_CLASS_TYPE_ID NUMBER
ERISA_PLAN_ASSET_CATEGORY_ID NUMBER
SIDE_LETTER_FLAG CHAR(1)
INCEPTION_DATE DATE
ALLOW_ERISA_FLAG CHAR(1)
ALLOW_PLAN_ASSET_FLAG CHAR(1)
ALLOW_US_TAXABLE_INVESTOR_FLAG CHAR(1)
ALLOW_OFFSHORE_INVESTOR_FLAG CHAR(1)
SUB_DOC_DEADLINE NUMBER
WIRE_DEADLINE NUMBER
DOMICILE_COUNTRY_ID NUMBER
CREATE_USER VARCHAR2(50)
CREATE_DATETIME DATE
LAST_UPDATE_USER VARCHAR2(50)
LAST_UPDATE_DATETIME DATE
PERTRAC_DATA_VENDOR_ID VARCHAR2(255)
PERTRAC_DATA_VENDOR_NAME VARCHAR2(255)
FTS_NAME VARCHAR2(255)
MATLAB_MANAGER_NAME VARCHAR2(255)
ACT_CO_FUND_NAME VARCHAR2(255)
ACT_INVESTMENT_VEHICLE_NAME VARCHAR2(255)
SIDE_POCKET_PCT NUMBER
MAX_ILLIQUID_PCT NUMBER
CONTRIBUTION_OPENING_ID NUMBER
MANAGEMENT_FEE_PCT NUMBER
INCENTIVE_FEE_PCT NUMBER
SIDE_POCKET_NOTE VARCHAR2(4000)
FTS_ID NUMBERI was trying to join the other 3 tables with the main query as below..
select me.manager_entity_id
, me.manager_entity_type_id
, me.manager_entity_parent_id
, me.manager_entity_link_id
, level
from manager_entity me
, manager_roof mr
, manager_product mp
, investment_vehicle iv
where me.manager_entity_link_id= mr.manager_roof_id
and mr.manager_roof_id= mp.manager_roof_id
and mp.manager_product_id= iv.manager_product_id
start with me.manager_entity_id=:p_id
connect by prior me.manager_entity_id=me.manager_entity_parent_idHere manager_entity_link_id of manager_entity table represents(or has) the primary key of all the other 3 table..like
Enter value for p_id: 1
old 7: start with me.manager_entity_id=&p_id
new 7: start with me.manager_entity_id=1
MANAGER_ENTITY_ID MANAGER_ENTITY_TYPE_ID MANAGER_ENTITY_PARENT_ID
MANAGER_ENTITY_LINK_ID LEVEL
1 1008
14793 1
263 1009 1
19695 2
803 1010 263
7031783 3
MANAGER_ENTITY_ID MANAGER_ENTITY_TYPE_ID MANAGER_ENTITY_PARENT_ID
MANAGER_ENTITY_LINK_ID LEVEL
804 1010 263
7031782 3
805 1010 263
7031781 3The above is the output for the hierarchy query
Here the MANAGER_ENTITY_LINK_ID has values (14793, 19695, 7031783 , 7031782 , 7031781)
Where 14793 is the manager_roof_id in manager_roof_table
19695 is the manager_product_id in the manager_product table
7031783 , 7031782 , 7031781 are the investment_vehicle_id’s in the investment_vehicle table…
In the output I need to retrieve manager_roof_name, manager_product_name, investment_vehicle_name..
Thanks in advance
HTH
Edited by: user10280715 on Dec 3, 2008 11:55 AMThe reason result show as no rows selected is your first insert. If fails since column list has 3 columns while values list has 4 values. You probably missed "ORA-00913: too many values" error:
SQL> drop table manager_entity
2 /
Table dropped.
SQL> create table manager_entity(manager_entity_id number,manager_entity_type_id number,manager_entity_parent_id number,manager_entity_link_id number)
2 /
Table created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_link_id)
2 values(1,1008,null,14793)
3 /
insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_link_id)
ERROR at line 1:
ORA-00913: too many values
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(263, 1009, 1, 19695)
3 /
1 row created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(803, 1010, 263, 7031783)
3 /
1 row created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(804, 1010, 263, 7031782)
3 /
1 row created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(805, 1010, 263, 7031781)
3 /
1 row created.
SQL> drop table manager_roof
2 /
Table dropped.
SQL> create table manager_roof(manager_roof_id number,manager_roof_name varchar2(20))
2 /
Table created.
SQL> insert into manager_roof(manager_roof_id,manager_roof_name)
2 values(14793,'roof')
3 /
1 row created.
SQL> drop table manager_product
2 /
Table dropped.
SQL> create table manager_product(manager_product_id number,manager_product_name varchar2(20),manager_roof_id number)
2 /
Table created.
SQL> Insert into manager_product(manager_product_id,manager_product_name,manager_roof_id)
2 Values(19695,'product1', 14793)
3 /
1 row created.
SQL> drop table investment_vehicle
2 /
Table dropped.
SQL> create table investment_vehicle(investment_vehicle_id number,manager_product_id number,investment_vehicle_name varchar2(20))
2 /
Table created.
SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
2 Values(7031781,19695,'inv1')
3 /
1 row created.
SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
2 Values(7031782,19695,'inv3')
3 /
1 row created.
SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
2 Values(7031783,19695,'inv3')
3 /
1 row created.
SQL> COMMIT
2 /
Commit complete.
SQL>
SQL> select me.manager_entity_id
2 , me.manager_entity_type_id
3 , me.manager_entity_parent_id
4 , me.manager_entity_link_id
5 , level
6 from manager_entity me
7 start with me.manager_entity_id=&p_id
8 connect by prior me.manager_entity_id=me.manager_entity_parent_id
9
SQL> /
Enter value for p_id: 1
old 7: start with me.manager_entity_id=&p_id
new 7: start with me.manager_entity_id=1
no rows selectedAs soon as you fix the error:
SQL> drop table manager_entity
2 /
Table dropped.
SQL> create table manager_entity(manager_entity_id number,manager_entity_type_id number,manager_entity_parent_id number,manager_entity_link_id number)
2 /
Table created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(1,1008,null,14793)
3 /
1 row created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(263, 1009, 1, 19695)
3 /
1 row created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(803, 1010, 263, 7031783)
3 /
1 row created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(804, 1010, 263, 7031782)
3 /
1 row created.
SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
2 values(805, 1010, 263, 7031781)
3 /
1 row created.
SQL> drop table manager_roof
2 /
Table dropped.
SQL> create table manager_roof(manager_roof_id number,manager_roof_name varchar2(20))
2 /
Table created.
SQL> insert into manager_roof(manager_roof_id,manager_roof_name)
2 values(14793,'roof')
3 /
1 row created.
SQL> drop table manager_product
2 /
Table dropped.
SQL> create table manager_product(manager_product_id number,manager_product_name varchar2(20),manager_roof_id number)
2 /
Table created.
SQL> Insert into manager_product(manager_product_id,manager_product_name,manager_roof_id)
2 Values(19695,'product1', 14793)
3 /
1 row created.
SQL> drop table investment_vehicle
2 /
Table dropped.
SQL> create table investment_vehicle(investment_vehicle_id number,manager_product_id number,investment_vehicle_name varchar2(20))
2 /
Table created.
SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
2 Values(7031781,19695,'inv1')
3 /
1 row created.
SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
2 Values(7031782,19695,'inv3')
3 /
1 row created.
SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
2 Values(7031783,19695,'inv3')
3 /
1 row created.
SQL> COMMIT
2 /
Commit complete.
SQL>
SQL> select me.manager_entity_id
2 , me.manager_entity_type_id
3 , me.manager_entity_parent_id
4 , me.manager_entity_link_id
5 , level
6 from manager_entity me
7 start with me.manager_entity_id=&p_id
8 connect by prior me.manager_entity_id=me.manager_entity_parent_id
9
SQL> /
Enter value for p_id: 1
old 7: start with me.manager_entity_id=&p_id
new 7: start with me.manager_entity_id=1
MANAGER_ENTITY_ID MANAGER_ENTITY_TYPE_ID MANAGER_ENTITY_PARENT_ID MANAGER_ENTITY_LINK_ID LEVEL
1 1008 14793 1
263 1009 1 19695 2
803 1010 263 7031783 3
804 1010 263 7031782 3
805 1010 263 7031781 3
SQL> SY. -
Please tune my query written in PL/SQL.
Hi there,
I really appreciate you if could tune my query.
Here I am using tow tables PRDT_MASTER with 7 thosound records, REG_SUM with 50 records.
I get nearly 10 thosound records to my cursor.
From these 10 thosound records I have to prepare an SQL STATEMENT with dynamic sql.
That query selects sum() from ACTUALDATA table (This table contains nearly 75thosound records).
Then that data has to be inserted in to another table PROD_BRAND.
I had a predesigned tables where i can't change or create any index, Infact no tables any no index. There is no primary key on the columns also.
Now my problem is while i execute this procedure it is taking nearly 1 hour. I don't know why it is taking that much time. Is it because of dynamic sql and without any indexes?
Or IS IT NECESSARY for me to change anything???
Is there any alteranative way for me to over come from this problem....
Your help is really appreciatable bench mark for me.
I HAVE A TYPE FETCHCURSOR FOR REFCURSOR.
PROCEDURE PROD_MASTER_PRO
(DATE1 IN DATE
,DATE2 IN DATE
,TYPE IN VARCHAR2
) AS
MAINCUR MYPACK.FETCHCURSOR;
COU NUMBER(20);
V_SUM NUMBER(20);
V_SBUCODE VARCHAR2(255);
V_CATCODE VARCHAR2(255);
V_BRANDCODE VARCHAR2(255);
V_PRODCODE VARCHAR2(255);
V_TYPE VARCHAR2(10):= UPPER(TYPE);
REGNAME REG_SUM.REGION%TYPE;
CONDITION REG_SUM.COND%TYPE;
QRY VARCHAR2(2000);
BEGIN
--//This is for different catcodes codes
OPEN MAINCUR FOR
SELECT DISTINCT SBUCODE,CATCODE,PRODCODE,REGION ,COND
FROM PRDT_MASTER, REG_SUM
WHERE PRDT_MASTER.SBUCODE=REG_SUM.SUB
AND PRDT_MASTER.PRODCODE IS NOT NULL
ORDER BY SBUCODE,CATCODE,PRODCODE;
LOOP FETCH MAINCUR INTO V_SBUCODE,V_CATCODE,V_PRODCODE,REGNAME,CONDITION;
EXIT WHEN MAINCUR%NOTFOUND;
--SELECT NVL(SUM(GROSS),0) INTO V_SUM FROM ACTUALDATA WHERE PROD_CODE=V_PRODCODE
--AND (TRUNC(INV_DATE) BETWEEN DATE1 AND DATE2);
QRY:= 'SELECT NVL(SUM(GROSS),0) FROM ACTUALDATA ';
QRY:= QRY||' WHERE PROD_CODE= :V_PRODCODE_BIND ';
QRY:= QRY||' AND (TRUNC(INV_DATE) BETWEEN :DATE1_BIND AND :DATE2_BIND )';
QRY:= QRY||' AND '||CONDITION;
EXECUTE IMMEDIATE QRY INTO V_SUM USING V_PRODCODE ,DATE1,DATE2;
INSERT INTO PROD_BRAND
( PROD_CODE, SBUCODE , CODE ,
SUM , TYPE , CODE_TYPE,
REGION
) VALUES
( V_PRODCODE, V_SBUCODE, V_CATCODE,
V_SUM, PROD_MASTER_PRO.TYPE, 'THERAPY',
REGNAME
END LOOP;
CLOSE MAINCUR;
COMMIT;
END;
regards,
Khaleel.Parsing SQL is complex. Parsing SQL dynamically at run-time inside a FCAG policy function to determine what predicate to add, is a terribly bad idea. Performance wise and security wise.
Can you be more specific (basic example) of what you are trying to achieve? And more importantly, what business requirement you are attempting to solve with this approach?
Perhaps if we understand the full details, we can better assist you. -
Cosider the following record set from the emp table.
empno ename mgr
7839 KING
7566 SCOTT 7839
7566 BLAKE 7839
7782 CLARK 7839
If I use the following hierarchial query to populate a tree in Oracle forms
I will get the result as shown below.
Query
=====
select -1, level, ename, null, ename
from emp
where empno in (7839,7566,7698,7782)
start with ename = 'KING'
connect by mgr = prior empno;
Result
======
KING
JONES
BLAKE
CLARK
Here is my problem. Though diffrent employees can work under a manager,
we have some internal rules that assigns an order to each employee who
works under a manager. This helps us in identifying who should take
charge in the absence of a manager.
I have added one column to the emp table, in order to store the order in
which the employee reports to the manager.
Now the record set becomes
empno ename mgr emp_order
7839 KING 0
7566 SCOTT 7839 1
7566 BLAKE 7839 3
7782 CLARK 7839 2
Now I want the forms tree to be displayed as shown below.
KING
JONES
CLARK
BLAKE
(In short, I want the records in a particular level to be displayed
according to a pre-defined order, rather than getting them displayed
randomly).
Which query can I use for this purpose ?
Please help....
ShibuHi Guys,
Thanks a lot for your suggestions.
It really works great in SQL Plus.
I am familiar with Oracle Forms and I know how to use it if I want to build a tree in Forms.
Here is my requirement. I want to build the application using Oracle Portal. I know that there is something called 'Hierarchy' available in Portal. I don't know up to what extend it gives flexibility in programatically populating the tree.
Here is the scenario. I will use the hierarchial query with CONNECT SIBLINGS BY clause to populate the a tree which will show me employees in a department hierarchially.
Eg:
KING
SCOTT
BLAKE
SMITH
Now I like to show the projects assigned to each employee, which itself can be considered as another hierarchy.
Eg of Projects hierarchy.
Projects
Development
Oracle Applications
HRMS
Support
Intranet Applications
Suppose SCOTT is working in HRMS project, the tree should show as,
KING
SCOTT
Projects
Development
Oracle Applications
HRMS
BLAKE
SMITH
I can color code the node which will distinguish between an employee and his assignments.
Is there a way to achieve it in Oracle Portal using the 'Hierarchy' or what may be the best way to go (Applet etc...) ???
Thanks in advance for your help.
Shibu -
Hierarchy Query to get parent nodes?
Hi Everyone,
I want to write a hierarchy query which should give me the path starting from given node to its parents(Grand parents). below is the sample data and the output what i am expecting. and also the output what i am getting right now from my query.
CREATE TABLE RELATION (PARENT VARCHAR2(5),CHILD VARCHAR2(5) PRIMARY KEY);
--Data for the tree which starts from the root 'A'
Insert into RELATION (PARENT, CHILD) Values (NULL,'A');
Insert into RELATION (PARENT, CHILD) Values ('A', 'B');
Insert into RELATION (PARENT, CHILD) Values ('A', 'C');
Insert into RELATION (PARENT, CHILD) Values ('B', 'D');
Insert into RELATION (PARENT, CHILD) Values ('B', 'E');
Insert into RELATION (PARENT, CHILD) Values ('D', 'F');
Insert into RELATION (PARENT, CHILD) Values ('C', 'G');
--Data for the tree which starts from the root 'H'
Insert into RELATION (PARENT, CHILD) Values (NULL,'H');
Insert into RELATION (PARENT, CHILD) Values ('H', 'I');
Insert into RELATION (PARENT, CHILD) Values ('H', 'J');
Expected Output by passing values as 'F' which gives the path from bottom to up.
A<-B<-D<-F
My Query:
SELECT substr(sys_connect_by_path(child,'<-'),3)
FROM relation
WHERE connect_by_isleaf = 1
START WITH child = 'F'
CONNECT BY PRIOR parent = child
ORDER BY child;
Output of my query:
F<-D<-B<-A
I am getting the output in reverse order. i can use the reverse string function to reverse the string but the problem is the node can also contain the values like 'AC' 'BA'.. in future.
Can anyone please help me in getting the correct output.
Thank you in advance.I like ListAgg :D
with RELATION(PARENT,CHILD) as(
select NULL,'A' from dual union all
select 'A', 'B' from dual union all
select 'A', 'C' from dual union all
select 'B', 'D' from dual union all
select 'B', 'E' from dual union all
select 'D', 'F' from dual union all
select 'C', 'G' from dual union all
select NULL,'H' from dual union all
select 'H', 'I' from dual union all
select 'H', 'J' from dual)
SELECT ListAgg(child,'<-')
within group(order by Level desc) as revPath
FROM relation
START WITH child = 'F'
CONNECT BY PRIOR parent = child;
revPath
A<-B<-D<-F -
How to tune this query for the improve performance ?
Hi All,
How to tune this query for the improve performance ?
select a.claim_number,a.pay_cd,a.claim_occurrence_number,
case
when sum(case
when a.payment_status_cd ='0'
then a.payment_est_amt
else 0
end
)=0
then 0
else (sum(case
when a.payment_status_cd='0'and a.payment_est_amt > 0
then a.payment_est_amt
else 0
end)
- sum(case
when a.payment_status_cd<>'0'
then a.payment_amt
else 0
end))
end as estimate
from ins_claim_payment a
where a.as_of_date between '31-jan-03' and '30-aug-06'
and ( a.data_source = '25' or (a.data_source between '27' and '29'))
and substr(a.pay_cd,1,1) IN ('2','3','4','8','9')
group by a.claim_number, a.pay_cd, a.claim_occurrence_number
Thank you,
MckaMcka
As well as EXPLAIN PLAN, let us know what proportion of rows are visited by this query. It may be that it is not using a full table scan when it should (or vice versa).
And of course we'd need to know what indexes are available, and how selective they are for the predicated you have in this query ...
Regards Nigel -
Please tune this query.
Hi Experts,
My below query is taking long time.
[code]SELECT FAX_LIST.*
FROM (SELECT /*+ use_nl(fax, src) */
ROW_NUMBER () OVER (ORDER BY fax.ID ASC NULLS FIRST) RN,
fax.ACCOUNT_TYPE,
fax.BU_FILE_LOCATION,
fax.COUNT_PAGES_RECEIVED,
NVL (fax.CUSTOMER_NAME, fax.SENDER_NAME) AS CUSTOMER_NAME,
fax.FAX_SOURCE,
fax.CUSTOMER_NUMBER,
fax.CUSTOMER_OMEGA_NUMBER,
fax.GENIFAX_RECIPIENT_ID,
fax.ID AS FAX_ID,
fax.DATE_RECEIVED AS FAX_RECEIVED,
fax.IS_LOCKED,
fax.LOCKED_BY,
fax.ORIGINATOR_CSI,
fax.MARGIN,
fax.PAYMENT_TYPE,
fax.PRIORITY_CODE,
fax.PRIORITY_VALUE,
FROM_TZ (fax.DATE_RECEIVED, 'UTC')
AT TIME ZONE fax.LOCAL_TZ_NAME
AS DATE_RECEIVED,
fax.SALES_PERSON,
fax.SENDER_EMAIL,
fax.SENDER_NAME,
fax.SUBJECT,
fax.WORKGROUP_ID,
fax.LOCKED_TIME,
src.DESCRIPTION,
src.FAX_NUMBER,
src.WORKFLOW_ID,
fax.CREATED_BY,
fax.CREATED_DATE,
fax.UPDATE_DATE,
fax.UPDATED_BY,
fax.RESERVED_BY,
fax.PRICE_TO_ORDER,
fax.SKU_COUNT_TO_ORDER,
NVL (ORL.GET_FTH_WTR (fax.LAST_TRANSITION_ID).CHANGED_BY,
CASE
WHEN fax.LAST_TRANSITION_ID IS NULL
AND fax.GENIFAX_RECIPIENT_ID IS NOT NULL
THEN
'ORL FEEDER'
ELSE
'Admin'
END)
AS LAST_USER,
FROM_TZ (
NVL (ORL.GET_FTH_WTR (fax.LAST_TRANSITION_ID).CHANGED_DATE,
fax.DATE_RECEIVED),
'UTC')
AT TIME ZONE fax.LOCAL_TZ_NAME
AS MOVE_DATETIME,
NVL (ORL.GET_FTH_WTR (fax.LAST_TRANSITION_ID).REASON,
'Reroute')
AS MOVE_REASON,
NVL (
(SELECT fw.DESCRIPTION
FROM ORL.WORKGROUP_TRANSITION wt, ORL.WORKGROUP fw
WHERE wt.ID =
ORL.GET_FTH_WTR (fax.LAST_TRANSITION_ID).WORKGROUP_TRANSITION_ID
AND fw.ID = wt.CURRENT_WORKGROUP_ID),
CASE
WHEN fax.LAST_TRANSITION_ID IS NULL
AND fax.GENIFAX_RECIPIENT_ID IS NOT NULL
THEN
'ORL FEEDER STAGING'
ELSE
'N/A'
END)
AS OLD_STATUS,
(SELECT MAX (PURCHASE_ORDER_NUMBER)
FROM ORL.FAX_OFFER_DETAIL
WHERE FAX_ID = fax.ID)
AS MAXPO,
(SELECT CASE COUNT (PURCHASE_ORDER_NUMBER)
WHEN 0 THEN NULL
ELSE COUNT (PURCHASE_ORDER_NUMBER)
END
AS POCOUNT
FROM ORL.FAX_OFFER_DETAIL
WHERE FAX_ID = fax.ID)
AS POCOUNT,
(SELECT SUM (VALUE) AS ORDER_VALUE
FROM ORL.FAX_OFFER_DETAIL
WHERE FAX_ID = fax.ID)
AS ORDER_VALUE,
fax.SALESPERSON_NAME,
fax.GROUP_NAME,
fax.ROLE_NAME,
fax.EMAIL,
fax.SALES_CHANNEL
FROM (SELECT fax.*,
map.ORACLE_TZ_NAME AS LOCAL_TZ_NAME,
ORL.GET_SALESPERSON (map.ORG_ID, fax.SALES_PERSON).SALESPERSON_NAME
AS SALESPERSON_NAME,
ORL.GET_SALESPERSON (map.ORG_ID, fax.SALES_PERSON).GROUP_NAME
AS GROUP_NAME,
ORL.GET_SALESPERSON (map.ORG_ID, fax.SALES_PERSON).ROLE_NAME
AS ROLE_NAME,
ORL.GET_SALESPERSON (map.ORG_ID, fax.SALES_PERSON).EMAIL
AS EMAIL,
ORL.GET_SALESPERSON (map.ORG_ID, fax.SALES_PERSON).SALES_CHANNEL
AS SALES_CHANNEL
FROM APPS_GLOBAL.GLOBAL_BU_MAPPING map,
(SELECT *
FROM ORL.FAX_HEADER FH
WHERE FH.WORKGROUP_ID = 262) fax
WHERE map.GEDIS = 'Y'
AND map.BU_ID = (SELECT BUID
FROM ORL.WORKGROUP
WHERE ID = fax.WORKGROUP_ID)
AND ORL.GET_SALESPERSON (map.ORG_ID, fax.SALES_PERSON).SALESPERSON_NAME =
'A_CARRICK') fax,
(SELECT *
FROM ORL.FAX_SOURCE FS
WHERE FS.WORKFLOW_ID IN
(SELECT /*+ CARDINALITY(t, 1) */
TO_NUMBER (
COLUMN_VALUE)
AS COLUMN_VALUE
FROM TABLE (
SplitClob ('1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98', ',')) t)) src
WHERE src.ID(+) = fax.FAX_SOURCE) FAX_LIST
WHERE RN BETWEEN 1 AND 100
ORDER BY RN ASC;[/code]
In my query the following three functions are using.
ORL.GET_FTH_WTR
ORL.GET_SALESPERSON
APPS_GLOBAL.SplitClob
[code]CREATE OR REPLACE FUNCTION ORL.GET_FTH_WTR(p_LAST_TRANSITION_ID NUMBER)
RETURN ORL.FTH_WTR_T
DETERMINISTIC
IS
v_REASON nvarchar2(1024 char);
v_WORKGROUP_TRANSITION_ID number;
v_CHANGED_BY nvarchar2(64 char);
v_CHANGED_DATE timestamp(6);
BEGIN
SELECT
WTR.REASON,
wtr.WORKGROUP_TRANSITION_ID,
fth.CHANGED_BY,
fth.CHANGED_DATE
INTO
v_REASON,
v_WORKGROUP_TRANSITION_ID,
v_CHANGED_BY,
v_CHANGED_DATE
FROM
ORL.FAX_TRANSITION_HISTORY fth,
ORL.WORKGROUP_TRANSITION_REASON wtr
WHERE
fth.ID = p_LAST_TRANSITION_ID
AND wtr.ID(+) = fth.TRANSITION_REASON_ID;
RETURN ORL.FTH_WTR_T(v_CHANGED_BY, v_CHANGED_DATE, v_REASON, v_WORKGROUP_TRANSITION_ID);
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN ORL.FTH_WTR_T(NULL, NULL, NULL, NULL);
END GET_FTH_WTR;
CREATE OR REPLACE function ORL.GET_SALESPERSON(ORG_ID number, SALESPERSON_ID number)
return ORL.SALESPERSON_T
deterministic
is
apps_bu varchar2(30);
salesperson_name varchar2(150 char);
email varchar2(70 char);
sales_channel varchar2(60 char);
role_name varchar2(60 char);
group_name varchar2(60 char);
begin
select OWNER_NAME into apps_bu
from APPS_GLOBAL.GLOBAL_BU_MAPPING
where ORG_ID = GET_SALESPERSON.ORG_ID;
execute immediate
replace('
select SALESPERSON_NAME
, EMAIL
, SALES_CHANNEL
, ROLE_NAME
, GROUP_NAME
from APPS_**.ORL_ACTIVE_SALESPERSON
where SALESPERSON_ID = :1
and rownum = 1
', 'APPS_**', apps_bu)
into salesperson_name, email, sales_channel, role_name, group_name
using SALESPERSON_ID;
return SALESPERSON_T(ORG_ID, SALESPERSON_ID, salesperson_name, email, sales_channel, role_name, group_name);
exception
when no_data_found then
return SALESPERSON_T(null, null, null, null, null, null, null);
end GET_SALESPERSON;
CREATE OR REPLACE function APPS_GLOBAL.SplitClob
p_clob clob
, p_delimiter varchar2 := ','
return StringTable
deterministic
pipelined
as
v_current_pos pls_integer := 1;
v_delimiter_pos pls_integer;
begin
if (p_clob is not NULL) and (p_delimiter is not NULL) then
while v_current_pos <= length(p_clob) loop
v_delimiter_pos := instr(p_clob, p_delimiter, v_current_pos);
if v_delimiter_pos < 1 then -- no more delimiters
v_delimiter_pos := length(p_clob) + 1;
end if;
pipe row( to_char( substr(p_clob,
v_current_pos,
v_delimiter_pos - v_current_pos) ) );
v_current_pos := v_delimiter_pos + length(p_delimiter);
end loop;
end if;
end SplitClob;
CREATE OR REPLACE TYPE SALESPERSON_T AS OBJECT
SALESPERSON_ID number(15)
, SALESPERSON_NUMBER varchar2(150 char)
, FIRST_NAME varchar2(20 char)
, LAST_NAME varchar2(40 char)
, SALES_CHANNEL varchar2(60 char)
, ORG_ID number(15)
, USER_NAME varchar2(61 char)
, EFFECTIVE_START_DATE date
, EFFECTIVE_END_DATE date
, STATUS_FLAG varchar2(1 char)
, EMAIL varchar2(70 char)
, WORK_TELEPHONE varchar2(60 char)
, MANAGERS_NAME varchar2(50 char)
, FAX_NO varchar2(60 char)
, SALESPERSON_NAME varchar2(30 char)
, TERRITORY varchar2(40 char)
, FO_LOGON varchar2(150 char)
, BO_LOGON varchar2(150 char)
, SUB_CHANNEL varchar2(25 char)
, BUSINESS_SEGMENT varchar2(3 char)
, DISCOUNT_NAME varchar2(30 char)
, RESPONSIBILITY_ID number
, RESPONSIBILITY_KEY varchar2(30 char)
CREATE OR REPLACE TYPE STRINGTABLE as table of varchar2(4000);[/code]
The total number of records in each table.
[code]SELECT COUNT(*) FROM ORL.FAX_HEADER FH --4397829
SELECT COUNT(*) FROM APPS_GLOBAL.GLOBAL_BU_MAPPING map --31
SELECT COUNT(*) FROM ORL.WORKGROUP_TRANSITION --6735
SELECT COUNT(*) FROM ORL.WORKGROUP fw --1495
SELECT COUNT(*) FROM ORL.FAX_OFFER_DETAIL --5904039
SELECT COUNT(*) FROM ORL.FAX_SOURCE--2368 --2457[/code]
Indexes on the columns.
[code]ORL.WORKGROUP_TRANSITION(ID),
ORL.WORKGROUP(ID),
ORL.FAX_OFFER_DETAIL(FAX_ID),
ORL.FAX_HEADER(WORKGROUP_ID).[/code]
Please help me to tune this query.
Thanks in advance.Hi,
Thanks for your reply.
For split the numbers into different rows , we are sending randomly.
It's not constant numbers.We have used bind variables.
For testing purpose I have hard coded the values.
How to do this split without using user defined function.
I am sending the actual query along with execution plan without any hints.
[code]SELECT FAX_LIST.*
FROM (SELECT ROW_NUMBER () OVER (ORDER BY fax.ID ASC) RN,
fax.ACCOUNT_TYPE,
fax.BU_FILE_LOCATION,
fax.COUNT_PAGES_RECEIVED,
NVL (fax.CUSTOMER_NAME, fax.SENDER_NAME) AS CUSTOMER_NAME,
fax.FAX_SOURCE,
fax.CUSTOMER_NUMBER,
fax.CUSTOMER_OMEGA_NUMBER,
fax.GENIFAX_RECIPIENT_ID,
fax.ID AS FAX_ID,
fax.DATE_RECEIVED AS FAX_RECEIVED,
fax.IS_LOCKED,
fax.LOCKED_BY,
fax.ORIGINATOR_CSI,
fax.MARGIN,
fax.PAYMENT_TYPE,
fax.PRIORITY_CODE,
fax.PRIORITY_VALUE,
FROM_TZ (fax.DATE_RECEIVED, 'UTC') AT TIME ZONE map.ORACLE_TZ_NAME AS DATE_RECEIVED,
fax.SALES_PERSON,
fax.SENDER_EMAIL,
fax.SENDER_NAME,
fax.SUBJECT,
fax.WORKGROUP_ID,
fax.LOCKED_TIME,
src.DESCRIPTION,
src.FAX_NUMBER,
src.WORKFLOW_ID,
fax.CREATED_BY,
fax.CREATED_DATE,
fax.UPDATE_DATE,
fax.UPDATED_BY,
fax.RESERVED_BY,
fax.PRICE_TO_ORDER,
fax.SKU_COUNT_TO_ORDER,
NVL (
ORL.GET_FTH_WTR (fax.LAST_TRANSITION_ID).CHANGED_BY,
CASE
WHEN fax.LAST_TRANSITION_ID IS NULL
AND fax.GENIFAX_RECIPIENT_ID IS NOT NULL
THEN
'ORL FEEDER'
ELSE
'Admin'
END
AS LAST_USER,
FROM_TZ (NVL (ORL.GET_FTH_WTR (fax.LAST_TRANSITION_ID).CHANGED_DATE,fax.DATE_RECEIVED),'UTC')
AT TIME ZONE map.ORACLE_TZ_NAME AS MOVE_DATETIME,
NVL (ORL.GET_FTH_WTR (fax.LAST_TRANSITION_ID).REASON,'Reroute')AS MOVE_REASON,
NVL ((SELECT fw.DESCRIPTION
FROM ORL.WORKGROUP_TRANSITION wt, ORL.WORKGROUP fw
WHERE wt.ID =
ORL.GET_FTH_WTR (
fax.LAST_TRANSITION_ID
).WORKGROUP_TRANSITION_ID
AND fw.ID = wt.CURRENT_WORKGROUP_ID),
CASE
WHEN fax.LAST_TRANSITION_ID IS NULL
AND fax.GENIFAX_RECIPIENT_ID IS NOT NULL
THEN
'ORL FEEDER STAGING'
ELSE
'N/A'
END
AS OLD_STATUS,
(SELECT MAX (PURCHASE_ORDER_NUMBER)
FROM ORL.FAX_OFFER_DETAIL
WHERE FAX_ID = fax.ID)
AS MAXPO,
(SELECT CASE COUNT (PURCHASE_ORDER_NUMBER)
WHEN 0 THEN NULL
ELSE COUNT (PURCHASE_ORDER_NUMBER)
END
AS POCOUNT
FROM ORL.FAX_OFFER_DETAIL
WHERE FAX_ID = fax.ID)
AS POCOUNT,
(SELECT SUM (VALUE) AS ORDER_VALUE
FROM ORL.FAX_OFFER_DETAIL
WHERE FAX_ID = fax.ID) AS ORDER_VALUE,
ORL.GET_SALESPERSON (map.ORG_ID,fax.SALES_PERSON).SALESPERSON_NAME AS SALESPERSON_NAME,
ORL.GET_SALESPERSON (map.ORG_ID,fax.SALES_PERSON).GROUP_NAME AS GROUP_NAME,
ORL.GET_SALESPERSON (map.ORG_ID,fax.SALES_PERSON).ROLE_NAME AS ROLE_NAME,
ORL.GET_SALESPERSON (map.ORG_ID, fax.SALES_PERSON).EMAIL AS EMAIL,
ORL.GET_SALESPERSON (map.ORG_ID, fax.SALES_PERSON).SALES_CHANNEL AS SALES_CHANNEL
FROM ORL.FAX_HEADER fax,
APPS_GLOBAL.GLOBAL_BU_MAPPING map,
ORL.FAX_SOURCE src
WHERE fax.WORKGROUP_ID = :WORKGROUP_ID
AND map.GEDIS = 'Y'
AND map.BU_ID = (SELECT BUID
FROM ORL.WORKGROUP
WHERE ID = fax.WORKGROUP_ID)
AND ORL.GET_SALESPERSON (map.ORG_ID,fax.SALES_PERSON).GROUP_NAME =:SALES_TEAM
AND ORL.GET_SALESPERSON (map.ORG_ID,fax.SALES_PERSON
).SALESPERSON_NAME = :SALESPERSON_NAME
AND src.WORKFLOW_ID IN
(SELECT TO_NUMBER (COLUMN_VALUE) AS COLUMN_VALUE
FROM table(SplitClob (:WORKFLOW_ID,:WORKFLOW_ID_delim)) t)
AND src.ID(+) = fax.FAX_SOURCE) FAX_LIST
WHERE RN BETWEEN 1 AND 100;
Execution Plan
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
| 0 | SELECT STATEMENT | | 2 | 12092 | 88923 (1)|
| 1 | NESTED LOOPS | | 1 | 38 | 3 (0)|
| 2 | TABLE ACCESS BY INDEX ROWID | WORKGROUP_TRANSITION | 1 | 9 | 2 (0)|
| 3 | INDEX UNIQUE SCAN | PK_WORKGROUP_TRANSITION | 1 | | 1 (0)|
| 4 | TABLE ACCESS BY INDEX ROWID | WORKGROUP | 1482 | 42978 | 1 (0)|
| 5 | INDEX UNIQUE SCAN | PK_WORKGROUP | 1 | | 0 (0)|
| 6 | SORT AGGREGATE | | 1 | 16 | |
| 7 | TABLE ACCESS BY INDEX ROWID | FAX_OFFER_DETAIL | 1 | 16 | 5 (0)|
| 8 | INDEX RANGE SCAN | FAX_OFFER_DETAIL_IDX1 | 1 | | 3 (0)|
| 9 | SORT AGGREGATE | | 1 | 16 | |
| 10 | TABLE ACCESS BY INDEX ROWID | FAX_OFFER_DETAIL | 1 | 16 | 5 (0)|
| 11 | INDEX RANGE SCAN | FAX_OFFER_DETAIL_IDX1 | 1 | | 3 (0)|
| 12 | SORT AGGREGATE | | 1 | 11 | |
| 13 | TABLE ACCESS BY INDEX ROWID | FAX_OFFER_DETAIL | 1 | 11 | 5 (0)|
| 14 | INDEX RANGE SCAN | FAX_OFFER_DETAIL_IDX1 | 1 | | 3 (0)|
| 15 | VIEW | | 2 | 12092 | 88923 (1)|
| 16 | WINDOW SORT PUSHED RANK | | 2 | 1378 | 88923 (1)|
| 17 | NESTED LOOPS | | | | |
| 18 | NESTED LOOPS | | 2 | 1378 | 88920 (1)|
| 19 | NESTED LOOPS | | 18420 | 11M| 70490 (1)|
| 20 | HASH JOIN RIGHT SEMI | | 69 | 3657 | 49 (3)|
| 21 | COLLECTION ITERATOR PICKLER FETCH| SPLITCLOB | 8168 | 16336 | 29 (0)|
| 22 | TABLE ACCESS FULL | FAX_SOURCE | 2409 | 119K| 19 (0)|
| 23 | TABLE ACCESS BY INDEX ROWID | FAX_HEADER | 268 | 160K| 2854 (1)|
| 24 | INDEX RANGE SCAN | FAX_HEADER_FS_IDX | 4345 | | 7 (0)|
| 25 | INDEX RANGE SCAN | GLOBAL_BU_MAPPING_BUID | 1 | | 0 (0)|
| 26 | TABLE ACCESS BY INDEX ROWID | WORKGROUP | 1 | 8 | 2 (0)|
| 27 | INDEX UNIQUE SCAN | PK_WORKGROUP | 1 | | 1 (0)|
| 28 | TABLE ACCESS BY INDEX ROWID | GLOBAL_BU_MAPPING | 1 | 24 | 1 (0)|
Note
- 'PLAN_TABLE' is old version
Statistics
894400 recursive calls
60 db block gets
7402741 consistent gets
0 physical reads
0 redo size
46309 bytes sent via SQL*Net to client
430 bytes received via SQL*Net from client
8 SQL*Net roundtrips to/from client
848304 sorts (memory)
0 sorts (disk)
100 rows processed[/code]
Please help me.
Thanks in advance. -
Hi All,
I have below tables,
Tables
1 Employees Type (Tells About Employees Designation)
2.Employee Details (Tells Employee Details)
3.Employee Relation (Tells Relationship between Employees)
Hierarchy
ARC (SENIOR MANAGER)
SUN (MANAGER)
MOON (TECH LEAD)
LITE (EMPLOYEE)
RAG (TECH LEAD)
BESH (TECH LEAD)
CHESH (EMPLOYEE)
PRASAD (EMPLOYEE)
1 Employees Type Data
Type No||Type Name
1|Employee
2|Tech Lead
3|Manager
4|Senior Manager
2.Employee Details
Emp No||Emp Name|Employee Type
10|ARC|4
20|SUN|3
30|RAG|2
40|PRASAD|1
50|MOON|2
60|LITE|1
70|CHESH|1
80|BESH|2
3. Employee Relation
Relation Number|Emp No|Prnt_Relation Number
1|10|NULL
2|20|1
3|30|1
4|40|1
5|50|2
6|60|2
7|70|3
8|80|3
These are my tables structure,
Now I want Hierarchial Query for below,
Input will be Relation Number,
if I give relation number as input I want to display all immediate childern that are Tech Leads and Employees only (it should ignore if it is having any Managers in the result set)
Ex: -
Input is relation number from Employee Relation Table,
If I give input as *1*
Output Should be,
Relation Number|Employee_id|Employee Name
3|30|Rag
7|70|Besh
8|80|Chesh
If I give input as *2*
Output Should be,
Relation Number|Employee_id|Employee Name
5|50|MOON
6|60|LITE,
If I give input as *4*
Output Should be,
Relation Number|Employee_id|Employee Name
<NO Rows Returned>
Thanks,Hi,
with emp_type as ( select 1 type_id, 'Employee' emp_type from dual
union
select 2 type_id, 'Tech Lead' emp_type from dual
union
select 3 type_id, 'Manager' emp_type from dual
union
select 4 type_id, 'Senior Manager' emp_type from dual),
emp_details as ( select 10 emp_no, 'ARC' fname, 4 type1 from dual
union
select 20 emp_no, 'SUN' fname, 3 type1 from dual
union
select 30 emp_no, 'RAG' fname, 2 type1 from dual
union
select 40 emp_no, 'PRASAD' fname, 1 type1 from dual
union
select 50 emp_no, 'MOON' fname, 2 type1 from dual
union
select 60 emp_no, 'LITE' fname, 1 type1 from dual
union
select 70 emp_no, 'CHESH' fname, 1 type1 from dual
union
select 80 emp_no, 'BESH' fname, 2 type1 from dual),
Emp_Relation as (
select 1 Relation, 10 emp_no1, null parent_Relation from dual
union
select 2 Relation, 20 emp_no1, 1 parent_Relation from dual
union
select 3 Relation, 30 emp_no1, 1 parent_Relation from dual
union
select 4 Relation, 40 emp_no1, 1 parent_Relation from dual
union
select 5 Relation, 50 emp_no1, 2 parent_Relation from dual
union
select 6 Relation, 60 emp_no1, 2 parent_Relation from dual
union
select 7 Relation, 70 emp_no1, 3 parent_Relation from dual
union
select 8 Relation, 80 emp_no1, 8 parent_Relation from dual)
select type_id, emp_type,
emp_no, fname, relation, parent_relation
from EMP_DETAILS, EMP_TYPE, EMP_RELATION
WHERE TYPE_ID = type1
AND EMP_NO = EMP_NO1
AND LEVEL = 2
CONNECT BY PRIOR RELATION = PARENT_RELATION
START WITH RELATION = :P_RELATION
--START WITH PARENT_RELATION IS NULL -- If want to display the complete heirarchy remove comments for this line and remove "and level = 2" and "START WITH RELATION = :P_RELATION"For p_relation = 1
TYPE_ID EMP_TYPE EMP_NO FNAME RELATION PARENT_RELATION
3 Manager 20 SUN 2 1
2 Tech Lead 30 RAG 3 1
1 Employee 40 PRASAD 4 1
3 rows selected.Not sure how do you get the following and it's not clear on what basis.
If I give input as *1*
Output Should be,
Relation Number|Employee_id|Employee Name
3|30|Rag
7|70|Besh
8|80|CheshFor p_relation = 2
TYPE_ID EMP_TYPE EMP_NO FNAME RELATION PARENT_RELATION
2 Tech Lead 50 MOON 5 2
1 Employee 60 LITE 6 2
2 rows selected.For p_relation = 3
TYPE_ID EMP_TYPE EMP_NO FNAME RELATION PARENT_RELATION
1 Employee 70 CHESH 7 3
1 row selected.For p_relation = 4
no rows selected.Hope this helps
Best Regards
Arif Khadas
Edited by: Arif Khadas on Jun 29, 2010 12:47 PM -
Hi,
How I can tune sql query? what are the steps for tuning.First important step: Infomation gathering. One part can be learning to use the powerful search engine. E.g. search this forum for: "When your query takes too long".
Second step: Information processing. Check the data you found and apply it to your problem
Third step: Testing. Compare the result of the applied change before and after. Was there any performance gain as expected? -
Get only last level in SQL Hierarchy Query
Hi,
How to get only the last level in Oracle SQL Hierarchy Query?
ThanksHi,
1007372 wrote:
Hi,
How to get only the last level in Oracle SQL Hierarchy Query?Depending on your requirements:
WHERE CONNECT_BY_ISLEAF = 1
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
If you can show what you want to do using commonly available tables (such as scott.emp, which contains a hierarchy), then you don't need to post any sample data; just the results and the explanation.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0). This is always important, but especially so with CONNECT BY queries, because every version since Oracle 7 has had significant improvements in this area.
See the forum FAQ {message:id=9360002}
Maybe you are looking for
-
Files moved to external hardrive now iTunes library is empty
I moved iTunes to an external hard drive, but when I go to use iTunes the library is blank. I still have the library on the new drive, how do I get it to appear back on iTunes. My iPod has not been docked so the library in on the iPod as well. Please
-
Hi all, I have a serious problem with my powerbook: The last day or two the whole system has frozen (no cursor movement/no force quit) so I had to do a couple of hard resets (pressing the power button) This morning a lot of white writing on black bac
-
How do get my iphone 4 to be recognized by tvs using the usb port
When i connect my iphone 4 through the usb port of tvs it is not recognized.
-
Multiple cells selection after research
Hi to everyone, i'm trying to create a function word-find into a JTable (like the fuction - find on this page CTRL F). Now my method, when there are two or more same objects in the table, selects(with a differrent cell background) only the last one o
-
Suggestions for a gaming laptop
So I am curious about buying a laptop that can handle games, even if it is at the lowest available setting. The sims 3 would a great game to base the requirements off of. I am willing to spend up to about 1000$ but would really like to go cheaper tha