Need Help in sql tuning in EXADATA environment

I am uploadin the sql with its current explain plan, this sql in Prd database is executing in 6-10 mins and we need to improve this sql perf to 1-2 mins as the requirement from business team.
I am giving some backgroud about this sql tuning requirement, this sql is newly developed in and currently is in UAT phase, we don't have much option for tuning code here since the sql is tool generated through COGNOS DataMart tool, options are there to look into from DBA end with plan level or creating indexes on suitible columns to reduce i/o in minimizing the rows traversing by the sql.
Is anybody can help me out here?
WITH "WCRS_CLAIM_DETAIL_VW5"
AS (SELECT "WCRS_CLAIM_DETAIL_VW"."CLAIM_DETAIL_PK_ID"
"CLAIM_DETAIL_PK_ID",
"WCRS_CLAIM_DETAIL_VW"."CLAIM_ID" "CLAIM_ID",
"WCRS_CLAIM_DETAIL_VW"."CURRENT_SNAPSHOT_IND"
"CURRENT_SNAPSHOT_IND",
"WCRS_CLAIM_DETAIL_VW"."LOSS_DT" "LOSS_DT",
"WCRS_CLAIM_DETAIL_VW"."REGULATORY_STATE_CD"
"REGULATORY_STATE_CD"
FROM "CDW_DLV_IDS"."WCRS_CLAIM_DETAIL_VW" "WCRS_CLAIM_DETAIL_VW"
WHERE "WCRS_CLAIM_DETAIL_VW"."CURRENT_SNAPSHOT_IND" = 'Y'),
"WCRS_POLICY_DETAIL_VW7"
AS (SELECT "WCRS_POLICY_DETAIL_VW"."CLAIM_NBR" "CLAIM_NBR",
"WCRS_POLICY_DETAIL_VW"."CLAIM_SYMBOL_CD" "CLAIM_SYMBOL_CD",
"WCRS_POLICY_DETAIL_VW"."CURRENT_SNAPSHOT_IND"
"CURRENT_SNAPSHOT_IND",
"WCRS_POLICY_DETAIL_VW"."KEY_OFFICE_CD" "KEY_OFFICE_CD",
"WCRS_POLICY_DETAIL_VW"."POLICY_NBR" "POLICY_NBR"
FROM "CDW_DLV_IDS"."WCRS_POLICY_DETAIL_VW" "WCRS_POLICY_DETAIL_VW"
WHERE "WCRS_POLICY_DETAIL_VW"."CURRENT_SNAPSHOT_IND" = 'Y')
SELECT /*+ gather_plan_statistics monitor bind_aware */
/* ^^unique_id */
"T0"."C0" "Account_Name",
"T0"."C1" "Accident_State_Cd",
"T0"."C2" "c3",
"T0"."C3" "PPO_Name",
"T0"."C4" "Invc_Classification_Type_Desc",
FIRST_VALUE (
"T0"."C5")
OVER (
PARTITION BY "T0"."C0",
"T0"."C1",
"T0"."C2",
"T0"."C3",
"T0"."C4",
"T0"."C6")
"Claim_Cnt___Distinct",
"T0"."C7" "Invc_Control_Number",
"T0"."C8" "Invc_Allowance_Amt",
"T0"."C9" "Invc_Charge_Amt",
"T0"."C10" "c10",
"T0"."C11" "PPO_Reduction_Amt",
"T0"."C12" "Dup_Ln_Save_Amt",
"T0"."C13" "c13",
"T0"."C14" "Sub_Total",
"T0"."C15" "c15",
"T0"."C6" "c16"
FROM (SELECT "T1"."C0" "C0",
"T1"."C1" "C1",
"T1"."C2" "C2",
"T1"."C3" "C3",
"T1"."C4" "C4",
"T1"."C6" "C5",
"T1"."C5" "C6",
"T0"."C0" "C7",
"T1"."C7" "C8",
"T1"."C8" "C9",
"T1"."C9" "C10",
"T1"."C10" "C11",
"T1"."C11" "C12",
"T1"."C12" "C13",
"T1"."C13" "C14",
"T1"."C14" "C15"
FROM (SELECT COUNT (DISTINCT "INVC_DIM_VW"."INVC_ID") "C0"
FROM "CDW_DLV_IDS"."WCRS_POLICY_GROUPING_VW" "WCRS_POLICY_GROUPING_VW",
"WCRS_CLAIM_DETAIL_VW5",
"EDW_DM"."INVC_DIM_VW" "INVC_DIM_VW",
"EDW_DM"."PROVIDER_NETWORK_DIM_VW" "PROVIDER_NETWORK_DIM_VW",
"EDW_DM"."INVC_ACTY_SNPSHT_FACT_VW" "INVC_ACTY_SNPSHT_FACT_VW6",
"EDW_DM"."CURRENT_MED_INVC_RPT_DT_VW" "CURRENT_MED_INVC_RPT_DT_VW",
"EDW_DM"."ALL_INVC_SNPSHT_FACT_VW" "ALL_INVC_SNPSHT_FACT_VW",
"CDW_DLV_IDS"."WCRS_CURRENT_CLAIM_RPT_DT_VW" "WCRS_CURRENT_CLAIM_RPT_DT_VW",
"CDW_DLV_IDS"."WCRS_CLAIM_FACT_VW" "WCRS_CLAIM_FACT_VW",
"WCRS_POLICY_DETAIL_VW7",
"EDW_DM"."INVC_CLAIM_DTL_BRDG_FACT_VW" "INVC_CLAIM_DTL_BRDG_FACT_VW"
WHERE "INVC_DIM_VW"."INVC_DELETION_IND" <> 'Y'
AND "INVC_DIM_VW"."INVC_CONSIDRTN_TYPE_DESC" =
'Original'
AND "CURRENT_MED_INVC_RPT_DT_VW"."CURRENT_MONTH_RPT_DT" =
"ALL_INVC_SNPSHT_FACT_VW"."AS_OF_MONTH_END_DT_PK_ID"
AND "WCRS_CURRENT_CLAIM_RPT_DT_VW"."CURRENT_CLAIM_RPT_DT" =
"WCRS_CLAIM_FACT_VW"."CLAIM_REPORTING_DT"
AND "WCRS_POLICY_GROUPING_VW"."ACCOUNT_NM" =
CAST ('1ST TEAM STAFFING SERVICES, INC.' AS VARCHAR (50 CHAR))
AND "WCRS_POLICY_DETAIL_VW7"."POLICY_NBR" =
"WCRS_POLICY_GROUPING_VW"."POLICY_IDENTIFIER"
AND "WCRS_POLICY_DETAIL_VW7"."CLAIM_NBR" =
"WCRS_CLAIM_FACT_VW"."CLAIM_NBR"
AND "WCRS_POLICY_DETAIL_VW7"."CLAIM_SYMBOL_CD" =
"WCRS_CLAIM_FACT_VW"."CLAIM_SYMBOL_CD"
AND "WCRS_POLICY_DETAIL_VW7"."KEY_OFFICE_CD" =
"WCRS_CLAIM_FACT_VW"."KEY_OFFICE_CD"
AND "WCRS_POLICY_DETAIL_VW7"."CURRENT_SNAPSHOT_IND" =
'Y'
AND "WCRS_CLAIM_FACT_VW"."CLAIM_DETAIL_PK_ID" =
"WCRS_CLAIM_DETAIL_VW5"."CLAIM_DETAIL_PK_ID"
AND "WCRS_CLAIM_DETAIL_VW5"."CURRENT_SNAPSHOT_IND" =
'Y'
AND "WCRS_CLAIM_FACT_VW"."CLAIM_GID" =
"INVC_CLAIM_DTL_BRDG_FACT_VW"."CLM_GID"
AND "INVC_CLAIM_DTL_BRDG_FACT_VW"."INVC_GID" =
"INVC_DIM_VW"."INVC_GID"
AND "INVC_DIM_VW"."INVC_PK_ID" =
"INVC_ACTY_SNPSHT_FACT_VW6"."INVC_PK_ID"
AND "ALL_INVC_SNPSHT_FACT_VW"."MONTH_END_DT_PK_ID" =
"INVC_ACTY_SNPSHT_FACT_VW6"."MONTH_END_DT_PK_ID"
AND "ALL_INVC_SNPSHT_FACT_VW"."INVC_GID" =
"INVC_ACTY_SNPSHT_FACT_VW6"."INVC_GID"
AND "PROVIDER_NETWORK_DIM_VW"."PROVIDER_NETWORK_PK_ID" =
"INVC_ACTY_SNPSHT_FACT_VW6"."PPO_PROVIDER_NETWORK_PK_ID"
AND "WCRS_CURRENT_CLAIM_RPT_DT_VW"."CURRENT_CLAIM_RPT_DT" =
"WCRS_CLAIM_FACT_VW"."CLAIM_REPORTING_DT") "T0",
( SELECT "WCRS_POLICY_GROUPING_VW"."ACCOUNT_NM" "C0",
"WCRS_CLAIM_DETAIL_VW5"."REGULATORY_STATE_CD" "C1",
CASE
WHEN "INVC_DIM_VW"."INVC_IN_OUT_OF_NETWORK_IND" =
'Y'
THEN
'In - Network'
WHEN "INVC_DIM_VW"."INVC_IN_OUT_OF_NETWORK_IND" =
'N'
THEN
'Out - Network'
ELSE
'Others'
END
"C2",
"PROVIDER_NETWORK_DIM_VW"."PROVIDER_NETWORK_NM" "C3",
"INVC_DIM_VW"."INVC_CLASS_TYPE_DESC" "C4",
CASE
WHEN (EXTRACT (
YEAR FROM ("WCRS_CLAIM_DETAIL_VW5"."LOSS_DT"))
IS NULL)
OR (EXTRACT (
MONTH FROM ("WCRS_CLAIM_DETAIL_VW5"."LOSS_DT"))
IS NULL)
THEN
NULL
ELSE
( EXTRACT (
YEAR FROM ("WCRS_CLAIM_DETAIL_VW5"."LOSS_DT"))
|| EXTRACT (
MONTH FROM ("WCRS_CLAIM_DETAIL_VW5"."LOSS_DT")))
END
"C5",
COUNT (DISTINCT "WCRS_CLAIM_DETAIL_VW5"."CLAIM_ID")
"C6",
SUM ("INVC_ACTY_SNPSHT_FACT_VW6"."INVC_ALWC_AMT") "C7",
SUM ("INVC_ACTY_SNPSHT_FACT_VW6"."INVC_CHRGS_AMT")
"C8",
SUM (
"INVC_ACTY_SNPSHT_FACT_VW6"."TOT_INVC_REVIEW_RULE_ALWC_AMT")
"C9",
SUM ("INVC_ACTY_SNPSHT_FACT_VW6"."INVC_PPO_REDUC_AMT")
"C10",
SUM ("INVC_ACTY_SNPSHT_FACT_VW6"."INVC_DUP_REDUC_AMT")
"C11",
SUM ("INVC_ACTY_SNPSHT_FACT_VW6"."INVC_OSR_REDUC_AMT")
"C12",
( SUM (
"INVC_ACTY_SNPSHT_FACT_VW6"."INVC_CHRGS_AMT")
- SUM ("INVC_ACTY_SNPSHT_FACT_VW6"."INVC_ALWC_AMT"))
- SUM (
"INVC_ACTY_SNPSHT_FACT_VW6"."INVC_DUP_REDUC_AMT")
"C13",
SUM (
"INVC_ACTY_SNPSHT_FACT_VW6"."INVC_CLNT_SPEC_REDUC_AMT")
"C14"
FROM "CDW_DLV_IDS"."WCRS_POLICY_GROUPING_VW" "WCRS_POLICY_GROUPING_VW",
"WCRS_CLAIM_DETAIL_VW5",
"EDW_DM"."INVC_DIM_VW" "INVC_DIM_VW",
"EDW_DM"."PROVIDER_NETWORK_DIM_VW" "PROVIDER_NETWORK_DIM_VW",
"EDW_DM"."INVC_ACTY_SNPSHT_FACT_VW" "INVC_ACTY_SNPSHT_FACT_VW6",
"EDW_DM"."CURRENT_MED_INVC_RPT_DT_VW" "CURRENT_MED_INVC_RPT_DT_VW",
"EDW_DM"."ALL_INVC_SNPSHT_FACT_VW" "ALL_INVC_SNPSHT_FACT_VW",
"CDW_DLV_IDS"."WCRS_CURRENT_CLAIM_RPT_DT_VW" "WCRS_CURRENT_CLAIM_RPT_DT_VW",
"CDW_DLV_IDS"."WCRS_CLAIM_FACT_VW" "WCRS_CLAIM_FACT_VW",
"WCRS_POLICY_DETAIL_VW7",
"EDW_DM"."INVC_CLAIM_DTL_BRDG_FACT_VW" "INVC_CLAIM_DTL_BRDG_FACT_VW"
WHERE "INVC_DIM_VW"."INVC_DELETION_IND" <> 'Y'
AND "INVC_DIM_VW"."INVC_CONSIDRTN_TYPE_DESC" =
'Original'
AND "CURRENT_MED_INVC_RPT_DT_VW"."CURRENT_MONTH_RPT_DT" =
"ALL_INVC_SNPSHT_FACT_VW"."AS_OF_MONTH_END_DT_PK_ID"
AND "WCRS_CURRENT_CLAIM_RPT_DT_VW"."CURRENT_CLAIM_RPT_DT" =
"WCRS_CLAIM_FACT_VW"."CLAIM_REPORTING_DT"
AND "WCRS_POLICY_GROUPING_VW"."ACCOUNT_NM" =
CAST ('1ST TEAM STAFFING SERVICES, INC.' AS VARCHAR (50 CHAR))
AND "WCRS_POLICY_DETAIL_VW7"."POLICY_NBR" =
"WCRS_POLICY_GROUPING_VW"."POLICY_IDENTIFIER"
AND "WCRS_POLICY_DETAIL_VW7"."CLAIM_NBR" =
"WCRS_CLAIM_FACT_VW"."CLAIM_NBR"
AND "WCRS_POLICY_DETAIL_VW7"."CLAIM_SYMBOL_CD" =
"WCRS_CLAIM_FACT_VW"."CLAIM_SYMBOL_CD"
AND "WCRS_POLICY_DETAIL_VW7"."KEY_OFFICE_CD" =
"WCRS_CLAIM_FACT_VW"."KEY_OFFICE_CD"
AND "WCRS_POLICY_DETAIL_VW7"."CURRENT_SNAPSHOT_IND" =
'Y'
AND "WCRS_CLAIM_FACT_VW"."CLAIM_DETAIL_PK_ID" =
"WCRS_CLAIM_DETAIL_VW5"."CLAIM_DETAIL_PK_ID"
AND "WCRS_CLAIM_DETAIL_VW5"."CURRENT_SNAPSHOT_IND" =
'Y'
AND "WCRS_CLAIM_FACT_VW"."CLAIM_GID" =
"INVC_CLAIM_DTL_BRDG_FACT_VW"."CLM_GID"
AND "INVC_CLAIM_DTL_BRDG_FACT_VW"."INVC_GID" =
"INVC_DIM_VW"."INVC_GID"
AND "INVC_DIM_VW"."INVC_PK_ID" =
"INVC_ACTY_SNPSHT_FACT_VW6"."INVC_PK_ID"
AND "ALL_INVC_SNPSHT_FACT_VW"."MONTH_END_DT_PK_ID" =
"INVC_ACTY_SNPSHT_FACT_VW6"."MONTH_END_DT_PK_ID"
AND "ALL_INVC_SNPSHT_FACT_VW"."INVC_GID" =
"INVC_ACTY_SNPSHT_FACT_VW6"."INVC_GID"
AND "PROVIDER_NETWORK_DIM_VW"."PROVIDER_NETWORK_PK_ID" =
"INVC_ACTY_SNPSHT_FACT_VW6"."PPO_PROVIDER_NETWORK_PK_ID"
AND "WCRS_CURRENT_CLAIM_RPT_DT_VW"."CURRENT_CLAIM_RPT_DT" =
"WCRS_CLAIM_FACT_VW"."CLAIM_REPORTING_DT"
GROUP BY "WCRS_POLICY_GROUPING_VW"."ACCOUNT_NM",
"WCRS_CLAIM_DETAIL_VW5"."REGULATORY_STATE_CD",
CASE
WHEN "INVC_DIM_VW"."INVC_IN_OUT_OF_NETWORK_IND" =
'Y'
THEN
'In - Network'
WHEN "INVC_DIM_VW"."INVC_IN_OUT_OF_NETWORK_IND" =
'N'
THEN
'Out - Network'
ELSE
'Others'
END,
"PROVIDER_NETWORK_DIM_VW"."PROVIDER_NETWORK_NM",
"INVC_DIM_VW"."INVC_CLASS_TYPE_DESC",
CASE
WHEN (EXTRACT (
YEAR FROM ("WCRS_CLAIM_DETAIL_VW5"."LOSS_DT"))
IS NULL)
OR (EXTRACT (
MONTH FROM ("WCRS_CLAIM_DETAIL_VW5"."LOSS_DT"))
IS NULL)
THEN
NULL
ELSE
( EXTRACT (
YEAR FROM ("WCRS_CLAIM_DETAIL_VW5"."LOSS_DT"))
|| EXTRACT (
MONTH FROM ("WCRS_CLAIM_DETAIL_VW5"."LOSS_DT")))
END) "T1") "T0"
ORDER BY "Account_Name" ASC NULLS LAST,
"Accident_State_Cd" ASC NULLS LAST,
"c3" ASC NULLS LAST,
"PPO_Name" ASC NULLS LAST,
"Invc_Classification_Type_Desc" ASC NULLS LAST

| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 1 | 838 | 1079K (1)| 00:00:34 | | |
| 1 | TEMP TABLE TRANSFORMATION | | | | | | | |
| 2 | PX COORDINATOR | | | | | | | |
| 3 | PX SEND QC (RANDOM) | :TQ10000 | 10M| 317M| 848K (1)| 00:00:27 | | |
| 4 | LOAD AS SELECT | SYS_TEMP_0FD9D677A_286AAA2E | | | | | | |
| 5 | PX BLOCK ITERATOR | | 10M| 317M| 848K (1)| 00:00:27 | | |
|* 6 | TABLE ACCESS STORAGE FULL | WCRS_CLAIM_DETAIL | 10M| 317M| 848K (1)| 00:00:27 | | |
| 7 | PX COORDINATOR | | | | | | | |
| 8 | PX SEND QC (RANDOM) | :TQ20000 | 10M| 268M| 44875 (1)| 00:00:02 | | |
| 9 | LOAD AS SELECT | SYS_TEMP_0FD9D677B_286AAA2E | | | | | | |
| 10 | PX BLOCK ITERATOR | | 10M| 268M| 44875 (1)| 00:00:02 | | |
|* 11 | TABLE ACCESS STORAGE FULL | WCRS_POLICY_DETAIL | 10M| 268M| 44875 (1)| 00:00:02 | | |
| 12 | PX COORDINATOR | | | | | | | |
| 13 | PX SEND QC (ORDER) | :TQ40017 | 1 | 838 | 186K (2)| 00:00:06 | | |
| 14 | WINDOW SORT | | 1 | 838 | 186K (2)| 00:00:06 | | |
| 15 | PX RECEIVE | | 1 | 838 | 186K (2)| 00:00:06 | | |
| 16 | PX SEND RANGE | :TQ40016 | 1 | 838 | 186K (2)| 00:00:06 | | |
| 17 | NESTED LOOPS | | 1 | 838 | 186K (2)| 00:00:06 | | |
| 18 | BUFFER SORT | | | | | | | |
| 19 | PX RECEIVE | | | | | | | |
| 20 | PX SEND BROADCAST | :TQ40001 | | | | | | |
| 21 | VIEW | | 1 | 13 | 93216 (2)| 00:00:03 | | |
| 22 | SORT GROUP BY | | 1 | 393 | | | | |
| 23 | PX COORDINATOR | | | | | | | |
| 24 | PX SEND QC (RANDOM) | :TQ30015 | 1 | 393 | | | | |
| 25 | SORT GROUP BY | | 1 | 393 | | | | |
| 26 | PX RECEIVE | | 1 | 393 | | | | |
| 27 | PX SEND HASH | :TQ30014 | 1 | 393 | | | | |
| 28 | SORT GROUP BY | | 1 | 393 | | | | |
|* 29 | HASH JOIN ANTI | | 1 | 393 | 93216 (2)| 00:00:03 | | |
| 30 | PX RECEIVE | | 1 | 376 | 85197 (2)| 00:00:03 | | |
| 31 | PX SEND HASH | :TQ30012 | 1 | 376 | 85197 (2)| 00:00:03 | | |
| 32 | BUFFER SORT | | 1 | 838 | | | | |
| 33 | NESTED LOOPS | | 1 | 376 | 85197 (2)| 00:00:03 | | |
| 34 | NESTED LOOPS | | 1 | 358 | 85197 (2)| 00:00:03 | | |
| 35 | NESTED LOOPS | | 1 | 348 | 85197 (2)| 00:00:03 | | |
|* 36 | HASH JOIN ANTI | | 1 | 316 | 85179 (2)| 00:00:03 | | |
| 37 | PX RECEIVE | | 4 | 1156 | 77161 (2)| 00:00:03 | | |
| 38 | PX SEND HASH | :TQ30010 | 4 | 1156 | 77161 (2)| 00:00:03 | | |
|* 39 | HASH JOIN ANTI BUFFERED | | 4 | 1156 | 77161 (2)| 00:00:03 | | |
| 40 | PX RECEIVE | | 371 | 94605 | 69142 (2)| 00:00:03 | | |
| 41 | PX SEND HASH | :TQ30008 | 371 | 94605 | 69142 (2)| 00:00:03 | | |
|* 42 | HASH JOIN | | 371 | 94605 | 69142 (2)| 00:00:03 | | |
| 43 | PX RECEIVE | | 350 | 77000 | 36642 (1)| 00:00:02 | | |
| 44 | PX SEND BROADCAST | :TQ30007 | 350 | 77000 | 36642 (1)| 00:00:02 | | |
|* 45 | HASH JOIN | | 350 | 77000 | 36642 (1)| 00:00:02 | | |
| 46 | PX RECEIVE | | 140 | 25200 | 28624 (1)| 00:00:01 | | |
| 47 | PX SEND BROADCAST | :TQ30006 | 140 | 25200 | 28624 (1)| 00:00:01 | | |
|* 48 | HASH JOIN | | 140 | 25200 | 28624 (1)| 00:00:01 | | |
| 49 | PX RECEIVE | | 140 | 22820 | 25169 (1)| 00:00:01 | | |
| 50 | PX SEND BROADCAST | :TQ30005 | 140 | 22820 | 25169 (1)| 00:00:01 | | |
|* 51 | HASH JOIN BUFFERED | | 140 | 22820 | 25169 (1)| 00:00:01 | | |
| 52 | BUFFER SORT | | | | | | | |
| 53 | PX RECEIVE | | 9 | 306 | 5 (0)| 00:00:01 | | |
| 54 | T PX SEND BROADCAS | :TQ30000 | 9 | 306 | 5 (0)| 00:00:01 | | |
| 55 | INDEX ROWID TABLE ACCESS BY | WCRS_POLICY_GROUPING | 9 | 306 | 5 (0)| 00:00:01 | | |
|* 56 | AN INDEX RANGE SC | SUK3 | 9 | | 1 (0)| 00:00:01 | | |
|* 57 | HASH JOIN | | 9699K| 1193M| 25149 (1)| 00:00:01 | | |
| 58 | PX RECEIVE | | 9699K| 434M| 22205 (1)| 00:00:01 | | |
| 59 | PX SEND HASH | :TQ30003 | 9699K| 434M| 22205 (1)| 00:00:01 | | |
| 60 | NESTED LOOPS | | 9699K| 434M| 22205 (1)| 00:00:01 | | |
| 61 | BUFFER SORT | | | | | | | |
| 62 | PX RECEIVE | | | | | | | |
| 63 | DCAST PX SEND BROA | :TQ30002 | | | | | | |
| 64 | CARTESIAN MERGE JOIN | | 1 | 14 | 13 (0)| 00:00:01 | | |
| 65 | TERATOR PX BLOCK I | | 1 | 8 | 10 (0)| 00:00:01 | | |
| 66 | ESS STORAGE FULL TABLE ACC | CURRENT_MED_INVC_RPT_DT | 1 | 8 | 10 (0)| 00:00:01 | | |
| 67 | T BUFFER SOR | | 1 | 6 | 3 (0)| 00:00:01 | | |
| 68 | E PX RECEIV | | 1 | 6 | 2 (0)| 00:00:01 | | |
| 69 | BROADCAST PX SEND | :TQ30001 | 1 | 6 | 2 (0)| 00:00:01 | | |
| 70 | K ITERATOR PX BLOC | | 1 | 6 | 2 (0)| 00:00:01 | | |
| 71 | ACCESS STORAGE FULL TABLE | WCRS_CURRENT_CLAIM_RPT_DT | 1 | 6 | 2 (0)| 00:00:01 | | |
| 72 | TOR PX BLOCK ITERA | | 9699K| 305M| 22192 (1)| 00:00:01 | KEY | KEY |
|* 73 | STORAGE FULL TABLE ACCESS | WCRS_CURRENT_CLAIM_FACT | 9699K| 305M| 22192 (1)| 00:00:01 | KEY | KEY |
| 74 | PX RECEIVE | | 10M| 785M| 2907 (2)| 00:00:01 | | |
| 75 | PX SEND HASH | :TQ30004 | 10M| 785M| 2907 (2)| 00:00:01 | | |
|* 76 | VIEW | | 10M| 785M| 2907 (2)| 00:00:01 | | |
| 77 | TOR PX BLOCK ITERA | | 10M| 268M| 2907 (2)| 00:00:01 | | |
| 78 | STORAGE FULL TABLE ACCESS | SYS_TEMP_0FD9D677B_286AAA2E | 10M| 268M| 2907 (2)| 00:00:01 | | |
|* 79 | VIEW | | 10M| 168M| 3439 (2)| 00:00:01 | | |
| 80 | PX BLOCK ITERATOR | | 10M| 317M| 3439 (2)| 00:00:01 | | |
| 81 | E FULL TABLE ACCESS STORAG | SYS_TEMP_0FD9D677A_286AAA2E | 10M| 317M| 3439 (2)| 00:00:01 | | |
| 82 | PX BLOCK ITERATOR | | 15M| 599M| 7994 (1)| 00:00:01 | | |
| 83 | LL TABLE ACCESS STORAGE FU | INVC_CLAIM_DTL_BRDG_FACT | 15M| 599M| 7994 (1)| 00:00:01 | | |
| 84 | PX BLOCK ITERATOR | | 15M| 521M| 32477 (2)| 00:00:02 | | |
|* 85 | TABLE ACCESS STORAGE FULL | INVC_DIM | 15M| 521M| 32477 (2)| 00:00:02 | | |
| 86 | PX RECEIVE | | 15M| 509M| 7994 (1)| 00:00:01 | | |
| 87 | PX SEND HASH | :TQ30009 | 15M| 509M| 7994 (1)| 00:00:01 | | |
| 88 | PX BLOCK ITERATOR | | 15M| 509M| 7994 (1)| 00:00:01 | | |
| 89 | TABLE ACCESS STORAGE FULL | INVC_CLAIM_DTL_BRDG_FACT | 15M| 509M| 7994 (1)| 00:00:01 | | |
| 90 | PX RECEIVE | | 15M| 404M| 7994 (1)| 00:00:01 | | |
| 91 | PX SEND HASH | :TQ30011 | 15M| 404M| 7994 (1)| 00:00:01 | | |
| 92 | PX BLOCK ITERATOR | | 15M| 404M| 7994 (1)| 00:00:01 | | |
| 93 | TABLE ACCESS STORAGE FULL | INVC_CLAIM_DTL_BRDG_FACT | 15M| 404M| 7994 (1)| 00:00:01 | | |
| 94 | TABLE ACCESS BY INDEX ROWID | INVC_ACTY_SNPSHT_FACT | 1 | 32 | 18 (0)| 00:00:01 | | |
|* 95 | INDEX RANGE SCAN | IFK_XPKINVOICE_ACTIVITY_SNAPSH | 1 | | 1 (0)| 00:00:01 | | |
|* 96 | INDEX UNIQUE SCAN | IFK_XPKPROVIDER_NETWORK_DIM | 1 | 10 | 0 (0)| 00:00:01 | | |
|* 97 | INDEX RANGE SCAN | IFK_XPKALL_INVC_SNPSHT_FACT | 1 | 18 | 1 (0)| 00:00:01 | | |
| 98 | PX RECEIVE | | 15M| 254M| 7994 (1)| 00:00:01 | | |
| 99 | PX SEND HASH | :TQ30013 | 15M| 254M| 7994 (1)| 00:00:01 | | |
| 100 | PX BLOCK ITERATOR | | 15M| 254M| 7994 (1)| 00:00:01 | | |
| 101 | TABLE ACCESS STORAGE FULL | INVC_CLAIM_DTL_BRDG_FACT | 15M| 254M| 7994 (1)| 00:00:01 | | |
| 102 | VIEW | | 1 | 825 | | | | |
| 103 | SORT GROUP BY | | 1 | 430 | 93216 (2)| 00:00:03 | | |
| 104 | BUFFER SORT | | | | | | | |
| 105 | PX RECEIVE | | 1 | 430 | 93216 (2)| 00:00:03 | | |
| 106 | PX SEND HASH | :TQ40015 | 1 | 430 | 93216 (2)| 00:00:03 | | |
|*107 | HASH JOIN ANTI BUFFERED | | 1 | 430 | 93216 (2)| 00:00:03 | | |
| 108 | PX RECEIVE | | 1 | 413 | 85198 (2)| 00:00:03 | | |
| 109 | PX SEND HASH | :TQ40013 | 1 | 413 | 85198 (2)| 00:00:03 | | |
| 110 | BUFFER SORT | | 1 | 838 | | | | |
| 111 | NESTED LOOPS | | 1 | 413 | 85198 (2)| 00:00:03 | | |
| 112 | NESTED LOOPS | | 1 | 395 | 85197 (2)| 00:00:03 | | |
| 113 | NESTED LOOPS | | 1 | 369 | 85197 (2)| 00:00:03 | | |
|*114 | HASH JOIN ANTI | | 1 | 311 | 85179 (2)| 00:00:03 | | |
| 115 | PX RECEIVE | | 4 | 1136 | 77161 (2)| 00:00:03 | | |
| 116 | PX SEND HASH | :TQ40011 | 4 | 1136 | 77161 (2)| 00:00:03 | | |
|*117 | HASH JOIN ANTI BUFFERED | | 4 | 1136 | 77161 (2)| 00:00:03 | | |
| 118 | PX RECEIVE | | 371 | 92750 | 69143 (2)| 00:00:03 | | |
| 119 | PX SEND HASH | :TQ40009 | 371 | 92750 | 69143 (2)| 00:00:03 | | |
|*120 | HASH JOIN | | 371 | 92750 | 69143 (2)| 00:00:03 | | |
| 121 | PX RECEIVE | | 350 | 72450 | 36642 (1)| 00:00:02 | | |
| 122 | PX SEND BROADCAST | :TQ40008 | 350 | 72450 | 36642 (1)| 00:00:02 | | |
|*123 | HASH JOIN | | 350 | 72450 | 36642 (1)| 00:00:02 | | |
| 124 | PX RECEIVE | | 140 | 23380 | 28624 (1)| 00:00:01 | | |
| 125 | PX SEND BROADCAST | :TQ40007 | 140 | 23380 | 28624 (1)| 00:00:01 | | |
|*126 | HASH JOIN | | 140 | 23380 | 28624 (1)| 00:00:01 | | |
| 127 | PX RECEIVE | | 140 | 15540 | 25169 (1)| 00:00:01 | | |
| 128 | PX SEND BROADCAST | :TQ40006 | 140 | 15540 | 25169 (1)| 00:00:01 | | |
|*129 | HASH JOIN BUFFERED | | 140 | 15540 | 25169 (1)| 00:00:01 | | |
| 130 | BUFFER SORT | | | | | | | |
| 131 | PX RECEIVE | | 9 | 306 | 5 (0)| 00:00:01 | | |
| 132 | PX SEND BROADCAST | :TQ40000 | 9 | 306 | 5 (0)| 00:00:01 | | |
| 133 | ROWID TABLE ACCESS BY INDEX | WCRS_POLICY_GROUPING | 9 | 306 | 5 (0)| 00:00:01 | | |
|*134 | INDEX RANGE SCAN | SUK3 | 9 | | 1 (0)| 00:00:01 | | |
|*135 | HASH JOIN | | 9699K| 712M| 25149 (1)| 00:00:01 | | |
| 136 | PX RECEIVE | | 10M| 287M| 2907 (2)| 00:00:01 | | |
| 137 | PX SEND HASH | :TQ40004 | 10M| 287M| 2907 (2)| 00:00:01 | | |
|*138 | VIEW | | 10M| 287M| 2907 (2)| 00:00:01 | | |
| 139 | PX BLOCK ITERATOR | | 10M| 268M| 2907 (2)| 00:00:01 | | |
| 140 | E FULL TABLE ACCESS STORAG | SYS_TEMP_0FD9D677B_286AAA2E | 10M| 268M| 2907 (2)| 00:00:01 | | |
| 141 | PX RECEIVE | | 9699K| 434M| 22205 (1)| 00:00:01 | | |
| 142 | PX SEND HASH | :TQ40005 | 9699K| 434M| 22205 (1)| 00:00:01 | | |
| 143 | NESTED LOOPS | | 9699K| 434M| 22205 (1)| 00:00:01 | | |
| 144 | BUFFER SORT | | | | | | | |
| 145 | PX RECEIVE | | | | | | | |
| 146 | PX SEND BROADCAST | :TQ40003 | | | | | | |
| 147 | IAN MERGE JOIN CARTES | | 1 | 14 | 13 (0)| 00:00:01 | | |
| 148 | R PX BLOCK ITERATO | | 1 | 8 | 10 (0)| 00:00:01 | | |
| 149 | ORAGE FULL TABLE ACCESS ST | CURRENT_MED_INVC_RPT_DT | 1 | 8 | 10 (0)| 00:00:01 | | |
| 150 | BUFFER SORT | | 1 | 6 | 3 (0)| 00:00:01 | | |
| 151 | PX RECEIVE | | 1 | 6 | 2 (0)| 00:00:01 | | |
| 152 | AST PX SEND BROADC | :TQ40002 | 1 | 6 | 2 (0)| 00:00:01 | | |
| 153 | ATOR PX BLOCK ITER | | 1 | 6 | 2 (0)| 00:00:01 | | |
| 154 | STORAGE FULL TABLE ACCESS | WCRS_CURRENT_CLAIM_RPT_DT | 1 | 6 | 2 (0)| 00:00:01 | | |
| 155 | PX BLOCK ITERATOR | | 9699K| 305M| 22192 (1)| 00:00:01 | KEY | KEY |
|*156 | E FULL TABLE ACCESS STORAG | WCRS_CURRENT_CLAIM_FACT | 9699K| 305M| 22192 (1)| 00:00:01 | KEY | KEY |
|*157 | VIEW | | 10M| 555M| 3439 (2)| 00:00:01 | | |
| 158 | PX BLOCK ITERATOR | | 10M| 317M| 3439 (2)| 00:00:01 | | |
| 159 | TABLE ACCESS STORAGE FULL | SYS_TEMP_0FD9D677A_286AAA2E | 10M| 317M| 3439 (2)| 00:00:01 | | |
| 160 | PX BLOCK ITERATOR | | 15M| 599M| 7994 (1)| 00:00:01 | | |
| 161 | TABLE ACCESS STORAGE FULL | INVC_CLAIM_DTL_BRDG_FACT | 15M| 599M| 7994 (1)| 00:00:01 | | |
| 162 | PX BLOCK ITERATOR | | 15M| 641M| 32477 (2)| 00:00:02 | | |
|*163 | TABLE ACCESS STORAGE FULL | INVC_DIM | 15M| 641M| 32477 (2)| 00:00:02 | | |
| 164 | PX RECEIVE | | 15M| 509M| 7994 (1)| 00:00:01 | | |
| 165 | PX SEND HASH | :TQ40010 | 15M| 509M| 7994 (1)| 00:00:01 | | |
| 166 | PX BLOCK ITERATOR | | 15M| 509M| 7994 (1)| 00:00:01 | | |
| 167 | TABLE ACCESS STORAGE FULL | INVC_CLAIM_DTL_BRDG_FACT | 15M| 509M| 7994 (1)| 00:00:01 | | |
| 168 | PX RECEIVE | | 15M| 404M| 7994 (1)| 00:00:01 | | |
| 169 | PX SEND HASH | :TQ40012 | 15M| 404M| 7994 (1)| 00:00:01 | | |
| 170 | PX BLOCK ITERATOR | | 15M| 404M| 7994 (1)| 00:00:01 | | |
| 171 | TABLE ACCESS STORAGE FULL | INVC_CLAIM_DTL_BRDG_FACT | 15M| 404M| 7994 (1)| 00:00:01 | | |
| 172 | TABLE ACCESS BY INDEX ROWID | INVC_ACTY_SNPSHT_FACT | 1 | 58 | 18 (0)| 00:00:01 | | |
|*173 | INDEX RANGE SCAN | IFK_XPKINVOICE_ACTIVITY_SNAPSH | 1 | | 1 (0)| 00:00:01 | | |
| 174 | TABLE ACCESS BY INDEX ROWID | PROVIDER_NETWORK_DIM | 1 | 26 | 0 (0)| 00:00:01 | | |
|*175 | INDEX UNIQUE SCAN | IFK_XPKPROVIDER_NETWORK_DIM | 1 | | 0 (0)| 00:00:01 | | |
|*176 | INDEX RANGE SCAN | IFK_XPKALL_INVC_SNPSHT_FACT | 1 | 18 | 1 (0)| 00:00:01 | | |
| 177 | PX RECEIVE | | 15M| 254M| 7994 (1)| 00:00:01 | | |
| 178 | PX SEND HASH | :TQ40014 | 15M| 254M| 7994 (1)| 00:00:01 | | |
| 179 | PX BLOCK ITERATOR | | 15M| 254M| 7994 (1)| 00:00:01 | | |
| 180 | TABLE ACCESS STORAGE FULL | INVC_CLAIM_DTL_BRDG_FACT | 15M| 254M| 7994 (1)| 00:00:01 | | |
---------------------------------------------------------------------------------------------------------------------------------------------------------------

Similar Messages

  • Need help in SQL tuning

    I created apackage to
    1) Explode BOM model based on Demand data
    2) Save into temp table
    3) Adding additional info from original records
    This involves 400,000 + records and before this it tooks around 3-4 hours
    but now it seems running forever. Please help me to tune this
    CREATE OR REPLACE PACKAGE ZZ_SCHEDULED_BOMEXPLODE
    AS
    PROCEDURE main (
    errbuf OUT VARCHAR2,
    retcode OUT VARCHAR2--,
    END ZZ_SCHEDULED_BOMEXPLODE;
    CREATE OR REPLACE PACKAGE BODY ZZ_SCHEDULED_BOMEXPLODE
    AS
    PROCEDURE main (
    errbuf OUT VARCHAR2,
    retcode OUT VARCHAR2--,
    IS     
    v_explodemodel      VARCHAR2(30);
    v_explodemodel_id NUMBER;
    v_plan_id          NUMBER;
    v_qty_rate          NUMBER;
    v_mrp_date     DATE;
    v_comp_id          NUMBER;
    v_item_cost     NUMBER;
    l_assembly_item_id      NUMBER;
    l_organization_id      NUMBER      := 101;
    l_group_id           NUMBER      := -1111;
    l_session_id     NUMBER      := -1111;
    l_levels_to_explode      NUMBER     := 60;
    l_revision_date      DATE          := null;
    l_err_msg           VARCHAR2(80);
    l_err_code      NUMBER;
    CURSOR c_isp_models IS
    SELECT DISTINCT mov.ITEM_SEGMENTS,mov.PLAN_ID, sum(mov.QUANTITY_RATE), trunc(mov.CREATION_DATE)
    FROM MSC_ORDERS_V mov,msc_plans mp
    WHERE mov.ORDER_TYPE_TEXT IN ('Manual MDS')
    AND mov.CATEGORY_SET_ID = 13
    AND mov.PLAN_ID in (66,366,387,406,587,288)
    and mov.quantity_rate <> 0
    and mov.order_number='MDS_MRP'
    and mov.PLAN_ID = mp.PLAN_ID
    GROUP BY mov.ITEM_SEGMENTS, mov.PLAN_ID, trunc(mov.CREATION_DATE);
    CURSOR c_frozen_cost IS
    select msi.inventory_item_id, cic.item_cost from cst_item_costs cic, mtl_system_items_b msi
    where msi.organization_id = 101
    and cic.cost_type_id = 1
    and msi.inventory_item_id in (select distinct(component_item_id) from zz_bom_explosion_temp_save)
    and cic.organization_id = msi.organization_id
    and cic.inventory_item_id = msi.inventory_item_id;
    BEGIN
    EXECUTE IMMEDIATE 'drop table APPS.ZZ_BOM_EXPLOSION_TEMP_SAVE';
    EXECUTE IMMEDIATE 'create table APPS.ZZ_BOM_EXPLOSION_TEMP_SAVE as select * from APPS.BOM_EXPLOSION_TEMP';
    EXECUTE IMMEDIATE 'delete from APPS.ZZ_BOM_EXPLOSION_TEMP_SAVE';
    EXECUTE IMMEDIATE 'alter table APPS.ZZ_BOM_EXPLOSION_TEMP_SAVE add(PLAN_ID NUMBER, QTY_RATE NUMBER, MRP_DATE DATE)';
    COMMIT;
    -- Starting Explosion prosess
    OPEN c_isp_models;
    LOOP
    FETCH c_isp_models INTO v_explodemodel, v_plan_id, v_qty_rate, v_mrp_date; -- Updated on 2nd Mar 2007
    --FETCH c_isp_models INTO v_explodemodel;
    EXIT WHEN c_isp_models%NOTFOUND;
    select inventory_item_id into v_explodemodel_id
    from mtl_system_items_b
    where segment1 = v_explodemodel
    and organization_id = l_organization_id;
    fnd_file.put_line (fnd_file.LOG, v_explodemodel);
    select bom_explosion_temp_s.nextval into l_group_id from dual;
    bompexpl.exploder_userexit
    0,
    l_organization_id,
    1,
    l_group_id,
    l_session_id,
    l_levels_to_explode,
    1,
    1,
    2,
    3,
    2,
    1,
    2,
    1,
    v_explodemodel_id,
    l_revision_date,
    l_err_msg,
    l_err_code
    COMMIT;
    insert into ZZ_BOM_EXPLOSION_TEMP_SAVE
    select
    TOP_BILL_SEQUENCE_ID,
    BILL_SEQUENCE_ID,
    ORGANIZATION_ID,
    COMPONENT_SEQUENCE_ID,
    COMPONENT_ITEM_ID,
    PLAN_LEVEL,
    EXTENDED_QUANTITY,
    SORT_ORDER,
    REQUEST_ID,
    PROGRAM_APPLICATION_ID,
    PROGRAM_ID,
    PROGRAM_UPDATE_DATE,
    GROUP_ID,
    SESSION_ID,
    SELECT_FLAG,
    SELECT_QUANTITY,
    EXTEND_COST_FLAG,
    TOP_ALTERNATE_DESIGNATOR,
    TOP_ITEM_ID,
    CONTEXT,
    ATTRIBUTE1,
    ATTRIBUTE2,
    ATTRIBUTE3,
    ATTRIBUTE4,
    ATTRIBUTE5,
    ATTRIBUTE6,
    ATTRIBUTE7,
    ATTRIBUTE8,
    ATTRIBUTE9,
    ATTRIBUTE10,
    ATTRIBUTE11,
    ATTRIBUTE12,
    ATTRIBUTE13,
    ATTRIBUTE14,
    ATTRIBUTE15,
    HEADER_ID,
    LINE_ID,
    LIST_PRICE,
    SELLING_PRICE,
    COMPONENT_YIELD_FACTOR,
    ITEM_COST,
    INCLUDE_IN_ROLLUP_FLAG,
    BASED_ON_ROLLUP_FLAG,
    ACTUAL_COST_TYPE_ID,
    COMPONENT_QUANTITY,
    SHRINKAGE_RATE,
    SO_BASIS,
    OPTIONAL,
    MUTUALLY_EXCLUSIVE_OPTIONS,
    CHECK_ATP,
    SHIPPING_ALLOWED,
    REQUIRED_TO_SHIP,
    REQUIRED_FOR_REVENUE,
    INCLUDE_ON_SHIP_DOCS,
    INCLUDE_ON_BILL_DOCS,
    LOW_QUANTITY,
    HIGH_QUANTITY,
    PICK_COMPONENTS,
    PRIMARY_UOM_CODE,
    PRIMARY_UNIT_OF_MEASURE,
    BASE_ITEM_ID,
    ATP_COMPONENTS_FLAG,
    ATP_FLAG,
    BOM_ITEM_TYPE,
    PICK_COMPONENTS_FLAG,
    REPLENISH_TO_ORDER_FLAG,
    SHIPPABLE_ITEM_FLAG,
    CUSTOMER_ORDER_FLAG,
    INTERNAL_ORDER_FLAG,
    CUSTOMER_ORDER_ENABLED_FLAG,
    INTERNAL_ORDER_ENABLED_FLAG,
    SO_TRANSACTIONS_FLAG,
    MTL_TRANSACTIONS_ENABLED_FLAG,
    STOCK_ENABLED_FLAG,
    DESCRIPTION,
    ASSEMBLY_ITEM_ID,
    CONFIGURATOR_FLAG,
    PRICE_LIST_ID,
    ROUNDING_FACTOR,
    PRICING_CONTEXT,
    PRICING_ATTRIBUTE1,
    PRICING_ATTRIBUTE2,
    PRICING_ATTRIBUTE3,
    PRICING_ATTRIBUTE4,
    PRICING_ATTRIBUTE5,
    PRICING_ATTRIBUTE6,
    PRICING_ATTRIBUTE7,
    PRICING_ATTRIBUTE8,
    PRICING_ATTRIBUTE9,
    PRICING_ATTRIBUTE10,
    PRICING_ATTRIBUTE11,
    PRICING_ATTRIBUTE12,
    PRICING_ATTRIBUTE13,
    PRICING_ATTRIBUTE14,
    PRICING_ATTRIBUTE15,
    COMPONENT_CODE,
    LOOP_FLAG,
    INVENTORY_ASSET_FLAG,
    PLANNING_FACTOR,
    OPERATION_SEQ_NUM,
    PARENT_BOM_ITEM_TYPE,
    WIP_SUPPLY_TYPE,
    ITEM_NUM,
    EFFECTIVITY_DATE,
    DISABLE_DATE,
    IMPLEMENTATION_DATE,
    SUPPLY_SUBINVENTORY,
    SUPPLY_LOCATOR_ID,
    COMPONENT_REMARKS,
    CHANGE_NOTICE,
    OPERATION_LEAD_TIME_PERCENT,
    REXPLODE_FLAG,
    COMMON_BILL_SEQUENCE_ID,
    PRIMARY_PATH_FLAG,
    AUTO_REQUEST_MATERIAL,
    v_plan_id,
    v_qty_rate,
    v_mrp_date
    from BOM_EXPLOSION_TEMP;
    delete from BOM_EXPLOSION_TEMP;
    commit;
    END LOOP;
    CLOSE c_isp_models;
    --insert into ZZ_BOM_EXPLOSION_TEMP_SAVE select * from BOM_EXPLOSION_TEMP;
    COMMIT;
    -- Ending of Explosion proxess
    -- Updated on 5th Mar 2007 to populate missing frozen item cost
    OPEN c_frozen_cost;
    LOOP
    FETCH c_frozen_cost INTO v_comp_id, v_item_cost;
    EXIT WHEN c_frozen_cost%NOTFOUND;
    update zz_bom_explosion_temp_save
    set item_cost = v_item_cost
    where component_item_id = v_comp_id;
    commit;
    END LOOP;
    CLOSE c_frozen_cost;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    DBMS_OUTPUT.PUT_LINE('No_data_found');
    WHEN UTL_FILE.INVALID_PATH THEN
    DBMS_OUTPUT.PUT_LINE('UTL_FILE.INVALID_PATH');
    WHEN UTL_FILE.READ_ERROR THEN
    DBMS_OUTPUT.PUT_LINE('UTL_FILE.READ_ERROR');
    WHEN UTL_FILE.WRITE_ERROR THEN
    DBMS_OUTPUT.PUT_LINE('UTL_FILE.WRITE_ERROR');
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Other stuff');
    END main;
    END ZZ_SCHEDULED_BOMEXPLODE;
    /

    Statistics have been updated? Any missing indices? Any explain plans / tkprof outputs on this one?
    Why don't you put
    select inventory_item_id into v_explodemodel_id
    from mtl_system_items_b
    where segment1 = v_explodemodel
    and organization_id = l_organization_id;inside c_isp_models?
    BULK processing that cursor could also be an option.
    Those were the thoughts that came up first when I saw your code.
    C.

  • Need help with SQL Query with Inline View + Group by

    Hello Gurus,
    I would really appreciate your time and effort regarding this query. I have the following data set.
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
    1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
    Please Ignore '----', added it for clarity
    I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
    The query should return the following data set
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
    The following is my query. I am kind of lost.
    select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    from (
    select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
    from INVOICE
    group by sequence_id,check_date, check_number, invoice_number, vendor_number
    ) A, INVOICE B
    where A.sequence_id = B.sequence_id
    Thanks,
    Nick

    It looks like it is a duplicate thread - correct me if i'm wrong in this case ->
    Need help with SQL Query with Inline View + Group by
    Regards.
    Satyaki De.

  • Need help in SQL (DENSE_RANK) function

    Hello All,
    I need the help in SQL.
    We have a table called status and the column are
    status_id number
    account_id number
    status_cd varchar2(10)
    created_id varchar2(10)
    created_by date
    and data is as follows
    insert into status values (1,101,'ENTER','ABC',to_date('21-JAN-2007 11:15:14','DD-MON-YYYY HH:MI:SS'));
    insert into status values (2,101,'REVIEW','DEF',to_date('21-JAN-2007 11:30:25','DD-MON-YYYY HH:MI:SS'));
    insert into status values (3,101,'APPROVE','GHI',to_date('21-JAN-2007 11:30:25','DD-MON-YYYY HH:MI:SS'));
    insert into status values (4,102,'ENTER','ABC',to_date('21-JAN-2007 11:18:14','DD-MON-YYYY HH:MI:SS'));
    insert into status values (5,102,'REVIEW','DEF',to_date('21-JAN-2007 11:33:25','DD-MON-YYYY HH:MI:SS'));
    insert into status values (6,102,'CANCEL','GHI',to_date('21-JAN-2007 11:33:25','DD-MON-YYYY HH:MI:SS'));
    insert into status values (7,103,'ENTER','ABC',to_date('21-JAN-2007 11:21:14','DD-MON-YYYY HH:MI:SS'));We have different status as follows
    1. ENTER
    2. REVIEW
    3. APPROVE
    4. CANCEL
    5. REJECT
    My requirement ..
    I need the max of created_id column for the status in ('APPROVE','CANCEL') and if there is no status in ('APPROVE','REVIEW') than it should be NULL.
    I wrote an SQL as
    select account_id,max(created_id) keep (dense_rank first order by decode(status_cd,'APPROVE',created_dt,'REVIEW',created_dt,NULL) DESC NULLS LAST,
          decode(status_cd,'APPROVE',status_id,'REVIEW',status_id,NULL) DESC NULLS LAST) last_app_rev_user
    from status
    group by account_id and gives me the output like
    ACCOUNT_ID LAST_APP_R
           101 GHI
           102 DEF
           103 ABCBut I want the Output like
    ACCOUNT_ID LAST_APP_R
           101 GHI
           102 DEF
           103 NULLAs the account 103 has no status called 'REVIEW' and 'APPROVE'
    My DB Version in 10.2.0.3.0.
    Hope I explain it properly. And if you have any other option without dense_rank still i will be happy.
    Thanks in advance for your help.
    AB
    null
    Message was edited by:
    AB

    instead of max(created_id) keep... use
    smth like max(case when status_cd in ('APPROVE','REVIEW') then created_id end) keep...

  • NEED HELP IN SQL HOMEWORK PROBLEMS

    I NEED HELP IN MY SQL HOMEWORK PROBLEMS....
    I CAN SEND IT VIA EMAIL ATTACHMENT IN MSWORD....

    Try this:
    SELECT SUBSTR( TN,
                   DECODE(LEVEL, 1, 1, INSTR(TN, '#', 1, LEVEL-1) + 1),
                   DECODE( INSTR(TN, '#', 1, LEVEL) , 0 ,
                           LENGTH(TN) + 1, INSTR(TN, '#', 1, LEVEL) )
                   - DECODE(LEVEL, 1, 1, INSTR(TN, '#', 1, LEVEL-1 ) + 1)
           ) xxx
    FROM (
        SELECT '234123#1254343#909823#908232#12345' TN FROM DUAL
    CONNECT BY LEVEL <= LENGTH(TN) - LENGTH(REPLACE(TN,'#')) + 1
    XXX                               
    234123                            
    1254343                           
    909823                            
    908232                            
    12345
    SELECT regexp_substr(tn, '[^#]+', 1, level) xx
    FROM (
        SELECT '234123#1254343#909823#908232#12345' TN FROM DUAL
    CONNECT BY LEVEL <= LENGTH(TN) - LENGTH(REPLACE(TN,'#')) + 1
    XX                                
    234123                            
    1254343                           
    909823                            
    908232                            
    12345 

  • Help on SQL tuning

    SQL is behaving different for different inputs. Its taking 20mins to execute when oraganization_id=382 is passed adn with other organization_id's are passed it is taking less than 2 minutes. Execution plan is different in both the cases. I will provide bith sql and execution plans.
    I tried rebuilding the indexes and gather stats for the tables but it did not help out.
    Please help me in tuning the sql.
    1) SQL
    SELECT DISTINCT mp . organization_name , mp . organization_code , mp .
    organization_name , wpsv . pick_slip_number , wpsv .
    from
    subinventory , csu . location shipto_location , wpsv . from_locator_id ,
    wpsv . to_subinventory , wpsv . to_locator_id , mtrh . request_number
    mo_number , wpsv . detailing_date , mtrl . line_id mo_line_id , wpsv .
    transaction_id , wdd . move_order_line_id , to_char ( wdd .
    source_header_id ) order_n_header_char , to_char ( wdd . source_line_id )
    order_n_line_char , wdd . source_header_id , wdd . source_line_id , mtrl .
    line_number mo_line_number , wtr . trip_id , wtr . name rip_name , wnd .
    delivery_id , wnd . name delivery_name , wdd . shipping_instructions , wdd
    . packing_instructions , r . customer_name , wdd . source_header_number ,
    ol . line_number sales_line_number , ol . schedule_ship_date , sum ( NVL (
    wdd . requested_quantity , 0 ) ) requested_quantity , sum ( NVL ( wdd .
    requested_quantity2 , 0 ) ) requested_quantity2 , sum ( NVL ( wdd .
    shipped_quantity , 0 ) ) shipped_quantity , sum ( NVL ( wdd .
    shipped_quantity2 , 0 ) ) shipped_quantity2 , wdd . ship_tolerance_above ,
    wdd . ship_tolerance_below , msi.description item_info , msi . segment1 ,
    msi . description item_description , wdd . inventory_item_id , os .
    set_name , wdd . requested_quantity_uom , wdd . requested_quantity_uom2 ,
    wpsv . transaction_id , wpsv . line_status , wdd . revision , wpsv .
    primary_qty , wpsv . trans_um1 , wpsv . secondary_qty , wpsv . trans_um2 ,
    wpsv . qc_grade , wpsv . lot_id , wpsv . lot_no lot_number , iim .
    attribute19 min_max_stor_temp , wpsv . location , SUBSTR ( wpsv . location ,
    1 , 3 ) lot_location_group FROM IC_ITEM_MST_B iim , WSH_TRIPS wtr ,
    WSH_TRIP_STOPS wts , WSH_DELIVERY_LEGS wlg , WSH_NEW_DELIVERIES wnd ,
    WSH_DELIVERY_ASSIGNMENTS wda , WSH_DELIVERY_DETAILS wdd ,
    GMI_WSH_PICK_SLIP_V wpsv , OE_ORDER_LINES_ALL ol , OE_SETS os ,
    RA_CUSTOMERS r , IC_TXN_REQUEST_HEADERS mtrh , IC_TXN_REQUEST_LINES mtrl ,
    MTL_SYSTEM_ITEMS msi , HZ_CUST_SITE_USES_ALL csu , OE_ORDER_HEADERS_ALL ooh
    , ( SELECT mp . organization_id , mp . organization_code , hou . name
    organization_name FROM HR_ORGANIZATION_UNITS hou , MTL_PARAMETERS mp where
    mp . organization_id = hou . organization_id ) mp WHERE wtr.trip_id (+) =
    wts.trip_id AND wts.stop_id (+) = wlg.pick_up_stop_id AND wlg.delivery_id
    (+) = wnd.delivery_id AND wnd.delivery_id (+) = wda.delivery_id AND
    wdd.source_header_id = ooh.header_id AND csu.site_use_id =
    ooh.ship_to_org_id AND os.set_id (+) = wdd.ship_set_id AND
    wda.delivery_detail_id = wdd.delivery_detail_id AND ol.line_id =
    wdd.source_line_id AND wpsv.transaction_id = ol.line_id AND
    wpsv.transaction_id = wdd.source_line_id AND r.customer_id =
    wdd.customer_id AND mtrl.header_id = mtrh.header_id AND mtrl.line_id =
    wdd.move_order_line_id AND mtrl.inventory_item_id = wpsv.inventory_item_id
    AND mtrl.line_id = wpsv.move_order_line_id AND msi.inventory_item_id =
    wdd.inventory_item_id AND msi.organization_id = mtrl.organization_id AND
    iim.item_no = msi.segment1 AND mtrl.organization_id = : p_organization_id
    AND mtrl.organization_id = mp.organization_id and mtrh.request_number
    between : p_move_order_low and : p_move_order_high and wpsv.line_status =
    'UNPICKED' GROUP BY mp.organization_name , mp.organization_code ,
    csu.location , wpsv.pick_slip_number , wpsv.from_subinventory ,
    wpsv.from_locator_id , wpsv.to_subinventory , wpsv.to_locator_id ,
    mtrh.request_number , wpsv.detailing_date , mtrl.line_id ,
    wpsv.transaction_id , wdd.move_order_line_id , to_char (
    wdd.source_header_id ) , to_char ( wdd.source_line_id ) ,
    wdd.source_header_id , wdd.source_line_id , mtrl.line_number , wtr.trip_id ,
    wtr.name , wnd.delivery_id , wnd.name , wdd.shipping_instructions ,
    wdd.packing_instructions , r.customer_name , wdd.source_header_number ,
    ol.line_number , ol.schedule_ship_date , wdd.ship_tolerance_above ,
    wdd.ship_tolerance_below , msi.description , msi.segment1 , msi.description
    , wdd.inventory_item_id , os.set_name , wdd.requested_quantity_uom ,
    wdd.requested_quantity_uom2 , wpsv.transaction_id , wpsv.line_status ,
    wdd.revision , wpsv.primary_qty , wpsv.trans_um1 , wpsv.secondary_qty ,
    wpsv.trans_um2 , wpsv.qc_grade , wpsv.lot_id , wpsv.lot_no ,
    iim.attribute19 , wpsv.location , SUBSTR ( wpsv.location , 1 , 3 ) ORDER BY
    1 ASC,2 ASC,10 ASC,6 ASC,4 ASC,17 ASC,5 ASC,7 ASC,8 ASC,9 ASC,13 ASC,12 ASC,
    55 ASC,43 ASC,14 ASC,19 ASC,18 ASC,39 ASC,53 ASC,29 ASC,36 ASC,37 ASC,38
    ASC,30 ASC,41 ASC,31 ASC,42 ASC,40 ASC,33 ASC,34 ASC,35 ASC,27 ASC,28 ASC,
    20 ASC,21 ASC,22 ASC,23 ASC,26 ASC,24 ASC,25 ASC , mp.organization_code ,
    mo_number , pick_slip_number , mo_line_number , item_info
    2) Explain plan when the query is taking less than a minute
    Rows Row Source Operation
    1 SORT UNIQUE (cr=1299 r=87 w=0 time=50693 us)
    1 SORT GROUP BY (cr=1299 r=87 w=0 time=50475 us)
    1 FILTER (cr=1299 r=87 w=0 time=50009 us)
    1 NESTED LOOPS (cr=1299 r=87 w=0 time=50002 us)
    1 NESTED LOOPS (cr=1296 r=87 w=0 time=49937 us)
    1 NESTED LOOPS (cr=1293 r=87 w=0 time=49873 us)
    1 NESTED LOOPS (cr=1290 r=87 w=0 time=49799 us)
    1 NESTED LOOPS (cr=1287 r=87 w=0 time=49740 us)
    1 NESTED LOOPS OUTER (cr=1284 r=87 w=0 time=49676 us)
    1 NESTED LOOPS OUTER (cr=1284 r=87 w=0 time=49654 us)
    1 NESTED LOOPS OUTER (cr=1284 r=87 w=0 time=49633 us)
    1 NESTED LOOPS OUTER (cr=1282 r=87 w=0 time=49566 us)
    1 NESTED LOOPS (cr=1279 r=87 w=0 time=49490 us)
    1 NESTED LOOPS (cr=1276 r=87 w=0 time=49381 us)
    1 NESTED LOOPS (cr=1273 r=87 w=0 time=49287 us)
    1 NESTED LOOPS OUTER (cr=1270 r=87 w=0 time=49209 us)
    1 NESTED LOOPS (cr=1270 r=87 w=0 time=49182 us)
    1 NESTED LOOPS (cr=1267 r=87 w=0 time=49043 us)
    1 NESTED LOOPS (cr=19 r=0 w=0 time=4308 us)
    1 NESTED LOOPS (cr=16 r=0 w=0 time=4207 us)
    1 NESTED LOOPS (cr=13 r=0 w=0 time=4076 us)
    1 NESTED LOOPS (cr=5 r=0 w=0 time=781 us)
    1 TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 r=0 w=0 time=111 us)
    1 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 r=0 w=0 time=60 us)(object id 37657)
    1 TABLE ACCESS BY INDEX ROWID HR_ALL_ORGANIZATION_UNITS_TL (cr=3 r=0 w=0 time=636 us)
    1 INDEX UNIQUE SCAN HR_ALL_ORGANIZATION_UNTS_TL_PK (cr=2 r=0 w=0 time=605 us)(object id 44637)
    1 TABLE ACCESS BY INDEX ROWID HR_ALL_ORGANIZATION_UNITS (cr=8 r=0 w=0 time=3278 us)
    1 INDEX UNIQUE SCAN HR_ORGANIZATION_UNITS_PK (cr=1 r=0 w=0 time=31 us)(object id 43498)
    1 TABLE ACCESS BY INDEX ROWID IC_TXN_REQUEST_HEADERS (cr=3 r=0 w=0 time=104 us)
    1 INDEX RANGE SCAN IC_TXN_REQUEST_HEADERS_U1 (cr=2 r=0 w=0 time=67 us)(object id 637615)
    1 TABLE ACCESS BY INDEX ROWID IC_TXN_REQUEST_LINES (cr=3 r=0 w=0 time=84 us)
    1 INDEX RANGE SCAN IC_TXN_REQUEST_LINES_U1 (cr=2 r=0 w=0 time=53 us)(object id 637626)
    1 VIEW (cr=1248 r=87 w=0 time=44702 us)
    1 UNION-ALL PARTITION (cr=1248 r=87 w=0 time=44669 us)
    1 NESTED LOOPS (cr=1248 r=87 w=0 time=44561 us)
    1 NESTED LOOPS (cr=1244 r=87 w=0 time=44429 us)
    1 NESTED LOOPS (cr=13 r=0 w=0 time=322 us)
    1 NESTED LOOPS (cr=11 r=0 w=0 time=281 us)
    1 NESTED LOOPS (cr=9 r=0 w=0 time=228 us)
    1 NESTED LOOPS (cr=6 r=0 w=0 time=156 us)
    1 TABLE ACCESS BY INDEX ROWID IC_TXN_REQUEST_LINES (cr=3 r=0 w=0 time=64 us)
    1 INDEX UNIQUE SCAN IC_TXN_REQUEST_LINES_PK (cr=2 r=0 w=0 time=38 us)(object id 637620)
    1 TABLE ACCESS BY INDEX ROWID MTL_SYSTEM_ITEMS_B (cr=3 r=0 w=0 time=74 us)
    1 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=2 r=0 w=0 time=41 us)(object id 38017)
    1 TABLE ACCESS BY INDEX ROWID IC_ITEM_MST_B (cr=3 r=0 w=0 time=60 us)
    1 INDEX UNIQUE SCAN IC_ITEM_MST_B_UNQ1 (cr=2 r=0 w=0 time=38 us)(object id 637202)
    1 INDEX UNIQUE SCAN IC_ITEM_MST_TL_PK (cr=2 r=0 w=0 time=33 us)(object id 637049)
    1 INDEX UNIQUE SCAN IC_TXN_REQUEST_HEADERS_PK (cr=2 r=0 w=0 time=33 us)(object id 637610)
    1 TABLE ACCESS BY INDEX ROWID IC_TRAN_PND (cr=1231 r=87 w=0 time=44078 us)
    1907 INDEX RANGE SCAN IC_TRAN_PNDI6 (cr=10 r=0 w=0 time=3000 us)(object id 222381)
    1 TABLE ACCESS BY INDEX ROWID IC_LOTS_MST (cr=4 r=0 w=0 time=90 us)
    1 INDEX UNIQUE SCAN IC_LOTS_MST_PK (cr=3 r=0 w=0 time=60 us)(object id 637681)
    0 FILTER (cr=0 r=0 w=0 time=2 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID IC_TXN_REQUEST_LINES (cr=0 r=0 w=0 time=0 us)
    0 INDEX UNIQUE SCAN IC_TXN_REQUEST_LINES_PK (cr=0 r=0 w=0 time=0 us)(object id 637620)
    0 TABLE ACCESS BY INDEX ROWID MTL_SYSTEM_ITEMS_B (cr=0 r=0 w=0 time=0 us)
    0 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=0 r=0 w=0 time=0 us)(object id 38017)
    0 TABLE ACCESS BY INDEX ROWID IC_ITEM_MST_B (cr=0 r=0 w=0 time=0 us)
    0 INDEX UNIQUE SCAN IC_ITEM_MST_B_UNQ1 (cr=0 r=0 w=0 time=0 us)(object id 637202)
    0 INDEX UNIQUE SCAN IC_TXN_REQUEST_HEADERS_PK (cr=0 r=0 w=0 time=0 us)(object id 637610)
    0 TABLE ACCESS BY INDEX ROWID IC_TRAN_PND (cr=0 r=0 w=0 time=0 us)
    0 INDEX RANGE SCAN IC_TRAN_PNDI6 (cr=0 r=0 w=0 time=0 us)(object id 222381)
    0 TABLE ACCESS BY INDEX ROWID IC_LOTS_MST (cr=0 r=0 w=0 time=0 us)
    0 INDEX UNIQUE SCAN IC_LOTS_MST_PK (cr=0 r=0 w=0 time=0 us)(object id 637681)
    1 TABLE ACCESS BY INDEX ROWID WSH_DELIVERY_DETAILS (cr=3 r=0 w=0 time=106 us)
    1 INDEX RANGE SCAN WSH_DELIVERY_DETAILS_N3 (cr=2 r=0 w=0 time=65 us)(object id 46264)
    0 TABLE ACCESS BY INDEX ROWID OE_SETS (cr=0 r=0 w=0 time=3 us)
    0 INDEX UNIQUE SCAN OE_SETS_U1 (cr=0 r=0 w=0 time=1 us)(object id 43138)
    1 TABLE ACCESS BY INDEX ROWID OE_ORDER_LINES_ALL (cr=3 r=0 w=0 time=58 us)
    1 INDEX UNIQUE SCAN OE_ORDER_LINES_U1 (cr=2 r=0 w=0 time=35 us)(object id 42102)
    1 TABLE ACCESS BY INDEX ROWID MTL_SYSTEM_ITEMS_B (cr=3 r=0 w=0 time=67 us)
    1 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=2 r=0 w=0 time=41 us)(object id 38017)
    1 TABLE ACCESS BY INDEX ROWID WSH_DELIVERY_ASSIGNMENTS (cr=3 r=0 w=0 time=87 us)
    1 INDEX RANGE SCAN WSH_DELIVERY_ASSIGNMENTS_N3 (cr=2 r=0 w=0 time=65 us)(object id 46295)
    1 TABLE ACCESS BY INDEX ROWID WSH_NEW_DELIVERIES (cr=3 r=0 w=0 time=49____
    1 INDEX UNIQUE SCAN WSH_NEW_DELIVERIES_U1 (cr=2 r=0 w=0 time=28 us)(object id 46306)
    0 TABLE ACCESS BY INDEX ROWID WSH_DELIVERY_LEGS (cr=2 r=0 w=0 time=37 us)
    0 INDEX RANGE SCAN WSH_DELIVERY_LEGS_N1 (cr=2 r=0 w=0 time=35 us)(object id 46235)
    0 TABLE ACCESS BY INDEX ROWID WSH_TRIP_STOPS (cr=0 r=0 w=0 time=3 us)
    0 INDEX UNIQUE SCAN WSH_TRIP_STOPS_U1 (cr=0 r=0 w=0 time=1 us)(object id 46088)
    0 TABLE ACCESS BY INDEX ROWID WSH_TRIPS (cr=0 r=0 w=0 time=2 us)
    0 INDEX UNIQUE SCAN WSH_TRIPS_U1 (cr=0 r=0 w=0 time=1 us)(object id 46057)
    1 TABLE ACCESS BY INDEX ROWID OE_ORDER_HEADERS_ALL (cr=3 r=0 w=0 time=47 us)
    1 INDEX UNIQUE SCAN OE_ORDER_HEADERS_U1 (cr=2 r=0 w=0 time=27 us)(object id 41952)
    1 TABLE ACCESS BY INDEX ROWID HZ_CUST_SITE_USES_ALL (cr=3 r=0 w=0 time=44 us)
    1 INDEX UNIQUE SCAN HZ_CUST_SITE_USES_U1 (cr=2 r=0 w=0 time=29 us)(object id 236588)
    1 TABLE ACCESS BY INDEX ROWID HZ_CUST_ACCOUNTS (cr=3 r=0 w=0 time=52 us)
    1 INDEX UNIQUE SCAN HZ_CUST_ACCOUNTS_U1 (cr=2 r=0 w=0 time=34 us)(object id 81600)
    1 TABLE ACCESS BY INDEX ROWID HZ_PARTIES (cr=3 r=0 w=0 time=46 us)
    1 INDEX UNIQUE SCAN HZ_PARTIES_U1 (cr=2 r=0 w=0 time=28 us)(object id 237346)
    1 TABLE ACCESS BY INDEX ROWID IC_ITEM_MST_B (cr=3 r=0 w=0 time=41 us)
    1 INDEX UNIQUE SCAN IC_ITEM_MST_B_UNQ1 (cr=2 r=0 w=0 time=24 us)(object id 637202)
    3) Explain plan when the query is taking 22mins (for org_id=382)
    Rows Row Source Operation
    1 SORT UNIQUE (cr=72660499 r=624 w=0 time=1327230739 us)
    1 SORT GROUP BY (cr=72660499 r=624 w=0 time=1327230336 us)
    1 FILTER (cr=72660499 r=624 w=0 time=1327229578 us)
    1 NESTED LOOPS (cr=72660499 r=624 w=0 time=1327229570 us)
    1 NESTED LOOPS (cr=72660496 r=623 w=0 time=1327217298 us)
    1 NESTED LOOPS (cr=72660493 r=623 w=0 time=1327217219 us)
    1 NESTED LOOPS OUTER (cr=72660490 r=623 w=0 time=1327217140 us)
    1 NESTED LOOPS OUTER (cr=72660490 r=623 w=0 time=1327217118 us)
    1 NESTED LOOPS OUTER (cr=72660490 r=623 w=0 time=1327217092 us)
    1 NESTED LOOPS OUTER (cr=72660488 r=623 w=0 time=1327217006 us)
    1 NESTED LOOPS (cr=72660485 r=622 w=0 time=1327207555 us)
    1 NESTED LOOPS (cr=72660480 r=621 w=0 time=1327207177 us)
    1 NESTED LOOPS (cr=72660477 r=621 w=0 time=1327207115 us)
    1 NESTED LOOPS (cr=72660474 r=621 w=0 time=1327207034 us)
    1 NESTED LOOPS (cr=72660471 r=621 w=0 time=1327206951 us)
    7 NESTED LOOPS (cr=72660455 r=619 w=0 time=1327206132 us)
    7 NESTED LOOPS OUTER (cr=72660439 r=613 w=0 time=1327203302 us)
    7 NESTED LOOPS (cr=72660439 r=613 w=0 time=1327203073 us)
    14 NESTED LOOPS (cr=72660407 r=610 w=0 time=1327200108 us)
    90549 NESTED LOOPS (cr=3359 r=455 w=0 time=1818230 us)
    1 NESTED LOOPS (cr=13 r=0 w=0 time=4463 us)
    1 NESTED LOOPS (cr=5 r=0 w=0 time=962 us)
    1 TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 r=0 w=0 time=107 us)
    1 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 r=0 w=0 time=55 us)(object id 37657)
    1 TABLE ACCESS BY INDEX ROWID HR_ALL_ORGANIZATION_UNITS_TL (cr=3 r=0 w=0 time=820 us)
    1 INDEX UNIQUE SCAN HR_ALL_ORGANIZATION_UNTS_TL_PK (cr=2 r=0 w=0 time=786 us)(object id 44637)
    1 TABLE ACCESS BY INDEX ROWID HR_ALL_ORGANIZATION_UNITS (cr=8 r=0 w=0 time=3479 us)
    1 INDEX UNIQUE SCAN HR_ORGANIZATION_UNITS_PK (cr=1 r=0 w=0 time=23 us)(object id 43498)
    90549 TABLE ACCESS BY INDEX ROWID IC_TXN_REQUEST_LINES (cr=3346 r=455 w=0 time=1704106 us)
    90549 INDEX RANGE SCAN IC_TXN_REQUEST_LINES_N1 (cr=210 r=41 w=0 time=694480 us)(object id 133389)
    14 VIEW (cr=72657048 r=155 w=0 time=1324006502 us)
    14 UNION-ALL PARTITION (cr=72657048 r=155 w=0 time=1322889352 us)
    14 NESTED LOOPS (cr=72657048 r=155 w=0 time=1318179989 us)
    14 NESTED LOOPS (cr=72656992 r=151 w=0 time=1318005647 us)
    90549 NESTED LOOPS (cr=1177138 r=52 w=0 time=20959096 us)
    90549 NESTED LOOPS (cr=996040 r=51 w=0 time=18410001 us)
    90549 NESTED LOOPS (cr=814942 r=51 w=0 time=15523206 us)
    90549 NESTED LOOPS (cr=543294 r=50 w=0 time=10944790 us)
    90549 TABLE ACCESS BY INDEX ROWID IC_TXN_REQUEST_LINES (cr=271647 r=1 w=0 time=5063466 us)
    90549 INDEX UNIQUE SCAN IC_TXN_REQUEST_LINES_PK (cr=181098 r=1 w=0 time=2863447 us)(object id 637620)
    90549 TABLE ACCESS BY INDEX ROWID MTL_SYSTEM_ITEMS_B (cr=271647 r=49 w=0 time=4794430 us)
    90549 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=181098 r=1 w=0 time=2553802 us)(object id 38017)
    90549 TABLE ACCESS BY INDEX ROWID IC_ITEM_MST_B (cr=271648 r=1 w=0 time=3786267 us)
    90549 INDEX UNIQUE SCAN IC_ITEM_MST_B_UNQ1 (cr=181098 r=0 w=0 time=2164425 us)(object id 637202)
    90549 INDEX UNIQUE SCAN IC_ITEM_MST_TL_PK (cr=181098 r=0 w=0 time=2260794 us)(object id 637049)
    90549 INDEX UNIQUE SCAN IC_TXN_REQUEST_HEADERS_PK (cr=181098 r=1 w=0 time=1902881 us)(object id 637610)
    14 TABLE ACCESS BY INDEX ROWID IC_TRAN_PND (cr=71479854 r=99 w=0 time=1295671259 us)
    101213210 INDEX RANGE SCAN IC_TRAN_PNDI6 (cr=676173 r=21 w=0 time=136382307 us)(object id 222381)
    14 TABLE ACCESS BY INDEX ROWID IC_LOTS_MST (cr=56 r=4 w=0 time=2052 us)
    14 INDEX UNIQUE SCAN IC_LOTS_MST_PK (cr=42 r=2 w=0 time=1265 us)(object id 637681)
    0 FILTER (cr=0 r=0 w=0 time=59787 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID IC_TXN_REQUEST_LINES (cr=0 r=0 w=0 time=0 us)
    0 INDEX UNIQUE SCAN IC_TXN_REQUEST_LINES_PK (cr=0 r=0 w=0 time=0 us)(object id 637620)
    0 TABLE ACCESS BY INDEX ROWID MTL_SYSTEM_ITEMS_B (cr=0 r=0 w=0 time=0 us)
    0 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=0 r=0 w=0 time=0 us)(object id 38017)
    0 TABLE ACCESS BY INDEX ROWID IC_ITEM_MST_B (cr=0 r=0 w=0 time=0 us)
    0 INDEX UNIQUE SCAN IC_ITEM_MST_B_UNQ1 (cr=0 r=0 w=0 time=0 us)(object id 637202)
    0 INDEX UNIQUE SCAN IC_TXN_REQUEST_HEADERS_PK (cr=0 r=0 w=0 time=0 us)(object id 637610)
    0 TABLE ACCESS BY INDEX ROWID IC_TRAN_PND (cr=0 r=0 w=0 time=0 us)
    0 INDEX RANGE SCAN IC_TRAN_PNDI6 (cr=0 r=0 w=0 time=0 us)(object id 222381)
    0 TABLE ACCESS BY INDEX ROWID IC_LOTS_MST (cr=0 r=0 w=0 time=0 us)
    0 INDEX UNIQUE SCAN IC_LOTS_MST_PK (cr=0 r=0 w=0 time=0 us)(object id 637681)
    7 TABLE ACCESS BY INDEX ROWID WSH_DELIVERY_DETAILS (cr=32 r=3 w=0 time=2586 us)
    14 INDEX RANGE SCAN WSH_DELIVERY_DETAILS_N3 (cr=16 r=1 w=0 time=1221 us)(object id 46264)
    0 TABLE ACCESS BY INDEX ROWID OE_SETS (cr=0 r=0 w=0 time=32 us)
    0 INDEX UNIQUE SCAN OE_SETS_U1 (cr=0 r=0 w=0 time=6 us)(object id 43138)
    7 TABLE ACCESS BY INDEX ROWID OE_ORDER_LINES_ALL (cr=16 r=6 w=0 time=2715 us)
    7 INDEX UNIQUE SCAN OE_ORDER_LINES_U1 (cr=9 r=2 w=0 time=1399 us)(object id 42102)
    1 TABLE ACCESS BY INDEX ROWID IC_TXN_REQUEST_HEADERS (cr=16 r=2 w=0 time=679 us)
    7 INDEX UNIQUE SCAN IC_TXN_REQUEST_HEADERS_PK (cr=9 r=0 w=0 time=124 us)(object id 637610)
    1 TABLE ACCESS BY INDEX ROWID MTL_SYSTEM_ITEMS_B (cr=3 r=0 w=0 time=50 us)
    1 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=2 r=0 w=0 time=23 us)(object id 38017)
    1 TABLE ACCESS BY INDEX ROWID OE_ORDER_HEADERS_ALL (cr=3 r=0 w=0 time=58 us)
    1 INDEX UNIQUE SCAN OE_ORDER_HEADERS_U1 (cr=2 r=0 w=0 time=36 us)(object id 41952)
    1 TABLE ACCESS BY INDEX ROWID IC_ITEM_MST_B (cr=3 r=0 w=0 time=33 us)
    1 INDEX UNIQUE SCAN IC_ITEM_MST_B_UNQ1 (cr=2 r=0 w=0 time=14 us)(object id 637202)
    1 TABLE ACCESS BY INDEX ROWID WSH_DELIVERY_ASSIGNMENTS (cr=5 r=1 w=0 time=358 us)
    1 INDEX RANGE SCAN WSH_DELIVERY_ASSIGNMENTS_N3 (cr=2 r=0 w=0 time=68 us)(object id 46295)
    1 TABLE ACCESS BY INDEX ROWID WSH_NEW_DELIVERIES (cr=3 r=1 w=0 time=9428 us)
    1 INDEX UNIQUE SCAN WSH_NEW_DELIVERIES_U1 (cr=2 r=1 w=0 time=9405 us)(object id 46306)
    0 TABLE ACCESS BY INDEX ROWID WSH_DELIVERY_LEGS (cr=2 r=0 w=0 time=58 us)
    0 INDEX RANGE SCAN WSH_DELIVERY_LEGS_N1 (cr=2 r=0 w=0 time=55 us)(object id 46235)
    0 TABLE ACCESS BY INDEX ROWID WSH_TRIP_STOPS (cr=0 r=0 w=0 time=2 us)
    0 INDEX UNIQUE SCAN WSH_TRIP_STOPS_U1 (cr=0 r=0 w=0 time=1 us)(object id 46088)
    0 TABLE ACCESS BY INDEX ROWID WSH_TRIPS (cr=0 r=0 w=0 time=1 us)
    0 INDEX UNIQUE SCAN WSH_TRIPS_U1 (cr=0 r=0 w=0 time=1 us)(object id 46057)
    1 TABLE ACCESS BY INDEX ROWID HZ_CUST_ACCOUNTS (cr=3 r=0 w=0 time=55 us)
    1 INDEX UNIQUE SCAN HZ_CUST_ACCOUNTS_U1 (cr=2 r=0 w=0 time=34 us)(object id 81600)
    1 TABLE ACCESS BY INDEX ROWID HZ_PARTIES (cr=3 r=0 w=0 time=48 us)
    1 INDEX UNIQUE SCAN HZ_PARTIES_U1 (cr=2 r=0 w=0 time=26 us)(object id 237346)
    1 TABLE ACCESS BY INDEX ROWID HZ_CUST_SITE_USES_ALL (cr=3 r=1 w=0 time=12241 us)
    1 INDEX UNIQUE SCAN HZ_CUST_SITE_USES_U1 (cr=2 r=1 w=0 time=12187 us)(object id 236588)

    SQL is behaving different for different inputs. Its taking 20mins to execute when oraganization_id=382 is passed adn with other organization_id's are passed it is taking less than 2 minutes. Execution plan is different in both the cases. I will provide bith sql and execution plans.
    I tried rebuilding the indexes and gather stats for the tables but it did not help out.
    Please help me in tuning the sql.
    1) SQL
    SELECT DISTINCT mp . organization_name , mp . organization_code , mp .
    organization_name , wpsv . pick_slip_number , wpsv .
    from
    subinventory , csu . location shipto_location , wpsv . from_locator_id ,
    wpsv . to_subinventory , wpsv . to_locator_id , mtrh . request_number
    mo_number , wpsv . detailing_date , mtrl . line_id mo_line_id , wpsv .
    transaction_id , wdd . move_order_line_id , to_char ( wdd .
    source_header_id ) order_n_header_char , to_char ( wdd . source_line_id )
    order_n_line_char , wdd . source_header_id , wdd . source_line_id , mtrl .
    line_number mo_line_number , wtr . trip_id , wtr . name rip_name , wnd .
    delivery_id , wnd . name delivery_name , wdd . shipping_instructions , wdd
    . packing_instructions , r . customer_name , wdd . source_header_number ,
    ol . line_number sales_line_number , ol . schedule_ship_date , sum ( NVL (
    wdd . requested_quantity , 0 ) ) requested_quantity , sum ( NVL ( wdd .
    requested_quantity2 , 0 ) ) requested_quantity2 , sum ( NVL ( wdd .
    shipped_quantity , 0 ) ) shipped_quantity , sum ( NVL ( wdd .
    shipped_quantity2 , 0 ) ) shipped_quantity2 , wdd . ship_tolerance_above ,
    wdd . ship_tolerance_below , msi.description item_info , msi . segment1 ,
    msi . description item_description , wdd . inventory_item_id , os .
    set_name , wdd . requested_quantity_uom , wdd . requested_quantity_uom2 ,
    wpsv . transaction_id , wpsv . line_status , wdd . revision , wpsv .
    primary_qty , wpsv . trans_um1 , wpsv . secondary_qty , wpsv . trans_um2 ,
    wpsv . qc_grade , wpsv . lot_id , wpsv . lot_no lot_number , iim .
    attribute19 min_max_stor_temp , wpsv . location , SUBSTR ( wpsv . location ,
    1 , 3 ) lot_location_group FROM IC_ITEM_MST_B iim , WSH_TRIPS wtr ,
    WSH_TRIP_STOPS wts , WSH_DELIVERY_LEGS wlg , WSH_NEW_DELIVERIES wnd ,
    WSH_DELIVERY_ASSIGNMENTS wda , WSH_DELIVERY_DETAILS wdd ,
    GMI_WSH_PICK_SLIP_V wpsv , OE_ORDER_LINES_ALL ol , OE_SETS os ,
    RA_CUSTOMERS r , IC_TXN_REQUEST_HEADERS mtrh , IC_TXN_REQUEST_LINES mtrl ,
    MTL_SYSTEM_ITEMS msi , HZ_CUST_SITE_USES_ALL csu , OE_ORDER_HEADERS_ALL ooh
    , ( SELECT mp . organization_id , mp . organization_code , hou . name
    organization_name FROM HR_ORGANIZATION_UNITS hou , MTL_PARAMETERS mp where
    mp . organization_id = hou . organization_id ) mp WHERE wtr.trip_id (+) =
    wts.trip_id AND wts.stop_id (+) = wlg.pick_up_stop_id AND wlg.delivery_id
    (+) = wnd.delivery_id AND wnd.delivery_id (+) = wda.delivery_id AND
    wdd.source_header_id = ooh.header_id AND csu.site_use_id =
    ooh.ship_to_org_id AND os.set_id (+) = wdd.ship_set_id AND
    wda.delivery_detail_id = wdd.delivery_detail_id AND ol.line_id =
    wdd.source_line_id AND wpsv.transaction_id = ol.line_id AND
    wpsv.transaction_id = wdd.source_line_id AND r.customer_id =
    wdd.customer_id AND mtrl.header_id = mtrh.header_id AND mtrl.line_id =
    wdd.move_order_line_id AND mtrl.inventory_item_id = wpsv.inventory_item_id
    AND mtrl.line_id = wpsv.move_order_line_id AND msi.inventory_item_id =
    wdd.inventory_item_id AND msi.organization_id = mtrl.organization_id AND
    iim.item_no = msi.segment1 AND mtrl.organization_id = : p_organization_id
    AND mtrl.organization_id = mp.organization_id and mtrh.request_number
    between : p_move_order_low and : p_move_order_high and wpsv.line_status =
    'UNPICKED' GROUP BY mp.organization_name , mp.organization_code ,
    csu.location , wpsv.pick_slip_number , wpsv.from_subinventory ,
    wpsv.from_locator_id , wpsv.to_subinventory , wpsv.to_locator_id ,
    mtrh.request_number , wpsv.detailing_date , mtrl.line_id ,
    wpsv.transaction_id , wdd.move_order_line_id , to_char (
    wdd.source_header_id ) , to_char ( wdd.source_line_id ) ,
    wdd.source_header_id , wdd.source_line_id , mtrl.line_number , wtr.trip_id ,
    wtr.name , wnd.delivery_id , wnd.name , wdd.shipping_instructions ,
    wdd.packing_instructions , r.customer_name , wdd.source_header_number ,
    ol.line_number , ol.schedule_ship_date , wdd.ship_tolerance_above ,
    wdd.ship_tolerance_below , msi.description , msi.segment1 , msi.description
    , wdd.inventory_item_id , os.set_name , wdd.requested_quantity_uom ,
    wdd.requested_quantity_uom2 , wpsv.transaction_id , wpsv.line_status ,
    wdd.revision , wpsv.primary_qty , wpsv.trans_um1 , wpsv.secondary_qty ,
    wpsv.trans_um2 , wpsv.qc_grade , wpsv.lot_id , wpsv.lot_no ,
    iim.attribute19 , wpsv.location , SUBSTR ( wpsv.location , 1 , 3 ) ORDER BY
    1 ASC,2 ASC,10 ASC,6 ASC,4 ASC,17 ASC,5 ASC,7 ASC,8 ASC,9 ASC,13 ASC,12 ASC,
    55 ASC,43 ASC,14 ASC,19 ASC,18 ASC,39 ASC,53 ASC,29 ASC,36 ASC,37 ASC,38
    ASC,30 ASC,41 ASC,31 ASC,42 ASC,40 ASC,33 ASC,34 ASC,35 ASC,27 ASC,28 ASC,
    20 ASC,21 ASC,22 ASC,23 ASC,26 ASC,24 ASC,25 ASC , mp.organization_code ,
    mo_number , pick_slip_number , mo_line_number , item_info
    2) Explain plan when the query is taking less than a minute
    Rows Row Source Operation
    1 SORT UNIQUE (cr=1299 r=87 w=0 time=50693 us)
    1 SORT GROUP BY (cr=1299 r=87 w=0 time=50475 us)
    1 FILTER (cr=1299 r=87 w=0 time=50009 us)
    1 NESTED LOOPS (cr=1299 r=87 w=0 time=50002 us)
    1 NESTED LOOPS (cr=1296 r=87 w=0 time=49937 us)
    1 NESTED LOOPS (cr=1293 r=87 w=0 time=49873 us)
    1 NESTED LOOPS (cr=1290 r=87 w=0 time=49799 us)
    1 NESTED LOOPS (cr=1287 r=87 w=0 time=49740 us)
    1 NESTED LOOPS OUTER (cr=1284 r=87 w=0 time=49676 us)
    1 NESTED LOOPS OUTER (cr=1284 r=87 w=0 time=49654 us)
    1 NESTED LOOPS OUTER (cr=1284 r=87 w=0 time=49633 us)
    1 NESTED LOOPS OUTER (cr=1282 r=87 w=0 time=49566 us)
    1 NESTED LOOPS (cr=1279 r=87 w=0 time=49490 us)
    1 NESTED LOOPS (cr=1276 r=87 w=0 time=49381 us)
    1 NESTED LOOPS (cr=1273 r=87 w=0 time=49287 us)
    1 NESTED LOOPS OUTER (cr=1270 r=87 w=0 time=49209 us)
    1 NESTED LOOPS (cr=1270 r=87 w=0 time=49182 us)
    1 NESTED LOOPS (cr=1267 r=87 w=0 time=49043 us)
    1 NESTED LOOPS (cr=19 r=0 w=0 time=4308 us)
    1 NESTED LOOPS (cr=16 r=0 w=0 time=4207 us)
    1 NESTED LOOPS (cr=13 r=0 w=0 time=4076 us)
    1 NESTED LOOPS (cr=5 r=0 w=0 time=781 us)
    1 TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 r=0 w=0 time=111 us)
    1 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 r=0 w=0 time=60 us)(object id 37657)
    1 TABLE ACCESS BY INDEX ROWID HR_ALL_ORGANIZATION_UNITS_TL (cr=3 r=0 w=0 time=636 us)
    1 INDEX UNIQUE SCAN HR_ALL_ORGANIZATION_UNTS_TL_PK (cr=2 r=0 w=0 time=605 us)(object id 44637)
    1 TABLE ACCESS BY INDEX ROWID HR_ALL_ORGANIZATION_UNITS (cr=8 r=0 w=0 time=3278 us)
    1 INDEX UNIQUE SCAN HR_ORGANIZATION_UNITS_PK (cr=1 r=0 w=0 time=31 us)(object id 43498)
    1 TABLE ACCESS BY INDEX ROWID IC_TXN_REQUEST_HEADERS (cr=3 r=0 w=0 time=104 us)
    1 INDEX RANGE SCAN IC_TXN_REQUEST_HEADERS_U1 (cr=2 r=0 w=0 time=67 us)(object id 637615)
    1 TABLE ACCESS BY INDEX ROWID IC_TXN_REQUEST_LINES (cr=3 r=0 w=0 time=84 us)
    1 INDEX RANGE SCAN IC_TXN_REQUEST_LINES_U1 (cr=2 r=0 w=0 time=53 us)(object id 637626)
    1 VIEW (cr=1248 r=87 w=0 time=44702 us)
    1 UNION-ALL PARTITION (cr=1248 r=87 w=0 time=44669 us)
    1 NESTED LOOPS (cr=1248 r=87 w=0 time=44561 us)
    1 NESTED LOOPS (cr=1244 r=87 w=0 time=44429 us)
    1 NESTED LOOPS (cr=13 r=0 w=0 time=322 us)
    1 NESTED LOOPS (cr=11 r=0 w=0 time=281 us)
    1 NESTED LOOPS (cr=9 r=0 w=0 time=228 us)
    1 NESTED LOOPS (cr=6 r=0 w=0 time=156 us)
    1 TABLE ACCESS BY INDEX ROWID IC_TXN_REQUEST_LINES (cr=3 r=0 w=0 time=64 us)
    1 INDEX UNIQUE SCAN IC_TXN_REQUEST_LINES_PK (cr=2 r=0 w=0 time=38 us)(object id 637620)
    1 TABLE ACCESS BY INDEX ROWID MTL_SYSTEM_ITEMS_B (cr=3 r=0 w=0 time=74 us)
    1 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=2 r=0 w=0 time=41 us)(object id 38017)
    1 TABLE ACCESS BY INDEX ROWID IC_ITEM_MST_B (cr=3 r=0 w=0 time=60 us)
    1 INDEX UNIQUE SCAN IC_ITEM_MST_B_UNQ1 (cr=2 r=0 w=0 time=38 us)(object id 637202)
    1 INDEX UNIQUE SCAN IC_ITEM_MST_TL_PK (cr=2 r=0 w=0 time=33 us)(object id 637049)
    1 INDEX UNIQUE SCAN IC_TXN_REQUEST_HEADERS_PK (cr=2 r=0 w=0 time=33 us)(object id 637610)
    1 TABLE ACCESS BY INDEX ROWID IC_TRAN_PND (cr=1231 r=87 w=0 time=44078 us)
    1907 INDEX RANGE SCAN IC_TRAN_PNDI6 (cr=10 r=0 w=0 time=3000 us)(object id 222381)
    1 TABLE ACCESS BY INDEX ROWID IC_LOTS_MST (cr=4 r=0 w=0 time=90 us)
    1 INDEX UNIQUE SCAN IC_LOTS_MST_PK (cr=3 r=0 w=0 time=60 us)(object id 637681)
    0 FILTER (cr=0 r=0 w=0 time=2 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID IC_TXN_REQUEST_LINES (cr=0 r=0 w=0 time=0 us)
    0 INDEX UNIQUE SCAN IC_TXN_REQUEST_LINES_PK (cr=0 r=0 w=0 time=0 us)(object id 637620)
    0 TABLE ACCESS BY INDEX ROWID MTL_SYSTEM_ITEMS_B (cr=0 r=0 w=0 time=0 us)
    0 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=0 r=0 w=0 time=0 us)(object id 38017)
    0 TABLE ACCESS BY INDEX ROWID IC_ITEM_MST_B (cr=0 r=0 w=0 time=0 us)
    0 INDEX UNIQUE SCAN IC_ITEM_MST_B_UNQ1 (cr=0 r=0 w=0 time=0 us)(object id 637202)
    0 INDEX UNIQUE SCAN IC_TXN_REQUEST_HEADERS_PK (cr=0 r=0 w=0 time=0 us)(object id 637610)
    0 TABLE ACCESS BY INDEX ROWID IC_TRAN_PND (cr=0 r=0 w=0 time=0 us)
    0 INDEX RANGE SCAN IC_TRAN_PNDI6 (cr=0 r=0 w=0 time=0 us)(object id 222381)
    0 TABLE ACCESS BY INDEX ROWID IC_LOTS_MST (cr=0 r=0 w=0 time=0 us)
    0 INDEX UNIQUE SCAN IC_LOTS_MST_PK (cr=0 r=0 w=0 time=0 us)(object id 637681)
    1 TABLE ACCESS BY INDEX ROWID WSH_DELIVERY_DETAILS (cr=3 r=0 w=0 time=106 us)
    1 INDEX RANGE SCAN WSH_DELIVERY_DETAILS_N3 (cr=2 r=0 w=0 time=65 us)(object id 46264)
    0 TABLE ACCESS BY INDEX ROWID OE_SETS (cr=0 r=0 w=0 time=3 us)
    0 INDEX UNIQUE SCAN OE_SETS_U1 (cr=0 r=0 w=0 time=1 us)(object id 43138)
    1 TABLE ACCESS BY INDEX ROWID OE_ORDER_LINES_ALL (cr=3 r=0 w=0 time=58 us)
    1 INDEX UNIQUE SCAN OE_ORDER_LINES_U1 (cr=2 r=0 w=0 time=35 us)(object id 42102)
    1 TABLE ACCESS BY INDEX ROWID MTL_SYSTEM_ITEMS_B (cr=3 r=0 w=0 time=67 us)
    1 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=2 r=0 w=0 time=41 us)(object id 38017)
    1 TABLE ACCESS BY INDEX ROWID WSH_DELIVERY_ASSIGNMENTS (cr=3 r=0 w=0 time=87 us)
    1 INDEX RANGE SCAN WSH_DELIVERY_ASSIGNMENTS_N3 (cr=2 r=0 w=0 time=65 us)(object id 46295)
    1 TABLE ACCESS BY INDEX ROWID WSH_NEW_DELIVERIES (cr=3 r=0 w=0 time=49____
    1 INDEX UNIQUE SCAN WSH_NEW_DELIVERIES_U1 (cr=2 r=0 w=0 time=28 us)(object id 46306)
    0 TABLE ACCESS BY INDEX ROWID WSH_DELIVERY_LEGS (cr=2 r=0 w=0 time=37 us)
    0 INDEX RANGE SCAN WSH_DELIVERY_LEGS_N1 (cr=2 r=0 w=0 time=35 us)(object id 46235)
    0 TABLE ACCESS BY INDEX ROWID WSH_TRIP_STOPS (cr=0 r=0 w=0 time=3 us)
    0 INDEX UNIQUE SCAN WSH_TRIP_STOPS_U1 (cr=0 r=0 w=0 time=1 us)(object id 46088)
    0 TABLE ACCESS BY INDEX ROWID WSH_TRIPS (cr=0 r=0 w=0 time=2 us)
    0 INDEX UNIQUE SCAN WSH_TRIPS_U1 (cr=0 r=0 w=0 time=1 us)(object id 46057)
    1 TABLE ACCESS BY INDEX ROWID OE_ORDER_HEADERS_ALL (cr=3 r=0 w=0 time=47 us)
    1 INDEX UNIQUE SCAN OE_ORDER_HEADERS_U1 (cr=2 r=0 w=0 time=27 us)(object id 41952)
    1 TABLE ACCESS BY INDEX ROWID HZ_CUST_SITE_USES_ALL (cr=3 r=0 w=0 time=44 us)
    1 INDEX UNIQUE SCAN HZ_CUST_SITE_USES_U1 (cr=2 r=0 w=0 time=29 us)(object id 236588)
    1 TABLE ACCESS BY INDEX ROWID HZ_CUST_ACCOUNTS (cr=3 r=0 w=0 time=52 us)
    1 INDEX UNIQUE SCAN HZ_CUST_ACCOUNTS_U1 (cr=2 r=0 w=0 time=34 us)(object id 81600)
    1 TABLE ACCESS BY INDEX ROWID HZ_PARTIES (cr=3 r=0 w=0 time=46 us)
    1 INDEX UNIQUE SCAN HZ_PARTIES_U1 (cr=2 r=0 w=0 time=28 us)(object id 237346)
    1 TABLE ACCESS BY INDEX ROWID IC_ITEM_MST_B (cr=3 r=0 w=0 time=41 us)
    1 INDEX UNIQUE SCAN IC_ITEM_MST_B_UNQ1 (cr=2 r=0 w=0 time=24 us)(object id 637202)
    3) Explain plan when the query is taking 22mins (for org_id=382)
    Rows Row Source Operation
    1 SORT UNIQUE (cr=72660499 r=624 w=0 time=1327230739 us)
    1 SORT GROUP BY (cr=72660499 r=624 w=0 time=1327230336 us)
    1 FILTER (cr=72660499 r=624 w=0 time=1327229578 us)
    1 NESTED LOOPS (cr=72660499 r=624 w=0 time=1327229570 us)
    1 NESTED LOOPS (cr=72660496 r=623 w=0 time=1327217298 us)
    1 NESTED LOOPS (cr=72660493 r=623 w=0 time=1327217219 us)
    1 NESTED LOOPS OUTER (cr=72660490 r=623 w=0 time=1327217140 us)
    1 NESTED LOOPS OUTER (cr=72660490 r=623 w=0 time=1327217118 us)
    1 NESTED LOOPS OUTER (cr=72660490 r=623 w=0 time=1327217092 us)
    1 NESTED LOOPS OUTER (cr=72660488 r=623 w=0 time=1327217006 us)
    1 NESTED LOOPS (cr=72660485 r=622 w=0 time=1327207555 us)
    1 NESTED LOOPS (cr=72660480 r=621 w=0 time=1327207177 us)
    1 NESTED LOOPS (cr=72660477 r=621 w=0 time=1327207115 us)
    1 NESTED LOOPS (cr=72660474 r=621 w=0 time=1327207034 us)
    1 NESTED LOOPS (cr=72660471 r=621 w=0 time=1327206951 us)
    7 NESTED LOOPS (cr=72660455 r=619 w=0 time=1327206132 us)
    7 NESTED LOOPS OUTER (cr=72660439 r=613 w=0 time=1327203302 us)
    7 NESTED LOOPS (cr=72660439 r=613 w=0 time=1327203073 us)
    14 NESTED LOOPS (cr=72660407 r=610 w=0 time=1327200108 us)
    90549 NESTED LOOPS (cr=3359 r=455 w=0 time=1818230 us)
    1 NESTED LOOPS (cr=13 r=0 w=0 time=4463 us)
    1 NESTED LOOPS (cr=5 r=0 w=0 time=962 us)
    1 TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 r=0 w=0 time=107 us)
    1 INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 r=0 w=0 time=55 us)(object id 37657)
    1 TABLE ACCESS BY INDEX ROWID HR_ALL_ORGANIZATION_UNITS_TL (cr=3 r=0 w=0 time=820 us)
    1 INDEX UNIQUE SCAN HR_ALL_ORGANIZATION_UNTS_TL_PK (cr=2 r=0 w=0 time=786 us)(object id 44637)
    1 TABLE ACCESS BY INDEX ROWID HR_ALL_ORGANIZATION_UNITS (cr=8 r=0 w=0 time=3479 us)
    1 INDEX UNIQUE SCAN HR_ORGANIZATION_UNITS_PK (cr=1 r=0 w=0 time=23 us)(object id 43498)
    90549 TABLE ACCESS BY INDEX ROWID IC_TXN_REQUEST_LINES (cr=3346 r=455 w=0 time=1704106 us)
    90549 INDEX RANGE SCAN IC_TXN_REQUEST_LINES_N1 (cr=210 r=41 w=0 time=694480 us)(object id 133389)
    14 VIEW (cr=72657048 r=155 w=0 time=1324006502 us)
    14 UNION-ALL PARTITION (cr=72657048 r=155 w=0 time=1322889352 us)
    14 NESTED LOOPS (cr=72657048 r=155 w=0 time=1318179989 us)
    14 NESTED LOOPS (cr=72656992 r=151 w=0 time=1318005647 us)
    90549 NESTED LOOPS (cr=1177138 r=52 w=0 time=20959096 us)
    90549 NESTED LOOPS (cr=996040 r=51 w=0 time=18410001 us)
    90549 NESTED LOOPS (cr=814942 r=51 w=0 time=15523206 us)
    90549 NESTED LOOPS (cr=543294 r=50 w=0 time=10944790 us)
    90549 TABLE ACCESS BY INDEX ROWID IC_TXN_REQUEST_LINES (cr=271647 r=1 w=0 time=5063466 us)
    90549 INDEX UNIQUE SCAN IC_TXN_REQUEST_LINES_PK (cr=181098 r=1 w=0 time=2863447 us)(object id 637620)
    90549 TABLE ACCESS BY INDEX ROWID MTL_SYSTEM_ITEMS_B (cr=271647 r=49 w=0 time=4794430 us)
    90549 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=181098 r=1 w=0 time=2553802 us)(object id 38017)
    90549 TABLE ACCESS BY INDEX ROWID IC_ITEM_MST_B (cr=271648 r=1 w=0 time=3786267 us)
    90549 INDEX UNIQUE SCAN IC_ITEM_MST_B_UNQ1 (cr=181098 r=0 w=0 time=2164425 us)(object id 637202)
    90549 INDEX UNIQUE SCAN IC_ITEM_MST_TL_PK (cr=181098 r=0 w=0 time=2260794 us)(object id 637049)
    90549 INDEX UNIQUE SCAN IC_TXN_REQUEST_HEADERS_PK (cr=181098 r=1 w=0 time=1902881 us)(object id 637610)
    14 TABLE ACCESS BY INDEX ROWID IC_TRAN_PND (cr=71479854 r=99 w=0 time=1295671259 us)
    101213210 INDEX RANGE SCAN IC_TRAN_PNDI6 (cr=676173 r=21 w=0 time=136382307 us)(object id 222381)
    14 TABLE ACCESS BY INDEX ROWID IC_LOTS_MST (cr=56 r=4 w=0 time=2052 us)
    14 INDEX UNIQUE SCAN IC_LOTS_MST_PK (cr=42 r=2 w=0 time=1265 us)(object id 637681)
    0 FILTER (cr=0 r=0 w=0 time=59787 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 NESTED LOOPS (cr=0 r=0 w=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID IC_TXN_REQUEST_LINES (cr=0 r=0 w=0 time=0 us)
    0 INDEX UNIQUE SCAN IC_TXN_REQUEST_LINES_PK (cr=0 r=0 w=0 time=0 us)(object id 637620)
    0 TABLE ACCESS BY INDEX ROWID MTL_SYSTEM_ITEMS_B (cr=0 r=0 w=0 time=0 us)
    0 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=0 r=0 w=0 time=0 us)(object id 38017)
    0 TABLE ACCESS BY INDEX ROWID IC_ITEM_MST_B (cr=0 r=0 w=0 time=0 us)
    0 INDEX UNIQUE SCAN IC_ITEM_MST_B_UNQ1 (cr=0 r=0 w=0 time=0 us)(object id 637202)
    0 INDEX UNIQUE SCAN IC_TXN_REQUEST_HEADERS_PK (cr=0 r=0 w=0 time=0 us)(object id 637610)
    0 TABLE ACCESS BY INDEX ROWID IC_TRAN_PND (cr=0 r=0 w=0 time=0 us)
    0 INDEX RANGE SCAN IC_TRAN_PNDI6 (cr=0 r=0 w=0 time=0 us)(object id 222381)
    0 TABLE ACCESS BY INDEX ROWID IC_LOTS_MST (cr=0 r=0 w=0 time=0 us)
    0 INDEX UNIQUE SCAN IC_LOTS_MST_PK (cr=0 r=0 w=0 time=0 us)(object id 637681)
    7 TABLE ACCESS BY INDEX ROWID WSH_DELIVERY_DETAILS (cr=32 r=3 w=0 time=2586 us)
    14 INDEX RANGE SCAN WSH_DELIVERY_DETAILS_N3 (cr=16 r=1 w=0 time=1221 us)(object id 46264)
    0 TABLE ACCESS BY INDEX ROWID OE_SETS (cr=0 r=0 w=0 time=32 us)
    0 INDEX UNIQUE SCAN OE_SETS_U1 (cr=0 r=0 w=0 time=6 us)(object id 43138)
    7 TABLE ACCESS BY INDEX ROWID OE_ORDER_LINES_ALL (cr=16 r=6 w=0 time=2715 us)
    7 INDEX UNIQUE SCAN OE_ORDER_LINES_U1 (cr=9 r=2 w=0 time=1399 us)(object id 42102)
    1 TABLE ACCESS BY INDEX ROWID IC_TXN_REQUEST_HEADERS (cr=16 r=2 w=0 time=679 us)
    7 INDEX UNIQUE SCAN IC_TXN_REQUEST_HEADERS_PK (cr=9 r=0 w=0 time=124 us)(object id 637610)
    1 TABLE ACCESS BY INDEX ROWID MTL_SYSTEM_ITEMS_B (cr=3 r=0 w=0 time=50 us)
    1 INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=2 r=0 w=0 time=23 us)(object id 38017)
    1 TABLE ACCESS BY INDEX ROWID OE_ORDER_HEADERS_ALL (cr=3 r=0 w=0 time=58 us)
    1 INDEX UNIQUE SCAN OE_ORDER_HEADERS_U1 (cr=2 r=0 w=0 time=36 us)(object id 41952)
    1 TABLE ACCESS BY INDEX ROWID IC_ITEM_MST_B (cr=3 r=0 w=0 time=33 us)
    1 INDEX UNIQUE SCAN IC_ITEM_MST_B_UNQ1 (cr=2 r=0 w=0 time=14 us)(object id 637202)
    1 TABLE ACCESS BY INDEX ROWID WSH_DELIVERY_ASSIGNMENTS (cr=5 r=1 w=0 time=358 us)
    1 INDEX RANGE SCAN WSH_DELIVERY_ASSIGNMENTS_N3 (cr=2 r=0 w=0 time=68 us)(object id 46295)
    1 TABLE ACCESS BY INDEX ROWID WSH_NEW_DELIVERIES (cr=3 r=1 w=0 time=9428 us)
    1 INDEX UNIQUE SCAN WSH_NEW_DELIVERIES_U1 (cr=2 r=1 w=0 time=9405 us)(object id 46306)
    0 TABLE ACCESS BY INDEX ROWID WSH_DELIVERY_LEGS (cr=2 r=0 w=0 time=58 us)
    0 INDEX RANGE SCAN WSH_DELIVERY_LEGS_N1 (cr=2 r=0 w=0 time=55 us)(object id 46235)
    0 TABLE ACCESS BY INDEX ROWID WSH_TRIP_STOPS (cr=0 r=0 w=0 time=2 us)
    0 INDEX UNIQUE SCAN WSH_TRIP_STOPS_U1 (cr=0 r=0 w=0 time=1 us)(object id 46088)
    0 TABLE ACCESS BY INDEX ROWID WSH_TRIPS (cr=0 r=0 w=0 time=1 us)
    0 INDEX UNIQUE SCAN WSH_TRIPS_U1 (cr=0 r=0 w=0 time=1 us)(object id 46057)
    1 TABLE ACCESS BY INDEX ROWID HZ_CUST_ACCOUNTS (cr=3 r=0 w=0 time=55 us)
    1 INDEX UNIQUE SCAN HZ_CUST_ACCOUNTS_U1 (cr=2 r=0 w=0 time=34 us)(object id 81600)
    1 TABLE ACCESS BY INDEX ROWID HZ_PARTIES (cr=3 r=0 w=0 time=48 us)
    1 INDEX UNIQUE SCAN HZ_PARTIES_U1 (cr=2 r=0 w=0 time=26 us)(object id 237346)
    1 TABLE ACCESS BY INDEX ROWID HZ_CUST_SITE_USES_ALL (cr=3 r=1 w=0 time=12241 us)
    1 INDEX UNIQUE SCAN HZ_CUST_SITE_USES_U1 (cr=2 r=1 w=0 time=12187 us)(object id 236588)

  • Need help in Performance tuning for function...

    Hi all,
    I am using the below algorithm for calculating the Luhn Alogorithm to calculate the 15th luhn digit for an IMEI (Phone Sim Card).
    But the below function is taking about 6 min for 5 million records. I had 170 million records in a table want to calculate the luhn digit for all of them which might take up to 4-5 hours.Please help me performance tuning (better way or better logic for luhn calculation) to the below function.
    A wikipedia link is provided for the luhn algorithm below
    Create or Replace FUNCTION AddLuhnToIMEI (LuhnPrimitive VARCHAR2)
          RETURN VARCHAR2
       AS
          Index_no     NUMBER (2) := LENGTH (LuhnPrimitive);
          Multiplier   NUMBER (1) := 2;
          Total_Sum    NUMBER (4) := 0;
          Plus         NUMBER (2);
          ReturnLuhn   VARCHAR2 (25);
       BEGIN
          WHILE Index_no >= 1
          LOOP
             Plus       := Multiplier * (TO_NUMBER (SUBSTR (LuhnPrimitive, Index_no, 1)));
             Multiplier := (3 - Multiplier);
             Total_Sum  := Total_Sum + TO_NUMBER (TRUNC ( (Plus / 10))) + MOD (Plus, 10);
             Index_no   := Index_no - 1;
          END LOOP;
          ReturnLuhn := LuhnPrimitive || CASE
                                             WHEN MOD (Total_Sum, 10) = 0 THEN '0'
                                             ELSE TO_CHAR (10 - MOD (Total_Sum, 10))
                                         END;
          RETURN ReturnLuhn;
       EXCEPTION
          WHEN OTHERS
          THEN
             RETURN (LuhnPrimitive);
       END AddLuhnToIMEI;
    http://en.wikipedia.org/wiki/Luhn_algorithmAny sort of help is much appreciated....
    Thanks
    Rede

    There is a not needed to_number function in it. TRUNC will already return a number.
    Also the MOD function can be avoided at some steps. Since multiplying by 2 will never be higher then 18 you can speed up the calculation with this.
    create or replace
    FUNCTION AddLuhnToIMEI_fast (LuhnPrimitive VARCHAR2)
          RETURN VARCHAR2
       AS
          Index_no     pls_Integer;
          Multiplier   pls_Integer := 2;
          Total_Sum    pls_Integer := 0;
          Plus         pls_Integer;
          rest         pls_integer;
          ReturnLuhn   VARCHAR2 (25);
       BEGIN
          for Index_no in reverse 1..LENGTH (LuhnPrimitive) LOOP
             Plus       := Multiplier * TO_NUMBER (SUBSTR (LuhnPrimitive, Index_no, 1));
             Multiplier := 3 - Multiplier;
             if Plus < 10 then
                Total_Sum  := Total_Sum + Plus ;
             else
                Total_Sum  := Total_Sum + Plus - 9;
             end if;  
          END LOOP;
          rest := MOD (Total_Sum, 10);
          ReturnLuhn := LuhnPrimitive || CASE WHEN rest = 0 THEN '0' ELSE TO_CHAR (10 - rest) END;
          RETURN ReturnLuhn;
       END AddLuhnToIMEI_fast;
    /My tests gave an improvement for about 40%.
    The next step to try could be to use native complilation on this function. This can give an additional big boost.
    Edited by: Sven W. on Mar 9, 2011 8:11 PM

  • SQL Tuning for Exadata

    Hi,
    I would like to know any SQL tuning methods specific to Oracle exadata so that they could improve the performance of the database?
    I am aware that oracle exadata runs with Oracle 11g, but i would like to know wheather there is any tuning scope w.r.t to SQL's on exadata?
    regards
    sunil

    Well there are some things that are very different about Exadata. All the standard Oracle SQL tuning you have learned already should not be forgotten as Exadata is running standard 11g database code, but there are many optimizations that have been added that you should be aware of. At a high level, if you are doing OLTP type work you should be trying to make sure that you take advantage of Exadata Smart Flash Cache which will significantly speed up your small I/O's. But long running queries are where the big benefits show up. The high level tuning approach for them is as follows:
    1. Check to see if you are getting Smart Scans.
    2. If you aren't, fix what ever is preventing them from being used.
    We've been involved in somewhere between 25-30 DB Machine installations now and in many cases, a little bit of effort changes performance dramatically. If you are only getting 2 to 3X improvement over your previous platform on these long running queries you are probably not getting the full benefit of the Exadata optimizations. So the first step is learning how to determine if you are getting Smart Scans or not and on what portions of the statement. Wait events, session statistics, V$SQL, SQL Monitoring are all viable tools that can show you that information.

  • Permissions needed for Applying SQL Tuning Sets/SQL Plans 11g?

    What permission are needed for a user to apply/activate sql tuning sets (sql plans) in 11g? The user can capture and move the the sql tuning sets from a 10g database to an 11g database but is getting "ORA-01031: insufficient privileges" when trying to activate/apply the sqlplans in 11g.
    The user has:
    ADMINISTER SQL MANAGEMENT OBJECT and ADMINISTER SQL TUNING SET and EXECUTE on SYS.DBMS_SPM
    The user is an administrator for our Data Warehouse team but they do not have sysdba priviliges.
    Do you also know of a good white paper that covers the step by step instructions and permissions needed for aquiring and applying/activating sqlplans?
    If more information is needed in order to respond please advise.
    Thank you

    What permission are needed for a user to apply/activate sql tuning sets (sql plans) in 11g? The user can capture and move the the sql tuning sets from a 10g database to an 11g database but is getting "ORA-01031: insufficient privileges" when trying to activate/apply the sqlplans in 11g.
    The user has:
    ADMINISTER SQL MANAGEMENT OBJECT and ADMINISTER SQL TUNING SET and EXECUTE on SYS.DBMS_SPM
    The user is an administrator for our Data Warehouse team but they do not have sysdba priviliges.
    Do you also know of a good white paper that covers the step by step instructions and permissions needed for aquiring and applying/activating sqlplans?
    If more information is needed in order to respond please advise.
    Thank you

  • Need help in Fine Tuning this query

    Hello Gurus,
    The below sql's are from Application engine . It runs more than 5 hours to complete . I have fewer knowledge on sql tuning and request to repharse the sql's to perform and complete the program within One hour.
    PS_GE_GAPS_INV is going thru Range Scan and TAO table is going for Full Table Scan.
    I have indexes on PS_GE_GAPS_INV which is the main table. Iam joining TAO(Temporary table) and Main Table with common keys defined thru Application designer.
    Appreciate all your help.
    First Sql :
    UPDATE PS_GE_GAPS_INV
    SET LAST_DTTM_UPDATE = TO_DATE(SYSDATE,'DD-MM-YY-HH24.MI.SS."000000"')
    WHERE
    (BUSINESS_UNIT,RECONCILE_DT,GE_INVENTORY_SOURC,TAG_NUMBER,ASSET_ID,SERIAL_ID_TR,S
    ERIAL_ID,GE_CUSTODIAN_PHY,CUSTODIAN,DEPTID_P,DEPTID,CHARTFIELD2,CHARTFIELD3,GE_GA
    P_RULE,SEQUENCENO) IN (
    SELECT DISTINCT B.BUSINESS_UNIT
    ,B.RECONCILE_DT
    ,B.GE_INVENTORY_SOURC
    ,B.TAG_NUMBER
    ,B.ASSET_ID
    ,B.SERIAL_ID_TR
    ,B.SERIAL_ID
    ,B.GE_CUSTODIAN_PHY
    ,B.CUSTODIAN
    ,B.DEPTID_P
    ,B.DEPTID
    ,B.CHARTFIELD2
    ,B.CHARTFIELD3
    ,B.GE_GAP_RULE
    ,B.SEQUENCENO
    FROM PS_GE_GAPS_TAO A
    , PS_GE_GAPS_INV B
    WHERE A.BUSINESS_UNIT = B.BUSINESS_UNIT
    AND (A.RECONCILE_DT = B.RECONCILE_DT
    OR (A.RECONCILE_DT IS NULL
    AND B.RECONCILE_DT IS NULL))
    AND A.GE_GAP_RULE = B.GE_GAP_RULE
    AND A.SEQUENCENO = B.SEQUENCENO
    AND A.GE_INVENTORY_SOURC = B.GE_INVENTORY_SOURC
    AND A.TAG_NUMBER = B.TAG_NUMBER
    AND A.ASSET_ID = B.ASSET_ID
    AND A.SERIAL_ID_TR = B.SERIAL_ID_TR
    AND A.SERIAL_ID = B.SERIAL_ID
    AND A.GE_CUSTODIAN_PHY = B.GE_CUSTODIAN_PHY
    AND A.CUSTODIAN = B.CUSTODIAN
    AND A.DEPTID_P = B.DEPTID_P
    AND A.DEPTID = B.DEPTID
    AND A.CHARTFIELD2 = B.CHARTFIELD2
    AND A.CHARTFIELD3 = B.CHARTFIELD3
    AND A.BUSINESS_UNIT = %Bind(BUSINESS_UNIT)
    AND A.RECONCILE_DT = %Bind(RECONCILE_DT)
    AND A.PROCESS_INSTANCE =%ProcessInstance)
    Second Sql :
    INSERT INTO PS_GE_GAPS_INV (BUSINESS_UNIT
    , RECONCILE_DT
    , GE_GAP_RULE
    , SEQUENCENO
    , GE_INVENTORY_SOURC
    , TAG_NUMBER
    , ASSET_ID
    , SERIAL_ID_TR
    , SERIAL_ID
    , GE_CUSTODIAN_PHY
    , CUSTODIAN
    , VENDOR_ID
    , DEPTID_P
    , DEPTID
    , CHARTFIELD2
    , CHARTFIELD3
    , GE_GAP_STATUS
    , CERTMESSAGE
    , LAST_DTTM_UPDATE
    , COMMENT1
    , ASSET_STATUS
    , DESCR1
    , DESCR
    , NAME1_AC
    , NAME1
    , CATEGORY_DESCR
    , CATEGORY
    , OPERATING_UNIT_TO
    , OPERATING_UNIT
    , PROJECT_ID_P
    , PROJECT_ID
    , PRODUCT_TO
    , PRODUCT
    , INV_ITEM_ID
    , ITEM_FIELD_C30_B
    , ITEM_FIELD_C30_C)
    SELECT DISTINCT B.BUSINESS_UNIT
    , B.RECONCILE_DT
    , B.GE_GAP_RULE
    , B.SEQUENCENO
    , B.GE_INVENTORY_SOURC
    , B.TAG_NUMBER
    , B.ASSET_ID
    , B.SERIAL_ID_TR
    , B.SERIAL_ID
    , B.GE_CUSTODIAN_PHY
    , B.CUSTODIAN
    , B.VENDOR_ID
    , B.DEPTID_P
    , B.DEPTID
    , B.CHARTFIELD2
    , B.CHARTFIELD3
    , B.GE_GAP_STATUS
    , B.CERTMESSAGE
    , B.LAST_DTTM_UPDATE
    , B.COMMENT1
    , B.ASSET_STATUS
    , B.DESCR1
    , B.DESCR
    , B.NAME1_AC
    , B.NAME1
    , B.CATEGORY_DESCR
    , B.CATEGORY
    , B.OPERATING_UNIT_TO
    , B.OPERATING_UNIT
    , B.PROJECT_ID_P
    , B.PROJECT_ID
    , B.PRODUCT_TO
    , B.PRODUCT
    , B.INV_ITEM_ID
    , B.ITEM_FIELD_C30_B
    , B.ITEM_FIELD_C30_C
    FROM PS_GE_GAPS_TAO B
    WHERE B.BUSINESS_UNIT = %Bind(BUSINESS_UNIT)
    AND B.RECONCILE_DT =%Bind(RECONCILE_DT)
    AND NOT EXISTS (
    SELECT 'X'
    FROM PS_GE_GAPS_INV A
    WHERE B.BUSINESS_UNIT = A.BUSINESS_UNIT
    AND (B.RECONCILE_DT = A.RECONCILE_DT
    OR (B.RECONCILE_DT IS NULL
    AND A.RECONCILE_DT IS NULL))
    AND B.GE_GAP_RULE = A.GE_GAP_RULE
    AND B.SEQUENCENO = A.SEQUENCENO
    AND B.GE_INVENTORY_SOURC = A.GE_INVENTORY_SOURC
    AND B.TAG_NUMBER = A.TAG_NUMBER
    AND B.ASSET_ID = A.ASSET_ID
    AND B.SERIAL_ID_TR = A.SERIAL_ID_TR
    AND B.SERIAL_ID = A.SERIAL_ID
    AND B.GE_CUSTODIAN_PHY = A.GE_CUSTODIAN_PHY
    AND B.CUSTODIAN = A.CUSTODIAN
    AND B.DEPTID_P = A.DEPTID_P
    AND B.DEPTID = A.DEPTID
    AND B.CHARTFIELD2 = A.CHARTFIELD2
    AND B.CHARTFIELD3 = A.CHARTFIELD3)
    Third Sql :
    INSERT INTO PS_GE_GAPST_TAO (BUSINESS_UNIT
    , RECONCILE_DT
    , GE_GAP_RULE
    , SEQUENCENO
    , GE_INVENTORY_SOURC
    , TAG_NUMBER
    , ASSET_ID
    , SERIAL_ID_TR
    , GE_CUSTODIAN_PHY
    , SERIAL_ID
    , CUSTODIAN
    , DEPTID_P
    , DEPTID
    , CHARTFIELD2
    , CHARTFIELD3
    , PROCESS_INSTANCE
    , GE_GAP_STATUS
    , CERTMESSAGE
    , LAST_DTTM_UPDATE
    , COMMENT1
    , ASSET_STATUS
    , DESCR1
    , DESCR
    , VENDOR_ID
    , NAME1_AC
    , NAME1
    , CATEGORY_DESCR
    , CATEGORY
    , OPERATING_UNIT_TO
    , OPERATING_UNIT
    , PROJECT_ID_P
    , PROJECT_ID
    , PRODUCT_TO
    , PRODUCT
    , INV_ITEM_ID
    , ITEM_FIELD_C30_B
    , ITEM_FIELD_C30_C)
    SELECT DISTINCT BUSINESS_UNIT
    , RECONCILE_DT
    , GE_GAP_RULE
    , SEQUENCENO
    , GE_INVENTORY_SOURC
    , TAG_NUMBER
    , ASSET_ID
    , SERIAL_ID_TR
    , GE_CUSTODIAN_PHY
    , SERIAL_ID
    , CUSTODIAN
    , DEPTID_P
    , DEPTID
    , CHARTFIELD2
    , CHARTFIELD3
    , %ProcessInstance
    , GE_GAP_STATUS
    , CERTMESSAGE
    , LAST_DTTM_UPDATE
    , COMMENT1
    , ASSET_STATUS
    , DESCR1
    , DESCR
    , VENDOR_ID
    , NAME1_AC
    , NAME1
    , CATEGORY_DESCR
    , CATEGORY
    , OPERATING_UNIT_TO
    , OPERATING_UNIT
    , PROJECT_ID_P
    , PROJECT_ID
    , PRODUCT_TO
    , PRODUCT
    , INV_ITEM_ID
    , ITEM_FIELD_C30_B
    , ITEM_FIELD_C30_C
    FROM ps_ge_gaps_inv B
    WHERE b.business_unit = %Bind(BUSINESS_UNIT)
    AND b.reconcile_dt =%Bind(RECONCILE_DT)
    AND NOT EXISTS (
    SELECT 'X'
    FROM ps_ge_gaps_tao a
    WHERE A.BUSINESS_UNIT = B.BUSINESS_UNIT
    AND (A.RECONCILE_DT = B.RECONCILE_DT
    OR (A.RECONCILE_DT IS NULL
    AND B.RECONCILE_DT IS NULL))
    AND A.GE_GAP_RULE = B.GE_GAP_RULE
    AND A.SEQUENCENO = B.SEQUENCENO
    AND A.GE_INVENTORY_SOURC = B.GE_INVENTORY_SOURC
    AND A.TAG_NUMBER = B.TAG_NUMBER
    AND A.ASSET_ID = B.ASSET_ID
    AND A.SERIAL_ID_TR = B.SERIAL_ID_TR
    AND A.SERIAL_ID = B.SERIAL_ID
    AND A.GE_CUSTODIAN_PHY = B.GE_CUSTODIAN_PHY
    AND A.CUSTODIAN = B.CUSTODIAN
    AND A.DEPTID_P = B.DEPTID_P
    AND A.DEPTID = B.DEPTID
    AND A.CHARTFIELD2 = B.CHARTFIELD2
    AND A.CHARTFIELD3 = B.CHARTFIELD3 )
    Best Regards,
    Bala

    Are the statistics on your temp table up to date?. Either add an %UpdateStats SQL step after loading the temp table, or check the following notes if your database is Oracle and is a relatively current version:
    pscbo_stats - Improving Statistics in Oracle RDBMS for PeopleSoft Enterprise [ID 1322888.1]
    E-ORA PeopleSoft Enterprise Performance on Oracle 11g Database [ID 1460735.1]
    Regards,
    Bob

  • Need help pl/sql function body returning SQL query - Reports

    I need help with Grouping by on a report that I developed in my application.
    I have posted my Code in
    Apex.oracle.com
    workspace : c a s e _ m a n a g e m e n t
    User Id : public
    Password : public
    I need help on Page 38 Reports.
    I get blank lines when I do break by first , second and third columns on the reports attribute.
    So I think I have to write "group by " or Distinct in side the SQL query. But not sure how to do it there.
    Thank you

    Is this an APEX question, then try here:
    Oracle Application Express (APEX)
    Is this an Oracle Reports question, then try here:
    Reports
    Is this an SQL question:
    Please provide sample data and expected output. Also please show what you have tried already.

  • Need Help On SQL Statement

    I am using Sybase as my back end database. I need help on my SQL statement regarding datetime. The datetime is store as a 9 digit integer in the database (...I believe it is a Decimal(30,6) format, let me know if I am wrong).
    If I do this, "select * from mytable;" It works out fine (except I don't know what the date means e.g. 998919534)
    If I do this, "select * from mytable where datetime_col < '9/5/2002' ; I got an error. I even tried '9/5/02 11:00 000 am' but it didn't help.
    How do I specify a date or datetime in my query?
    Thanks in advance.

    I execute the sql statement
    select * from mytable where datetim_col < convert(datetime, '3/4/2002', 101) ;
    I got mix result. I got an error message "cannot convert 10375584 to a date.
    Yet, he statistics window of the I-sql says
    "estimated 493 rows in query (I/O estimate 87)
    PLan> mytable (seq)"
    It looks like I my the SQL statement is correct and then the system can't display it in the Data window.
    Any thought ?

  • Need help for sql statement

    Hi,
    Need help to write sql statement.
    create table t_dt ( dt_start date, dt_end date, amount number);
    insert into t_dt values('1-Jan-10','10-Feb-10',12);
    insert into t_dt values('11-Feb-10','10-Mar-10',10);
    insert into t_dt values('11-Mar-10','20-Apr-10',8);
    insert into t_dt values('21-Apr-10','28-Jun-10',10);
    insert into t_dt values('29-Jun-10','20-Sep-10',10);
    insert into t_dt values('21-Sep-10','10-Oct-10',10);
    insert into t_dt values('11-Oct-10','31-Dec-10',8);
    insert into t_dt values('1-Jan-11','10-Feb-11',8);
    insert into t_dt values('11-Feb-11','10-Mar-11',7);
    insert into t_dt values('11-Mar-11','20-Apr-11',6);
    insert into t_dt values('21-Apr-11','28-Jun-11',6);
    insert into t_dt values('29-Jun-11','20-Sep-11',6);
    insert into t_dt values('21-Sep-11','10-Oct-11',4);
    insert into t_dt values('11-Oct-11','31-Dec-11',8);
    Result should be like below..
    dt_start     dt_end     Amount
    1-Jan-10     10-Feb-10     12
    11-Feb-10     10-Mar-10     10
    11-Mar-10     20-Apr-10     8
    21-Apr-10     10-Oct-10     10
    11-Oct-10     10-Feb-11     8
    11-Feb-11     10-Mar-11     7
    11-Mar-11     20-Sep-11     6
    21-Sep-11     10-Oct-11     4
    11-Oct-11     31-Dec-11     8
    Just to explain the example, take a row with start date as 21-Apr-10 in the above insert statements, since it has the same amount for next two rows (i.e. with start date '29-Jun-10' and '21-Sep-10') these 3 rows should be converted to represent only 1 row in the result and the start date and end date should be changed per the result shown above.
    Thanks.

    Hello
    I think this gives yuo what you need....
    SELECT
        MIN(dt_start),
        MAX(dt_end),
        amount
    FROM
        (   SELECT
                dt_start,
                dt_end,
                MAX(marker) OVER(ORDER BY dt_start) marker,
                amount
            FROM
                    Select
                        dt_start,
                        dt_end,
                        amount,
                        CASE
                            WHEN LAG(amount) OVER(ORDER BY dt_start) <> amount THEN
                                ROW_NUMBER() OVER(ORDER BY dt_start)
                        END marker
                    from t_dt
    GROUP BY
         amount,
         marker
    order by     
         MIN(dt_start)
    MIN(DT_START)        MAX(DT_END)              AMOUNT
    01-JAN-2010 00:00:00 10-FEB-2010 00:00:00         12
    11-FEB-2010 00:00:00 10-MAR-2010 00:00:00         10
    11-MAR-2010 00:00:00 20-APR-2010 00:00:00          8
    21-APR-2010 00:00:00 10-OCT-2010 00:00:00         10
    11-OCT-2010 00:00:00 10-FEB-2011 00:00:00          8
    11-FEB-2011 00:00:00 10-MAR-2011 00:00:00          7
    11-MAR-2011 00:00:00 20-SEP-2011 00:00:00          6
    21-SEP-2011 00:00:00 10-OCT-2011 00:00:00          4
    11-OCT-2011 00:00:00 31-DEC-2011 00:00:00          8
    9 rows selected.HTH
    David
    Edited by: Bravid on Feb 23, 2012 12:08 PM
    Beaten to it by Frank! :-)

  • Need help on SQL Statement for UDF

    Hi,
    as I am not so familiar with SQL statements on currently selected values, I urgently need help.
    The scenario looks as follows:
    I have defined two UDFs named Subgroup1 and Subgroup2 which represent the subgroups dependent on my article groups. So for example: When the user selects article group "pianos", he only sees the specific subgroups like "new pianos" and "used pianos" in field "Subgroup1". After he has selected one of these specific values, he sees only the specific sub-subgroups in field "Subgroup2", like "used grand pianos".
    I have defined UDTs for both UDFs. The UDT for field "Subgroup1" has a UDF called "ArticleGroup" which represents the relation to the article group codes. The UDT for field "Subgroup2" has a UDF called "Subgroup1" which represents the relation to the subgroups one level higher.
    The SQL statement for the formatted search in field "Subgroup1" looks as follows:
    SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP1]  T0 WHERE T0.[U_ArticleGroup]  = (SELECT $[OITM.ItmsGrpCod])
    It works fine.
    However, I cannot find the right statement for the formatted search in field "Subgroup2".
    Unfortunately this does NOT WORK:
    SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2]  T0 WHERE T0.[U_Subgroup1]  = (SELECT $[OITM.U_Subgroup1])
    I tried a lot of others that didn't work either.
    Then I tried the following one:
    SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2]  T0 WHERE T0.[U_Subgroup1] = (SELECT T1.[Code] FROM [dbo].[@B_SUBGROUP1] T1 WHERE T1.[U_ArticleGroup] = (SELECT $[OITM.ItmsGrpCod]))
    Unfortunately that only works as long as there is only one specific subgroup1 for the selected article group.
    I would be sooooo happy if there is anyone who can tell me the correct statement for my second UDF!
    Thanks so much in advance!!!!
    Edited by: Corinna Hochheim on Jan 18, 2010 10:16 PM
    Please ignore the "http://" in the above statements - it is certainly not part of my SQL.
    Please also ignore the strikes.

    Hello Dear,
    Use the below queries to get the values:
    Item Sub Group on the basis of Item Group
    SELECT T0.[Name] FROM [dbo].[@SUBGROUP]  T0 WHERE T0.[U_GroupCod] =$[OITM.ItmsGrpCod]
    Item Sub Group 1 on the basis of item sub group
    SELECT T0.[Name] FROM [dbo].[@SUBGROUP1]  T0 WHERE T0.[U_SubGrpCod]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP]  T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp])
    Sub group 2 on the basis of sub group 1
    SELECT T0.[Name] FROM [dbo].[@SUBGROUP2]  T0 WHERE T0.[U_SubGrpCod1]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP1]  T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp1])
    this will help you.
    regards,
    Neetu

  • Need help regarding sql query

    hii All
    I need help for pl/sql function.
    I build a function for monthly attendance all employees.
    but now i want to show all Sundays with 'S' and others respectively 'P' and 'A'.
    Currently Sunday also shows 'A'
    So please help
    SQL queries ... like
    SELECT DISTINCT AL.USERNAME,
    CASE WHEN DAY1 =1 THEN 'P' ELSE 'A' END DAY1,
    CASE WHEN DAY2 =1 THEN 'P' ELSE 'A' END DAY2,
    CASE WHEN DAY3 =1 THEN 'P' ELSE 'A' END DAY3,
    CASE WHEN DAY31 =1 THEN 'P' ELSE 'A' END DAY31
    FROM
    SELECT DISTINCT USERNAME, SUM(CASE WHEN
    fromdt=TRUNC(L.LOGIN_DATE) THEN
    1
    ELSE
    0
    END) DAY1
    ,SUM(CASE WHEN
    fromdt +1=TRUNC(L.LOGIN_DATE) THEN
    1
    ELSE
    0
    END) DAY2,
    SUM(CASE WHEN
    fromdt+30=TRUNC(L.LOGIN_DATE) THEN
    1
    ELSE
    0
    END) DAY31
    FROM ( SELECT DISTINCT TRUNC(LOGIN_DATE)LOGIN_DATE ,USERNAME FROM FCDM_AUDIT_TRAIL_NEW WHERE
    TRUNC(LOGIN_DATE) BETWEEN fromdt AND todt
    -- to_date( login_date, 'dd-mom-yyyy') between to_date( fromdt, 'dd-mom-yyyy') and to_date( todt, 'dd-mom-yyyy')
    ) L
    GROUP BY USERNAME
    ) AL;
    how can i show matched Sundays and show with 'SUN' or 'S'
    Regards
    vij..

    Try this way:
    SELECT USERNAME,
           MAX(CASE WHEN to_char(fromdt,'d')='1' and fromdt=TRUNC(L.LOGIN_DATE) THEN 'S'
                    WHEN to_char(fromdt,'d')!='1' and fromdt=TRUNC(L.LOGIN_DATE) THEN 'P'
                    ELSE 'A') DAY1,
           MAX(CASE WHEN to_char(fromdt+1,'d')='1' and fromdt+1=TRUNC(L.LOGIN_DATE) THEN 'S'
                    WHEN to_char(fromdt+1,'d')!='1' and fromdt+1=TRUNC(L.LOGIN_DATE) THEN 'P'
                    ELSE 'A') DAY2,
           MAX(CASE WHEN to_char(fromdt+30,'d')='1' and fromdt+30=TRUNC(L.LOGIN_DATE) THEN 'S'
                    WHEN to_char(fromdt+30,'d')!='1' and fromdt+30=TRUNC(L.LOGIN_DATE) THEN 'P'
                    ELSE 'A') DAY31
    FROM
    (SELECT DISTINCT TRUNC(LOGIN_DATE) LOGIN_DATE,
            USERNAME
       FROM FCDM_AUDIT_TRAIL_NEW
      WHERE TRUNC(LOGIN_DATE) BETWEEN fromdt AND todt
    ) L
    Group by USERNAME
    ;Max
    http://oracleitalia.wordpress.com

Maybe you are looking for

  • Wow!  No servers connecting after 10.5.1 upgrade through software update

    Just installed 10.5.1 update and cannot now connect to any smb/cifs or afp shares - after a delay after I select a server, or click the (connect as...) button, I get the spinning ball. Then the Finder restarts. I cannot connect to any shared services

  • How to capture the data within the given range of maximum and minimum values ? from csv files

    My requirement, 1. Here, the user will provide the range like maximum and minimum values, based on this range, the VI should capture the data within the given range. ( from CSV file as attached ) 2. Then VI should calcluate the average value for capt

  • Need a help on Update statement

    Hi All, I Need a help in updating a table column. PFB my requirement. Table1 ItemID OrgId       Date 1       82     12/sep/2012    2       82     25/oct/2012 3       82     17/Nov/2012 4     82     22/Jan/2013 5     82     26/sep/2012 Table2 Itemid  

  • HT2305 while trying to update my phone its just frozen

    I was updating my phone I dont know what happened it froze on a screen where i see the USB and itunes

  • Lost my Camera and motion paths

    Help! I saved and closed a project, and when I re-opened it later, i can't see my camera or motion paths. The paths tracked over several photographs, and while I can see the photos in perspective view, they do not show up in any 3D angles or camera v