Please help me tuning this query...

Hi all,
Can any body suggest some changes (synthatic) so that it can improve its performance... taking too much time...
This is a query used in oracle report...
SELECT  distinct cc.seg1,cc.seg2,cc.seg3,cc.seg4,cc.seg5,cc.seg6,cc.seg7,cc.seg8,cc.code_combination_id code_comb_id,
         r.flex_validation_rule_name cv_rule,gl.currency_code currency1,                                          
         (NVL (gjl.accounted_dr, 0) - NVL (gjl.accounted_cr, 0)) trans_amount,
         gjh.doc_sequence_value doc_num,
         gjs.user_je_source_name je_source, gjc.user_je_category_name je_category,
         fu.user_name last_updated_by,(NVL (gb.begin_balance_dr, 0)
               - NVL (gb.begin_balance_cr, 0))
               + (NVL (gb.period_net_dr_beq, 0)
               - NVL (gb.period_net_cr_beq, 0)) balance,
         gjh.last_update_date last_updated_date,gjl.effective_date
    FROM gl_code_combinations cc,
         fnd_flex_vdation_rules_vl r,
         fnd_flex_validation_rule_lines l,
         gl_je_headers gjh,
         gl_je_lines gjl,
         gl_balances gb,
         fnd_user fu,
         gl_je_categories gjc,
         gl_je_sources gjs,
         gl_ledgers gl
     WHERE cc.enabled_flag = 'Y'
     AND NVL (cc.end_date_active, SYSDATE + 1) > SYSDATE
     AND cc.chart_of_accounts_id = :p_chart_of_accounts_id
     AND r.id_flex_num = cc.chart_of_accounts_id
     AND r.id_flex_code = 'GL#'
     AND r.application_id = 101
     AND gjs.je_source_name=gjh.je_source
     AND gjc.je_category_name=gjh.je_category
     AND l.application_id = r.application_id
     AND gb.code_combination_id=cc.code_combination_id
     AND gjh.period_name=gb.period_name
     AND r.enabled_flag = 'Y'
     AND NVL (r.end_date_active, SYSDATE + 1) > SYSDATE
     AND l.id_flex_code = r.id_flex_code
     AND l.id_flex_num = r.id_flex_num
     AND l.flex_validation_rule_name = r.flex_validation_rule_name
     AND l.include_exclude_indicator = 'E'
     AND gjl.code_combination_id = gb.code_combination_id
     AND gjh.je_header_id = gjl.je_header_id
     AND gjh.status = 'P'
     AND gl.ledger_id=gjh.ledger_id
     and gl.ledger_id=:p_ledger_id
     AND gjh.last_updated_by = fu.user_id
     and  (gjh.last_update_date,gjl.last_update_date)=(
            SELECT MAX (a.last_update_date) ,MAX(b.last_update_date)
              FROM gl_je_headers a, gl_je_lines b
             WHERE b.code_combination_id = cc.code_combination_id
               AND a.je_header_id = b.je_header_id
               AND a.status = 'P'
               AND ROWNUM = 1)
     and (NVL (gjl.accounted_dr, 0) - NVL (gjl.accounted_cr, 0))=(select (NVL (accounted_dr, 0) - NVL (accounted_cr, 0)) from gl_je_lines
       where  je_header_id=gjh.je_header_id and code_combination_id=cc.code_combination_id and period_name=gjh.period_name and
       last_update_date=gjh.last_update_date and rownum=1)
    and  (NVL (gb.begin_balance_dr, 0)
               - NVL (gb.begin_balance_cr, 0))
               + (NVL (gb.period_net_dr_beq, 0)
               - NVL (gb.period_net_cr_beq, 0))=(select max((NVL (begin_balance_dr, 0)
               - NVL (begin_balance_cr, 0))
               + (NVL (period_net_dr_beq, 0)
               - NVL (period_net_cr_beq, 0))) from gl_balances where code_combination_id=cc.code_combination_id
               and period_name=gb.period_name)  
       and gjl.description=(select description from gl_je_lines where  code_combination_id=cc.code_combination_id and
                              je_header_id=gjh.je_header_id and period_name=gb.period_name and rownum=1)                    
     AND cc.seg1 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 1, 3),
                                  cc.seg1
                         AND NVL (SUBSTR (l.concatenated_segments_high, 1, 3),
                                  cc.seg1
     AND cc.seg2 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 5, 4),
                                  cc.seg2
                         AND NVL (SUBSTR (l.concatenated_segments_high, 5, 4),
                                  cc.seg2
     AND cc.seg3 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 10, 4),
                                  cc.segt3
                         AND NVL (SUBSTR (l.concatenated_segments_high, 10, 4),
                                  cc.seg3
     AND cc.seg4 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 15, 3),
                                  cc.seg4
                         AND NVL (SUBSTR (l.concatenated_segments_high, 15, 3),
                                  cc.seg4
     AND cc.seg5 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 19, 6),
                                  cc.seg5
                         AND NVL (SUBSTR (l.concatenated_segments_high, 19, 6),
                                  cc.seg5
     AND cc.seg6 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 26, 4),
                                  cc.segment6
                         AND NVL (SUBSTR (l.concatenated_segments_high, 26, 4),
                                  cc.seg6
     AND cc.seg7 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 31, 6),
                                  cc.seg7
                         AND NVL (SUBSTR (l.concatenated_segments_high, 31, 6),
                                  cc.seg7
     AND cc.seg8 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 38, 6),
                                  cc.seg8
                         AND NVL (SUBSTR (l.concatenated_segments_high, 38, 6),
                                  cc.seg8)Thanks for help
asp

Dear all,
the folliwing is explain plan for above query...
<ExplainPlan>
- <PlanElement object_ID="0" id="0" operation="SELECT STATEMENT" optimizer="ALL_ROWS" cost="1,417" cardinality="1" bytes="477" cpu_cost="263,995,086" io_cost="1,385" time="18">
- <PlanElements>
- <PlanElement object_ID="0" id="1" operation="HASH" option="UNIQUE" cost="1,417" cardinality="1" bytes="477" cpu_cost="263,995,086" io_cost="1,385" time="18">
- <PlanElements>
- <PlanElement object_ID="0" id="2" operation="FILTER" filter_predicates="("GJH"."LAST_UPDATE_DATE","GJL"."LAST_UPDATE_DATE")= (SELECT MAX("A"."LAST_UPDATE_DATE"),MAX("B"."LAST_UPDATE_DATE") FROM "GL"."GL_JE_LINES" "B","GL"."GL_JE_HEADERS" "A" WHERE ROWNUM=1 AND "A"."JE_HEADER_ID"="B"."JE_HEADER_ID" AND "A"."STATUS"='P' AND "B"."CODE_COMBINATION_ID"=:B1) AND NVL("GJL"."ACCOUNTED_DR",0)-NVL("GJL"."ACCOUNTED_CR",0)= (SELECT NVL("ACCOUNTED_DR",0)-NVL("ACCOUNTED_CR",0) FROM "GL"."GL_JE_LINES" "GL_JE_LINES" WHERE ROWNUM=1 AND "PERIOD_NAME"=:B2 AND "CODE_COMBINATION_ID"=:B3 AND "JE_HEADER_ID"=:B4 AND "LAST_UPDATE_DATE"=:B5) AND NVL("GB"."BEGIN_BALANCE_DR",0)-NVL("GB"."BEGIN_BALANCE_CR",0)+(NVL("GB"."PERIOD_NET_DR_BEQ",0)-NVL("GB"."PERIOD_NET_CR_BEQ",0))= (SELECT MAX(NVL("BEGIN_BALANCE_DR",0)-NVL("BEGIN_BALANCE_CR",0)+(NVL("PERIOD_NET_DR_BEQ",0)-NVL("PERIOD_NET_CR_BEQ",0))) FROM "GL"."GL_BALANCES" "GL_BALANCES" WHERE "PERIOD_NAME"=:B6 AND "CODE_COMBINATION_ID"=:B7)">
- <PlanElements>
- <PlanElement object_ID="0" id="3" operation="NESTED LOOPS" cost="1,262" cardinality="1" bytes="477" cpu_cost="254,376,045" io_cost="1,231" time="16">
- <PlanElements>
- <PlanElement object_ID="0" id="4" operation="NESTED LOOPS" cost="1,261" cardinality="1" bytes="464" cpu_cost="254,366,853" io_cost="1,230" time="16">
- <PlanElements>
- <PlanElement object_ID="0" id="5" operation="NESTED LOOPS" cost="1,260" cardinality="1" bytes="433" cpu_cost="254,357,622" io_cost="1,229" time="16">
- <PlanElements>
- <PlanElement object_ID="0" id="6" operation="NESTED LOOPS" cost="1,259" cardinality="1" bytes="402" cpu_cost="254,348,331" io_cost="1,228" time="16">
- <PlanElements>
- <PlanElement object_ID="0" id="7" operation="NESTED LOOPS" cost="1,258" cardinality="1" bytes="350" cpu_cost="254,337,522" io_cost="1,227" time="16">
- <PlanElements>
- <PlanElement object_ID="0" id="8" operation="NESTED LOOPS" cost="1,239" cardinality="1" bytes="273" cpu_cost="254,166,811" io_cost="1,208" time="15">
- <PlanElements>
- <PlanElement object_ID="0" id="9" operation="HASH JOIN" cost="1,184" cardinality="1" bytes="248" cpu_cost="253,727,112" io_cost="1,153" access_predicates=""B"."ID_FLEX_NUM"="CC"."CHART_OF_ACCOUNTS_ID"" filter_predicates=""CC"."SEGMENT1">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",1,3),"CC"."SEGMENT1") AND "CC"."SEGMENT1"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",1,3),"CC"."SEGMENT1") AND "CC"."SEGMENT2">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",5,4),"CC"."SEGMENT2") AND "CC"."SEGMENT2"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",5,4),"CC"."SEGMENT2") AND "CC"."SEGMENT3">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",10,4),"CC"."SEGMENT3") AND "CC"."SEGMENT3"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",10,4),"CC"."SEGMENT3") AND "CC"."SEGMENT4">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",15,3),"CC"."SEGMENT4") AND "CC"."SEGMENT4"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",15,3),"CC"."SEGMENT4") AND "CC"."SEGMENT5">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",19,6),"CC"."SEGMENT5") AND "CC"."SEGMENT5"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",19,6),"CC"."SEGMENT5") AND "CC"."SEGMENT6">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",26,4),"CC"."SEGMENT6") AND "CC"."SEGMENT6"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",26,4),"CC"."SEGMENT6") AND "CC"."SEGMENT7">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",31,6),"CC"."SEGMENT7") AND "CC"."SEGMENT7"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",31,6),"CC"."SEGMENT7") AND "CC"."SEGMENT8">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",38,6),"CC"."SEGMENT8") AND "CC"."SEGMENT8"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",38,6),"CC"."SEGMENT8")" time="15">
- <PlanElements>
- <PlanElement object_ID="1" id="10" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VALIDATION_RULE_LINES" object_type="TABLE" object_instance="3" cost="3" cardinality="1" bytes="119" cpu_cost="49,909" io_cost="3" filter_predicates=""L"."INCLUDE_EXCLUDE_INDICATOR"='E'" time="1">
- <PlanElements>
- <PlanElement object_ID="0" id="11" operation="NESTED LOOPS" cost="6" cardinality="1" bytes="189" cpu_cost="75,588" io_cost="6" time="1">
- <PlanElements>
- <PlanElement object_ID="0" id="12" operation="NESTED LOOPS" cost="3" cardinality="1" bytes="70" cpu_cost="25,679" io_cost="3" time="1">
- <PlanElements>
- <PlanElement object_ID="0" id="13" operation="NESTED LOOPS" cost="3" cardinality="1" bytes="39" cpu_cost="23,779" io_cost="3" time="1">
- <PlanElements>
- <PlanElement object_ID="2" id="14" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_LEDGERS" object_type="TABLE" object_instance="10" cost="1" cardinality="1" bytes="8" cpu_cost="8,541" io_cost="1" time="1">
- <PlanElements>
  <PlanElement object_ID="3" id="15" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_LEDGERS_U2" object_type="INDEX (UNIQUE)" search_columns="1" cost="0" cardinality="1" cpu_cost="1,050" io_cost="0" access_predicates=""GL"."LEDGER_ID"=TO_NUMBER(:P_LEDGER_ID)" time="1" />
  </PlanElements>
  </PlanElement>
- <PlanElement object_ID="4" id="16" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VALIDATION_RULES" object_type="TABLE" object_instance="19" cost="2" cardinality="1" bytes="31" cpu_cost="15,238" io_cost="2" filter_predicates=""B"."ENABLED_FLAG"='Y' AND NVL("B"."END_DATE_ACTIVE",SYSDATE@!+1)>SYSDATE@!" time="1">
- <PlanElements>
  <PlanElement object_ID="5" id="17" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VALIDATION_RULES_U1" object_type="INDEX (UNIQUE)" search_columns="3" cost="1" cardinality="1" cpu_cost="7,321" io_cost="1" access_predicates=""B"."APPLICATION_ID"=101 AND "B"."ID_FLEX_CODE"='GL#' AND "B"."ID_FLEX_NUM"=TO_NUMBER(:P_CHART_OF_ACCOUNTS_ID)" time="1" />
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
  <PlanElement object_ID="6" id="18" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VDATION_RULES_TL_U1" object_type="INDEX (UNIQUE)" search_columns="5" cost="0" cardinality="1" bytes="31" cpu_cost="1,900" io_cost="0" access_predicates=""T"."APPLICATION_ID"=101 AND "T"."ID_FLEX_CODE"='GL#' AND "T"."ID_FLEX_NUM"=TO_NUMBER(:P_CHART_OF_ACCOUNTS_ID) AND "B"."FLEX_VALIDATION_RULE_NAME"="T"."FLEX_VALIDATION_RULE_NAME" AND "T"."LANGUAGE"=USERENV('LANG')" time="1" />
  </PlanElements>
  </PlanElement>
  <PlanElement object_ID="7" id="19" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VAL_RULE_LINES_N1" object_type="INDEX" search_columns="4" cost="1" cardinality="41" cpu_cost="16,371" io_cost="1" access_predicates=""L"."APPLICATION_ID"=101 AND "L"."ID_FLEX_CODE"='GL#' AND "L"."ID_FLEX_NUM"=TO_NUMBER(:P_CHART_OF_ACCOUNTS_ID) AND "L"."FLEX_VALIDATION_RULE_NAME"="B"."FLEX_VALIDATION_RULE_NAME"" time="1" />
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
  <PlanElement object_ID="8" id="20" operation="TABLE ACCESS" option="FULL" optimizer="ANALYZED" object_owner="GL" object_name="GL_CODE_COMBINATIONS" object_type="TABLE" object_instance="1" cost="1,177" cardinality="1,088" bytes="64,192" cpu_cost="249,419,570" io_cost="1,147" filter_predicates=""CC"."ENABLED_FLAG"='Y' AND "CC"."CHART_OF_ACCOUNTS_ID"=TO_NUMBER(:P_CHART_OF_ACCOUNTS_ID) AND NVL("CC"."END_DATE_ACTIVE",SYSDATE@!+1)>SYSDATE@!" time="15" />
  </PlanElements>
  </PlanElement>
- <PlanElement object_ID="9" id="21" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_BALANCES" object_type="TABLE" object_instance="6" cost="55" cardinality="52" bytes="1,300" cpu_cost="439,699" io_cost="55" time="1">
- <PlanElements>
  <PlanElement object_ID="10" id="22" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_BALANCES_N1" object_type="INDEX" search_columns="1" cost="2" cardinality="52" cpu_cost="25,693" io_cost="2" access_predicates=""GB"."CODE_COMBINATION_ID"="CC"."CODE_COMBINATION_ID"" time="1" />
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
- <PlanElement object_ID="11" id="23" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES" object_type="TABLE" object_instance="5" cost="19" cardinality="40" bytes="3,080" cpu_cost="170,710" io_cost="19" time="1">
- <PlanElements>
  <PlanElement object_ID="12" id="24" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES_N1" object_type="INDEX" search_columns="1" cost="2" cardinality="49" cpu_cost="24,693" io_cost="2" access_predicates=""GJL"."CODE_COMBINATION_ID"="GB"."CODE_COMBINATION_ID"" time="1" />
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
- <PlanElement object_ID="13" id="25" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_HEADERS" object_type="TABLE" object_instance="4" cost="1" cardinality="1" bytes="52" cpu_cost="10,809" io_cost="1" filter_predicates=""GJH"."STATUS"='P' AND "GJH"."LEDGER_ID"=TO_NUMBER(:P_LEDGER_ID) AND "GJH"."PERIOD_NAME"="GB"."PERIOD_NAME"" time="1">
- <PlanElements>
- <PlanElement object_ID="14" id="26" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_HEADERS_U1" object_type="INDEX (UNIQUE)" search_columns="1" cost="0" cardinality="1" cpu_cost="1,950" io_cost="0" access_predicates=""GJH"."JE_HEADER_ID"="GJL"."JE_HEADER_ID"" filter_predicates=""GJL"."DESCRIPTION"= (SELECT "DESCRIPTION" FROM "GL"."GL_JE_LINES" "GL_JE_LINES" WHERE ROWNUM=1 AND "PERIOD_NAME"=:B1 AND "CODE_COMBINATION_ID"=:B2 AND "JE_HEADER_ID"=:B3)" time="1">
- <PlanElements>
- <PlanElement object_ID="0" id="27" operation="COUNT" option="STOPKEY" filter_predicates="ROWNUM=1">
- <PlanElements>
- <PlanElement object_ID="11" id="28" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES" object_type="TABLE" object_instance="15" cost="5" cardinality="1" bytes="62" cpu_cost="39,168" io_cost="5" filter_predicates=""JE_HEADER_ID"=:B1" time="1">
- <PlanElements>
  <PlanElement object_ID="12" id="29" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES_N1" object_type="INDEX" search_columns="2" cost="3" cardinality="4" cpu_cost="22,364" io_cost="3" access_predicates=""CODE_COMBINATION_ID"=:B1 AND "PERIOD_NAME"=:B2" time="1" />
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
- <PlanElement object_ID="15" id="30" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_SOURCES_TL" object_type="TABLE" object_instance="16" cost="1" cardinality="2" bytes="62" cpu_cost="9,291" io_cost="1" time="1">
- <PlanElements>
  <PlanElement object_ID="16" id="31" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_SOURCES_TL_U1" object_type="INDEX (UNIQUE)" search_columns="2" cost="0" cardinality="1" cpu_cost="1,900" io_cost="0" access_predicates=""JE_SOURCE_NAME"="GJH"."JE_SOURCE" AND "LANGUAGE"=USERENV('LANG')" time="1" />
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
- <PlanElement object_ID="17" id="32" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_CATEGORIES_TL" object_type="TABLE" object_instance="17" cost="1" cardinality="2" bytes="62" cpu_cost="9,231" io_cost="1" time="1">
- <PlanElements>
  <PlanElement object_ID="18" id="33" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_CATEGORIES_TL_U1" object_type="INDEX (UNIQUE)" search_columns="2" cost="0" cardinality="1" cpu_cost="1,900" io_cost="0" access_predicates=""JE_CATEGORY_NAME"="GJH"."JE_CATEGORY" AND "LANGUAGE"=USERENV('LANG')" time="1" />
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
- <PlanElement object_ID="19" id="34" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_USER" object_type="TABLE" object_instance="7" cost="1" cardinality="1" bytes="13" cpu_cost="9,191" io_cost="1" time="1">
- <PlanElements>
  <PlanElement object_ID="20" id="35" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_USER_U1" object_type="INDEX (UNIQUE)" search_columns="1" cost="0" cardinality="1" cpu_cost="1,900" io_cost="0" access_predicates=""GJH"."LAST_UPDATED_BY"="FU"."USER_ID"" time="1" />
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
- <PlanElement object_ID="0" id="36" operation="SORT" option="AGGREGATE" cardinality="1" bytes="33">
- <PlanElements>
- <PlanElement object_ID="0" id="37" operation="COUNT" option="STOPKEY" filter_predicates="ROWNUM=1">
- <PlanElements>
- <PlanElement object_ID="0" id="38" operation="NESTED LOOPS" cost="69" cardinality="49" bytes="1,617" cpu_cost="624,699" io_cost="69" time="1">
- <PlanElements>
- <PlanElement object_ID="11" id="39" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES" object_type="TABLE" object_instance="12" cost="20" cardinality="49" bytes="882" cpu_cost="164,029" io_cost="20" time="1">
- <PlanElements>
  <PlanElement object_ID="12" id="40" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES_N1" object_type="INDEX" search_columns="1" cost="3" cardinality="49" cpu_cost="30,964" io_cost="3" access_predicates=""B"."CODE_COMBINATION_ID"=:B1" time="1" />
  </PlanElements>
  </PlanElement>
- <PlanElement object_ID="13" id="41" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_HEADERS" object_type="TABLE" object_instance="11" cost="1" cardinality="1" bytes="15" cpu_cost="9,401" io_cost="1" filter_predicates=""A"."STATUS"='P'" time="1">
- <PlanElements>
  <PlanElement object_ID="14" id="42" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_HEADERS_U1" object_type="INDEX (UNIQUE)" search_columns="1" cost="0" cardinality="1" cpu_cost="1,900" io_cost="0" access_predicates=""A"."JE_HEADER_ID"="B"."JE_HEADER_ID"" time="1" />
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
- <PlanElement object_ID="0" id="43" operation="COUNT" option="STOPKEY" filter_predicates="ROWNUM=1">
- <PlanElements>
- <PlanElement object_ID="11" id="44" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES" object_type="TABLE" object_instance="13" cost="5" cardinality="1" bytes="33" cpu_cost="39,068" io_cost="5" filter_predicates=""JE_HEADER_ID"=:B1 AND "LAST_UPDATE_DATE"=:B2" time="1">
- <PlanElements>
  <PlanElement object_ID="12" id="45" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES_N1" object_type="INDEX" search_columns="2" cost="3" cardinality="4" cpu_cost="22,364" io_cost="3" access_predicates=""CODE_COMBINATION_ID"=:B1 AND "PERIOD_NAME"=:B2" time="1" />
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
- <PlanElement object_ID="0" id="46" operation="SORT" option="AGGREGATE" cardinality="1" bytes="25">
- <PlanElements>
- <PlanElement object_ID="9" id="47" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_BALANCES" object_type="TABLE" object_instance="14" cost="6" cardinality="1" bytes="25" cpu_cost="45,399" io_cost="6" time="1">
- <PlanElements>
  <PlanElement object_ID="10" id="48" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_BALANCES_N1" object_type="INDEX" search_columns="2" cost="3" cardinality="2" cpu_cost="21,964" io_cost="3" access_predicates=""CODE_COMBINATION_ID"=:B1 AND "PERIOD_NAME"=:B2" time="1" />
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
  </PlanElements>
  </PlanElement>
  </ExplainPlan>Sorry this xml generated...
Regards
asp

Similar Messages

  • Please help to modifiy this query for better performance

    Please help to rewrite this query for better performance. This is taking long time to execute.
    Table t_t_bil_bil_cycle_change contains 1200000 rows and table t_acctnumberTab countains  200000 rows.
    I have created index on ACCOUNT_ID
    Query is shown below
    update rbabu.t_t_bil_bil_cycle_change a
       set account_number =
           ( select distinct b.account_number
             from rbabu.t_acctnumberTab b
             where a.account_id = b.account_id
    Table structure  is shown below
    SQL> DESC t_acctnumberTab;
    Name           Type         Nullable Default Comments
    ACCOUNT_ID     NUMBER(10)                            
    ACCOUNT_NUMBER VARCHAR2(24)
    SQL> DESC t_t_bil_bil_cycle_change;
    Name                    Type         Nullable Default Comments
    ACCOUNT_ID              NUMBER(10)                            
    ACCOUNT_NUMBER          VARCHAR2(24) Y    

    Ishan's solution is good. I would avoid updating rows which already have the right value - it's a waste of time.
    You should have a UNIQUE or PRIMARY KEY constraint on t_acctnumberTab.account_id
    merge rbabu.t_t_bil_bil_cycle_change a
    using
          ( select distinct account_number, account_id
      from  rbabu.t_acctnumberTab
          ) t
    on    ( a.account_id = b.account_id
           and decode(a.account_number, b.account_number, 0, 1) = 1
    when matched then
      update set a.account_number = b.account_number

  • Could you please help me make this query less complicated

    could you please help me make this query less complicated
    select t1.R_OBJECT_ID
    from dm_relation_sp a, ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID
    union all
    select t3.R_OBJECT_ID
    from ddt_resolution_sp t3
    where t3.R_OBJECT_ID in (select t2.child_id
    from dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    union all
    select t4.R_OBJECT_ID
    from ddt_resolution_sp t4
    where t4.R_OBJECT_ID in(
    select t3.child_id from dm_relation_sp t3
    where t3.parent_id in (
    select t2.child_id
    from asud_fsk.dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    and t3.relation_name = 'RESOLUTION_RELATION')
    union all
    select t5.R_OBJECT_ID
    from ddt_resolution_sp t5
    where t5.R_OBJECT_ID in
    (select t4.child_id
    from dm_relation_sp t4
    where t4.parent_id in(
    select t3.child_id from dm_relation_sp t3
    where t3.parent_id in (
    select t2.child_id
    from asud_fsk.dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    and t3.relation_name = 'RESOLUTION_RELATION')
    and t4.relation_name = 'RESOLUTION_RELATION')
    Edited by: user13025450 on 29.04.2010 16:23

    Hi,
    Welcome to the forum! You'll find that there are many qualified people (such as Tubby) willing to help you. Will you do what you can to help them? In order to simplify the query you posted,someone will first have to understand what it does, what the tables that it uses are like, and what tools you have to work with (that is, what version of Oracle, and any other software you are using). To actually test their ideas, people will need versions of your tables.
    Many people, if they spent enough time, might be able to figure out roughly what you are doing, make some tables themselves and test a solution. You can help with all of that. I assume you already know what the appliction is, and what this particular query is supposed to do: you don't have to figure out any of that, you just have to say it. You know what all your tables are, what the datatypes of all the columns are, and what kinds of data are in the tables: you don't have to guess at any of that.
    Describe what you're doing. Think about it: how do we know that
    SELECT  NULL
    FROM    dual;doesn't do what you want?
    Post CREATE TABLE and INSERT statements for a little sample data.
    Post the results that this query is supposed to produce from those results. (Is it producing the right output now? Then it should be easy to post the correct results.)
    Describe, as well as you can, how the present query is doing it.
    Format your existing code, so it's easy to see what the different branches of the UNION are, and what the main clauses are in each one.
    When posting formatted text (code or results) type these 6 characters
    \(all small letters, inside curly brackets) before and after each formatted section, to keep this site from compressing the spaces.
    Say what versions of Oracle (e.g. 10.2.0.3.0) and any other relevant software you are using.
    I know it's a lot of work, but it really helps. You can do it as well (probably better) than anyone else, and if you're unwilling to do it, why should anyone else be willing?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Query Issue in Creating a View....Please help me with this query..

    I would like to create a view on this table with four columns
    1. PN#_EXP_DATE
    2. PN#
    3. PN#_EFF_DATE
    4. PN#
    P_S_C     A_C     P     EXP_DT
    21698     13921     1     5/29/2009 3:15:41 PM     
    21698     13921     1     5/29/2009 3:54:57 PM     
    21698     1716656     4     5/29/2009 3:15:41 PM     
    21698     3217     3     5/29/2009 3:15:40 PM     
    21698     3217     3     5/29/2009 3:54:57 PM     
    21698     60559     2     5/29/2009 3:15:41 PM     
    21698     60559     2     5/29/2009 3:54:57 PM     
    I have a trigger on A, which inserts the DML records into B. (Table A and B structure is the almost the same,
                                       where table B will have one extra column exp_dt)
    NOw Table B can have records with same P_S_C and A_C columns and exp_dt will capture the history.
    for example: from the above sample data, let us take first two records..
    P_S_C     A_C     P     EXP_DT
    21698     13921     1     5/29/2009 3:15:41 PM     --- Record 1
    21698     13921     1     5/29/2009 3:54:57 PM     --- Record 2
    from this..
    Note: 1. Table A and Table C can be joined using A.P_S_C and C.R_C to get the start_date.
    2. PN# comes from table D. It contains numbers for the resp. weeks.
    3. PN#_EFF_DATE is the previous immediate previous date for that record in history table (Table B).
    I wanted the data like..
    ---- this is for the second record in the above..
    PN#_EXP_DATE PN# PN#_EFF_DATE PN#
    5/29/2009 3:54:57 PM     214 5/29/2009 3:15:41 PM     214
    ---- this is for the first record in the above..
    PN#_EXP_DATE PN# PN#_EFF_DATE PN#
    5/29/2009 3:54:41 PM     214 ( for this we should query the table C to get the
                        start_date, for this combinatation of P_S_C and A_C in table B
                             where B.P_S_C = C.A_C
                             and that value should be the EFF_DT for this record)
    Please help me with this....
    Thanks in advance..

    Hi All,
    select d.P# as "PN#_EXP_DATE", exp_date
    from daily_prd d, cbs1_assoc_hist b
    where to_char(d.day_date,'MM/DD/YYYY') = to_char(b.exp_date,'MM/DD/YYYY')
    and d.period_type = 'TIMEREPORT';
    This above query gives the output as follows:
    pn#_exp_date exp_date
    214     5/29/2009 3:15:40 PM
    214     5/29/2009 3:15:41 PM
    214          5/29/2009 3:15:41 PM
    214          5/29/2009 3:15:41 PM
    214          5/29/2009 3:54:57 PM
    214          5/29/2009 3:54:57 PM
    214          5/29/2009 3:54:57 PM
    This below is the data from history table (Table B).
    P_S_C     A_C PLACE EXP_DATE
    21698          3217          3     5/29/2009 3:15:40 PM     
    21698          13921          1     5/29/2009 3:15:41 PM     
    21698          1716656          4     5/29/2009 3:15:41 PM     
    21698          60559          2     5/29/2009 3:15:41 PM     
    21698          13921          1     5/29/2009 3:54:57 PM     
    21698          3217          3     5/29/2009 3:54:57 PM     
    21698          60559          2     5/29/2009 3:54:57 PM     
    I got the pn#_exp_date from the Table 'D', for the given exp_date from Table B.
    My question is again....
    CASE - 1
    from the given records above, I need to look for exp_date for the given same P_S_C and A_C.
    in this case we can take the example...
    P_S_C     A_C PLACE EXP_DATE
    21698          3217          3     5/29/2009 3:15:40 PM
    21698          3217          3     5/29/2009 3:54:57 PM
    In this case, the
    pn#_exp_date exp_date     pn#_eff_date eff_date
    214     5/29/2009 3:15:57 PM     < PN# corresponding to the     5/29/2009 3:15:40 PM
                        eff_date .>
                        <Basically the eff_date is
                        nothing but the exp_date only.
                        we should take the immediate before one.
    In this case, our eff_date is '5/29/2009 3:15:40 PM'.
    but how to get this.
    CASE - 2
    from the above sample data, consider this
    P_S_C     A_C PLACE EXP_DATE
    21698     1716656     4     5/29/2009 3:15:41 PM
    In this case, there is only one record for the P_S_C and A_C combination.
    The expected result :
    pn#_exp_date exp_date               pn#_eff_date eff_date
    214     5/29/2009 3:15:41 PM     < PN# corresponding to the     5/29/2009 3:15:40 PM
                        eff_date .>
                   <Basically the eff_date is
                   nothing but the exp_date only.
                        we should take the immediate before one.
    In this case to get the eff_date, we should query the Table 'C', to get the eff_date, which is START_DT column in this table.
    for this join B.P_S_C and C.R_C.
    Hope I am clear now..
    Thanks in advance.....

  • Hi Everyone...Please help me with this query...!

    Please Help me with this doubt as I am unable to understand the logic...behind this code. It's a begineer level code but I need to understand the logic so that I am able to grasp knowledge. Thank you all for being supportive. Please help me.
    //Assume class Demo is inherited from class SuperDemo...in other words class Demo extends SuperDemo
    //Volume is a method declared in SuperDemo which returns an integer value
    //weight is an integer vairable declared in the subclass which is Demo
    class Example
         public static void main(String qw[])
              Demo ob1=new Demo(3,5,7,9);
    //Calling Constructor of Demo which takes in 4 int parameters
              SuperDemo ob2=new SuperDemo();
              int vol;
              vol=ob1.volume();
              System.out.println("Volume of ob1 is " + vol);
              System.out.println("Weight of ob1 is " + ob1.weight);
              System.out.println();
              ob2=ob1;
    }Can someone please make me understand --- how is this possible and why !
    If the above statement is valid then why not this one "System.out.println(ob2.weight);"
    Thanks Thanks Thanks!

    u see the line wherein I am referencing the objectof
    a subclass to the superclass...right? then why we
    can't do System.out.println(ob2.weight)?You need to distinguish two things:
    - the type of the object, which determines with the
    object can do
    - the type of the reference to the object, which
    determines what you see that you can do
    Both don't necessarily have to match. When you use a
    SuperDemo reference (obj2) to access a Demo instance
    (obj1), for all you know, the instance behind obj2 is
    of type SuperDemo. That it's in reality of type Demo
    is unknown to you. And usually, you don't care -
    that's what polymorphism is about.
    So you have a reference obj2 of type SuperDemo.
    SuperDemo objects don't have weight, so you don't see
    it - even though it is there.So from ur explanation wat I understand is - Even though u reference a subclass object to a superclass, u will only be able to access the members which are declared in the superclass thru the same...right
    ?

  • Please help me constructing this query

    please help me .
         table a          
         ===========          
    transactionid     personname     year     dept
    r001          person1          y1     d1
    r002          person1          y2     d2
    r005          person3          y1     d2
    r004          person2          y2     d1
         table b     
         ===========     
    transactionid     personname     year
    r005          person3          y2
    r006          person4          y1
    r001          person1          y1
         outout should be like                         
         ======================                         
    transactionid     personname     year     dept               
    r001          person1          y1     d1     record present (combination of transactionid/personname/year)in table a from table b          
    r005          person3          y2     d2     (no data present in table a (transactionid/personname/year) from table b
    so it will retrive previous dept records for this person for this year so here d2)          
    r006          person4          y1     unknown     no data present for this person in table a so department will be unknown          
    table creation script
    =====================
    CREATE TABLE A
    TRANSACTIONID VARCHAR2(30 BYTE),
    PERSONNAME VARCHAR2(30 BYTE),
    YEAR VARCHAR2(30 BYTE),
    DEPT VARCHAR2(30 BYTE)
    SET DEFINE OFF;
    Insert into A
    (TRANSACTIONID, PERSONNAME, YEAR, DEPT)
    Values
    ('r001', 'person1', 'y1', 'd1');
    Insert into A
    (TRANSACTIONID, PERSONNAME, YEAR, DEPT)
    Values
    ('r002', 'person1', 'y2', 'd2');
    Insert into A
    (TRANSACTIONID, PERSONNAME, YEAR, DEPT)
    Values
    ('r004', 'person2', 'y2', 'd1');
    Insert into A
    (TRANSACTIONID, PERSONNAME, YEAR, DEPT)
    Values
    ('r005', 'person3', 'y1', 'd2');
    COMMIT;
    CREATE TABLE B
    TRANSACTIONID VARCHAR2(30 BYTE),
    PERSONNAME VARCHAR2(30 BYTE),
    YEAR VARCHAR2(30 BYTE)
    SET DEFINE OFF;
    Insert into B
    (TRANSACTIONID, PERSONNAME, YEAR)
    Values
    ('r001', 'person1', 'y1');
    Insert into B
    (TRANSACTIONID, PERSONNAME, YEAR)
    Values
    ('r006', 'person4', 'y1');
    Insert into B
    (TRANSACTIONID, PERSONNAME, YEAR)
    Values
    ('r005', 'person3', 'y2');
    COMMIT;

    Anirudha Dhopate wrote:
    Following query should work - Data magic:
    SQL> SELECT  *
      2    FROM  a
      3  /
    TRANSACTIONID        PERSONNAME YEAR  DEPT
    r001                 person1    2010  d1
    r002                 person1    2011  d2
    r004                 person2    2011  d1
    r005                 person3    2010  d2
    r001                 person1    2010  d2
    SQL> SELECT  *
      2    FROM  b
      3  /
    TRANSACTIONID        PERSONNAME YEAR
    r001                 person1    2010
    r006                 person4    2010
    r005                 person3    2011
    SQL> SELECT b.transactionid
      2        ,b.personname
      3        ,b.year
      4        ,a.dept
      5    FROM a
      6   RIGHT OUTER JOIN b
      7      ON ((a.transactionid = b.transactionid) AND
      8         (a.personname = b.personname) AND
      9         (a.year = b.year OR a.year = b.year - 1))
    10     ORDER BY b.transactionid
    11  /
    TRANSACTIONID        PERSONNAME YEAR  DEPT
    r001                 person1    2010  d1
    r001                 person1    2010  d2
    r005                 person3    2011  d2
    r006                 person4    2010
    SQL> select  b.transactionid,
      2          b.personname,
      3          b.year,
      4          max(a.dept) keep(dense_rank last order by a.year) dept
      5    from      b
      6          left join
      7              a
      8            on (
      9                    b.transactionid = a.transactionid
    10                and
    11                    b.personname = a.personname
    12                and
    13                    b.year >= a.year
    14               )
    15    group by b.transactionid,
    16             b.personname,
    17             b.year
    18  /
    TRANSACTIONID        PERSONNAME YEAR  DEPT
    r001                 person1    2010  d2
    r005                 person3    2011  d2
    r006                 person4    2010
    SQL> SY.

  • Please help me tune this query

    Hi,
    Could you please suggest how the below query can be tuned? At present the query takes an hour to execute for a single transaction.
    ===================================================================
    /* Formatted on 2009/07/27 17:44 (Formatter Plus v4.8.8) */
    SELECT 'x' x,
    SUBSTR (cn.trx_number, 1, INSTR (cn.trx_number, 'CN') - 1) invoice_num,
    DECODE (INSTR (cn.trx_number, 'CNT'),
    0, '¿¿¿¿¿¿¿¿ (CREDIT NOTE)',
    '¿¿¿¿¿¿¿¿ (CREDIT NOTE) / ¿¿¿¿¿¿¿¿¿¿¿'
    ) report_name,
    INSTR (cn.trx_number, 'CNT') v_or_nv,
    xxth_get_info.get_org_name (:org_id) head_office_name, lc.location_id,
    lc.location_code, lc.attribute1 tax_regis_number,
    lc.attribute2 tax_payer_id, lc.attribute14 branch_number,
    lc.attribute15 name_of_place_of_business,
    lc.address_line_1 || ' ' || lc.address_line_2 address_line1,
    lc.address_line_3 || ' ' || lc.region_1 address_line2,
    lc.region_2
    || ' '
    || lc.town_or_city
    || ' '
    || lc.postal_code
    || ' '
    || lc.country address_line3,
    cn.type_cn, cn.rac_bill_to_customer_name, cn.address1,
    cn.raa_bill_to_address3, cn.bill_to_site_use_id, cn.trx_date,
    cn.trx_number, cn.rac_bill_to_customer_num, cn.description,
    ABS (cn.extended_amount) extended_amount, ABS (cn.tax_amt) tax_amt,
    rc.trx_rec_number, rc.apply_date, rc.cash_receipt_id
    FROM ra_cust_trx_types cc,
    hr_locations_v lc,
    (SELECT b.cash_receipt_id, a.trx_number, b.trx_rec_number,
    b.apply_date
    FROM ar_payment_schedules a, ar_app_adj_v b,ar_cash_receipts c
    WHERE b.payment_schedule_id = a.payment_schedule_id
    AND c.cash_receipt_id=b.cash_receipt_id
    AND c.status='APP'
    AND b.CLASS = 'Payment'
    group by b.cash_receipt_id, a.trx_number, b.trx_rec_number,b.apply_date) rc,
    (SELECT 'B' type_cn, a.customer_trx_id, a.cust_trx_type_id,
    a.rac_bill_to_customer_name,
    a.raa_bill_to_address1
    || ' '
    || a.raa_bill_to_address2 address1,
    a.raa_bill_to_address3, a.bill_to_site_use_id, a.trx_date,
    a.trx_number,
    ( SUBSTR (a.trx_number, 1,
    INSTR (a.trx_number, 'CN', -1) - 1)
    || SUBSTR (a.trx_number, INSTR (a.trx_number, 'CN', -1) + 2)
    ) trx_number_cmp,
    a.rac_bill_to_customer_num,
    ctl.description, -- b.description
    sum(nvl(ctl.gross_extended_amount, ctl.extended_amount)) extended_amount, -- V2.0
    -- SUM (c.extended_amount) tax_amt -- V2.0
    select SUM (ctl_tax.extended_amount)
    from ra_customer_trx_lines ctl_tax,
    ra_customer_trx_lines ctl_line
    WHERE ctl_tax.link_to_cust_trx_line_id = ctl_line.customer_trx_line_id
    AND ctl_tax.line_type = 'TAX'
    AND ctl_tax.customer_trx_id = a.customer_trx_id
    ) tax_amt
    FROM ra_customer_trx_partial_v a,
    ra_customer_trx_lines ctl,
    ra_customer_trx ct,
    ra_cust_trx_types ctt,
    hz_cust_acct_sites radd,
    hz_party_sites party_site,
    hz_locations loc,
    hz_cust_site_uses site
    -- ra_customer_trx_lines_v b
    -- ar_tax_summ_v c
    WHERE a.ctt_class = 'CM'
    AND ctl.line_type = 'LINE'
    &P_CUSTOMER_NUM_CLAUSE
    &P_CUST_TRX_NUM_CLAUSE
    -- AND b.customer_trx_id = a.customer_trx_id
    AND ctl.customer_trx_id = a.customer_trx_id
    AND ctl.customer_trx_id = ct.customer_trx_id
    AND ct.cust_trx_type_id = ctt.cust_trx_type_id
    AND ctt.TYPE NOT IN ('DEP', 'GUAR', 'BR')
    AND ct.bill_to_site_use_id = site.site_use_id
    AND site.cust_acct_site_id = radd.cust_acct_site_id
    AND radd.party_site_id = party_site.party_site_id
    AND loc.location_id = party_site.location_id
    -- AND c.customer_trx_id(+) = a.customer_trx_id
    GROUP BY a.cust_trx_type_id,
    a.rac_bill_to_customer_name,
    a.raa_bill_to_address1,
    a.raa_bill_to_address2,
    a.raa_bill_to_address3,
    a.bill_to_site_use_id,
    a.trx_date,
    a.trx_number,
    a.rac_bill_to_customer_num,
    a.customer_trx_id,
    ctl.description,
    (SUBSTR (a.trx_number, 1, INSTR (a.trx_number, 'CN') - 1)
    )) cn
    WHERE cc.cust_trx_type_id = cn.cust_trx_type_id
    AND cc.global_attribute19 = lc.location_code(+)
    AND rc.trx_number = cn.trx_number_cmp
    =============================================================

    Post relevant all details as explained in this instruction:
    HOW TO: Post a SQL statement tuning request - template posting

  • Help in Tuning this Query

    Hi,
    I have a query in my proj where the same table is looked up twice in the same query.
    Can anybody suggest in improving the performance of this query?
    select * from table1 a1 where (a1.column1, a1.column2, a1.column3, a1.column4, a1.column5, a1.column6, a1.column7, a1.column8, a1.column9,
    a1.column10) in ( select a2.column1, a2.column2, a2.column3, a2.column4, a2.column5, a2.column6, a2.column7, a2.column8, a2.column9,
    a2.column10 from table1 a2 where column20 = '<condn>')
    The table1 used here is same in outer query as well as the sub query. this is a example of what we use here, and the table1 contains 30 million rows. Though, creating index with 10 columns can be a option, we already have a unique index with 11 columns(which includes 10 from this query) and will that be helpful in anyway? or the same existing index can be forced?
    Thanks a lot for ur time

    Depending on the selectivity of column20 I am not sure Index is the best way to go. It might perform better with two full scans and a hash-join.
    Anyway, I do prefer the syntax:
    select /*+ leading(a2) */ a1.*
    from table1 a1, table1 a2
    where a2.column20 = '<condn>'
    and a1.column1 = a2.column1
    and a1.column2 = a2.column2
    and  a1.column3 = a2.column3
    and  a1.column4 = a2.column4
    and  a1.column5 = a2.column5
    and  a1.column6 = a2.column6
    and  a1.column7 = a2.column7
    and  a1.column8 = a2.column8
    and  a1.column9 = a2.column9
    and  a1.column10 = a2.column10;I've added a leading hint to tell oracle that the start table is a2. Might be useless.
    Ensure your stats are up to date. You might need histograms here if your column20 is skewed.
    Hope this helps,
    François
    Edited by: Francois Berger on Oct 24, 2008 1:47 AM

  • Help on tuning this query

    Hi all i have this query:
    SELECT VTA.CO_VENDEDOR
    ,VTA.NB_VENDEDOR
    ,VTA.CO_CLASE_CLIENTE
    ,VTA.DE_CLASE_CLIENTE
    ,VTA.CO_CLIENTE
    ,VTA.NB_CLIENTE
    ,VTA.MN_VENDIDO
    ,NVL(DEV.MN_DEVUELTO,0) MN_DEVUELTO
    ,VTA.MN_VENDIDO - NVL(DEV.MN_DEVUELTO,0) MN_NETO_VENDIDO
    ,NVL(COB.MN_COBRADO,0) MN_COBRADO
    ,NVL(COB.MN_DESCUENTO,0) MN_DESCUENTO
    ,NVL(COB.MN_COBRADO,0) + NVL(COB.MN_DESCUENTO,0) MN_COBRADO_MAS_DESCUENTO
    FROM (SELECT FCL.CTV_CO_CLASE_ORGANIZACION CO_CLASE_CLIENTE
    ,FCL.CTV_DE_CLASE_ORGANIZACION DE_CLASE_CLIENTE
    ,FCL.CO_ORGANIZACION CO_CLIENTE
    ,FCL.ORG_NB_CLIENTE NB_CLIENTE
    ,FCL.PER_CO_IDENTIFICACION_VENDEDOR CO_VENDEDOR
    ,FCL.PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    FCL.PER_NB_PRIMER_APELLIDO_VEND NB_VENDEDOR
    ,SUM((CA_PRODUCTO * (PR_PRODUCTO - NVL(PR_DESCUENTO_PRODUCTO,0))) * (1 - NVL(PC_DESCUENTO,0))) MN_VENDIDO
    FROM S04_FACTURA_CLIENTE_TOTAL_R FCL
    ,S04_FACTURA_CLIENTE_PRD_TOT FPR
         ,(SELECT FCP.FAC_ID_FACTURA
    ,SUM(DDC.MN_DEBITO_CREDITO) /
    SUM(FCP.CA_PRODUCTO * (FCP.PR_PRODUCTO - NVL(FCP.PR_DESCUENTO_PRODUCTO,0))) PC_DESCUENTO
         FROM S04_DOCUMENTO_DEBITO_CREDITO_R DDC
    ,S04_FACTURA_CLIENTE_PRD_TOT FCP
         WHERE DDC.ID_DOCUMENTO_REFERENCIA = FCP.FAC_ID_FACTURA
    AND DDC.TDC_IN_DEBITO_CREDITO = 'C'
    GROUP BY FCP.FAC_ID_FACTURA) DCT
    WHERE FCL.ID_REGISTRO = FPR.FAC_ID_FACTURA
    AND DCT.FAC_ID_FACTURA (+) = FPR.FAC_ID_FACTURA
    AND FCL.FE_EMISION BETWEEN to_date('01112009','ddmmyyyy') AND to_date('29112009','ddmmyyyy')
    AND FCL.ORG_ID_CLIENTE = NVL(NULL,FCL.ORG_ID_CLIENTE)
    AND FCL.PER_ID_VENDEDOR = NVL(7647771,FCL.PER_ID_VENDEDOR)
                   AND FCL.CTV_CO_ESTADO_DOCUMENTO = 'EM'
    AND FCL.UBG_ID_UBICACION_CLIENTE in (SELECT ID_REGISTRO
    FROM S00_UBICACION_GEOGRAFICA
    START WITH ID_REGISTRO = nvl(NULL, FCL.UBG_ID_UBICACION_CLIENTE)
    CONNECT BY PRIOR ID_REGISTRO = UBG_ID_UBICACION_PADRE)
    GROUP BY FCL.CTV_CO_CLASE_ORGANIZACION
    ,FCL.CTV_DE_CLASE_ORGANIZACION
    ,FCL.CO_ORGANIZACION
    ,FCL.ORG_NB_CLIENTE
    ,PER_CO_IDENTIFICACION_VENDEDOR
    ,PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    PER_NB_PRIMER_APELLIDO_VEND) VTA
    ,(SELECT NDC .CTV_CO_CLASE_ORGANIZACION CO_CLASE_CLIENTE
    ,NDC.CTV_DE_CLASE_ORGANIZACION DE_CLASE_CLIENTE
    ,NDC.CO_CLIENTE
    ,NDC.ORG_NB_CLIENTE NB_CLIENTE
    ,FCL.PER_CO_IDENTIFICACION_VENDEDOR CO_VENDEDOR
    ,FCL.PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    FCL.PER_NB_PRIMER_APELLIDO_VEND NB_VENDEDOR
    ,SUM(CA_PRODUCTO * (PR_PRODUCTO - NVL(PR_DESCUENTO_PRODUCTO,0))) MN_DEVUELTO
    FROM S06_NOTA_DEBITO_CREDITO_TOT_R NDC
         ,S06_DETALLE_NOTA_DEB_CRED_TOT DND
    ,S04_FACTURA_CLIENTE_TOTAL_R FCL
         WHERE NDC.ID_REGISTRO = DND.NDC_ID_NOTA_DEBITO_CREDITO
    AND NDC.CTV_CO_TIPO_DOCUMENTO = SK00_BUSCAR.F_VCT('CO_TIPO_DOCUMENTO_NOTA_CREDITO_FISCAL')
    AND NDC.CTV_CO_ESTADO_DOCUMENTO = SK00_BUSCAR.F_VCT('CO_ESTADO_DOCUMENTO_EMITIDO')
         AND NDC.FE_EMISION BETWEEN to_date('01112009','ddmmyyyy') AND to_date('29112009','ddmmyyyy')
         AND (NDC.CTV_CO_MOTIVO_NOTA = SK00_BUSCAR.F_VCT('CO_MOTIVO_NOE_DEVOLUCION')
         OR NDC.CTV_CO_MOTIVO_NOTA = SK00_BUSCAR.F_VCT('CO_MOTIVO_AJUSTE_PRECIO_NCD'))
    AND NDC.ORG_ID_CLIENTE = NVL(NULL,NDC.ORG_ID_CLIENTE)
    AND FCL.ID_REGISTRO = NDC.FAC_ID_FACTURA
                             AND FCL.CTV_CO_ESTADO_DOCUMENTO = 'EM'
    AND FCL.UBG_ID_UBICACION_CLIENTE in (SELECT ID_REGISTRO
    FROM S00_UBICACION_GEOGRAFICA
    START WITH ID_REGISTRO = nvl(NULL, FCL.UBG_ID_UBICACION_CLIENTE)
    CONNECT BY PRIOR ID_REGISTRO = UBG_ID_UBICACION_PADRE)
    GROUP BY NDC.CTV_CO_CLASE_ORGANIZACION
    ,NDC.CTV_DE_CLASE_ORGANIZACION
    ,NDC.CO_CLIENTE
    ,NDC.ORG_NB_CLIENTE
    ,FCL.PER_CO_IDENTIFICACION_VENDEDOR
    ,FCL.PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    FCL.PER_NB_PRIMER_APELLIDO_VEND) DEV
    ,(SELECT RCD .CTV_CO_CLASE_ORGANIZACION CO_CLASE_CLIENTE
    ,RCD.CTV_DE_CLASE_ORGANIZACION DE_CLASE_CLIENTE
    ,RCD.CO_ORGANIZACION CO_CLIENTE
    ,RCD.ORG_NB_DISTRIBUIDOR NB_CLIENTE
    ,FCL.PER_CO_IDENTIFICACION_VENDEDOR CO_VENDEDOR
    ,FCL.PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    FCL.PER_NB_PRIMER_APELLIDO_VEND NB_VENDEDOR
    ,SUM(RCD.MN_DESCUENTO) MN_DESCUENTO
    ,SUM(DECODE(SIGN(RCO.MN_COBRADO_ANTES - IVA.MN_IVA)
    ,-1
    ,RCD.MN_ABONO - ABS(RCO.MN_COBRADO_ANTES - IVA.MN_IVA)
    ,RCD.MN_ABONO)) MN_COBRADO
    FROM S06_RECIBO_COBRO_DOC_TOTAL_R RCD
    ,S04_FACTURA_CLIENTE_TOTAL_R FCL
    ,(SELECT ID_DOCUMENTO_REFERENCIA FAC_ID_FACTURA
    ,NVL(SUM(MN_DEBITO_CREDITO),0) MN_IVA
    FROM S04_DOCUMENTO_DEBITO_CREDITO_R
    WHERE TDC_CO_TIPO_DEBITO_CREDITO = SK00_BUSCAR.F_VCT('CO_TIPO_DEBITO_IVA')
    GROUP BY ID_DOCUMENTO_REFERENCIA) IVA
    ,(SELECT ID_REFERENCIA FAC_ID_FACTURA
    ,NVL(SUM(MN_ABONO),0) MN_COBRADO_ANTES
    FROM S06_RECIBO_COBRO_DOC_TOTAL_R
    WHERE FE_EMISION < to_date('01112009','ddmmyyyy')
    GROUP BY ID_REFERENCIA) RCO
         WHERE RCD.CTV_CO_ESTADO_DOCUMENTO = SK00_BUSCAR.F_VCT('CO_ESTADO_DOCUMENTO_EMITIDO')
         AND RCD.FE_EMISION BETWEEN to_date('01112009','ddmmyyyy') AND to_date('29112009','ddmmyyyy')
    AND RCD.ORG_ID_ORGANIZACION = NVL(NULL,RCD.ORG_ID_ORGANIZACION)
    AND FCL.CTV_CO_ESTADO_DOCUMENTO = 'EM'
                             AND FCL.ID_REGISTRO = RCD.ID_REFERENCIA
    AND FCL.UBG_ID_UBICACION_CLIENTE in (SELECT ID_REGISTRO
    FROM S00_UBICACION_GEOGRAFICA
    START WITH ID_REGISTRO = nvl(NULL, FCL.UBG_ID_UBICACION_CLIENTE)
    CONNECT BY PRIOR ID_REGISTRO = UBG_ID_UBICACION_PADRE)
    AND IVA.FAC_ID_FACTURA (+) = FCL.ID_REGISTRO
    AND RCO.FAC_ID_FACTURA (+) = FCL.ID_REGISTRO
    GROUP BY RCD.CTV_CO_CLASE_ORGANIZACION
    ,RCD.CTV_DE_CLASE_ORGANIZACION
    ,RCD.CO_ORGANIZACION
    ,RCD.ORG_NB_DISTRIBUIDOR
    ,FCL.PER_CO_IDENTIFICACION_VENDEDOR
    ,FCL.PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    FCL.PER_NB_PRIMER_APELLIDO_VEND) COB
    WHERE VTA.CO_CLIENTE = DEV.CO_CLIENTE (+)
    AND VTA.CO_VENDEDOR = DEV.CO_VENDEDOR (+)
    AND VTA.CO_CLIENTE = COB.CO_CLIENTE (+)
    AND VTA.CO_VENDEDOR = COB.CO_VENDEDOR (+)
    ORDER BY VTA.NB_VENDEDOR
    ,VTA.CO_CLIENTE
    Is there a way i can influence the join method on this query ...?
    It's an XE DB.
    Regards, Luis ...!

    THIS IS THE PLAN:
    SQL> /
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=79006 Card=1 Bytes
    =253)
    1 0 SORT (ORDER BY) (Cost=79006 Card=1 Bytes=253)
    2 1 HASH JOIN (OUTER) (Cost=79005 Card=1 Bytes=253)
    3 2 HASH JOIN (OUTER) (Cost=78538 Card=1 Bytes=211)
    4 3 VIEW (Cost=78478 Card=1 Bytes=182)
    5 4 HASH (GROUP BY) (Cost=78478 Card=1 Bytes=232)
    6 5 FILTER
    7 6 HASH JOIN (OUTER) (Cost=78469 Card=1 Bytes=232
    8 7 TABLE ACCESS (BY INDEX ROWID) OF 'T04_FACTUR
    A_PRODUCTO' (TABLE) (Cost=2 Card=1 Bytes=46)
    9 8 NESTED LOOPS (Cost=25 Card=1 Bytes=213)
    10 9 VIEW OF 'V04_FACTURA_CLIENTE_TOTAL_R' (V
    IEW) (Cost=23 Card=1 Bytes=167)
    11 10 NESTED LOOPS (Cost=23 Card=1 Bytes=284
    12 11 NESTED LOOPS (OUTER) (Cost=23 Card=1
    Bytes=278)
    13 12 HASH JOIN (SEMI) (Cost=23 Card=1 B
    ytes=272)
    14 13 NESTED LOOPS (Cost=17 Card=1 Byt
    es=259)
    15 14 NESTED LOOPS (Cost=16 Card=1 B
    ytes=218)
    16 15 NESTED LOOPS (OUTER) (Cost=1
    6 Card=1 Bytes=212)
    17 16 NESTED LOOPS (Cost=15 Card
    =1 Bytes=179)
    18 17 NESTED LOOPS (Cost=15 Ca
    rd=1 Bytes=173)
    19 18 NESTED LOOPS (OUTER) (
    Cost=14 Card=1 Bytes=162)
    20 19 NESTED LOOPS (OUTER)
    (Cost=14 Card=1 Bytes=156)
    21 20 NESTED LOOPS (OUTE
    R) (Cost=14 Card=1 Bytes=150)
    22 21 NESTED LOOPS (OU
    TER) (Cost=14 Card=1 Bytes=144)
    23 22 NESTED LOOPS (
    Cost=14 Card=1 Bytes=105)
    24 23 SORT (UNIQUE
    ) (Cost=2 Card=1 Bytes=13)
    25 24 TABLE ACCE
    SS (FULL) OF 'T00_GRUPO_DATO_USUARIO_ACTIVO' (TABLE (TEMP))
    (Cost=2 Card=1 Bytes=13)
    26 23 TABLE ACCESS
    (BY INDEX ROWID) OF 'T04_FACTURA' (TABLE) (Cost=11 Card=1 B
    ytes=92)
    27 26 INDEX (RAN
    GE SCAN) OF 'I04_FAC_FE_EMISION' (INDEX) (Cost=10 Card=2)
    28 22 TABLE ACCESS (
    BY INDEX ROWID) OF 'T03_EMPRESA_SUCURSAL' (TABLE) (Cost=0 Ca
    rd=1 Bytes=39)
    29 28 INDEX (RANGE
    SCAN) OF 'I03_EMS_EMP' (INDEX) (Cost=0 Card=1)
    30 21 INDEX (UNIQUE SC
    AN) OF 'PK_PRY' (INDEX (UNIQUE)) (Cost=0 Card=1 Bytes=6)
    31 20 INDEX (UNIQUE SCAN
    ) OF 'PK_CAJ' (INDEX (UNIQUE)) (Cost=0 Card=1 Bytes=6)
    32 19 INDEX (UNIQUE SCAN)
    OF 'PK_PEC' (INDEX (UNIQUE)) (Cost=0 Card=1 Bytes=6)
    33 18 TABLE ACCESS (BY INDEX
    ROWID) OF 'T00_CONTENIDO_TABLA_VIRTUAL' (TABLE) (Cost=1 Car
    d=1 Bytes=11)
    34 33 INDEX (UNIQUE SCAN)
    OF 'PK_CTV' (INDEX (UNIQUE)) (Cost=0 Card=1)
    SORRY EXPLAIN OUTPUT TRUNCATED DUE TO SPACE RESTRICION .....
    Any help would be greatly appreciated.
    I believe there must be a way to influence on the tha costly HASH JOIN operation
    SQL> SPOOL OFF

  • Please help me with this query -- i am trying with Dense rank

    version 10g
    i received a quote for an account. if the same quote is received under different account then i should mark the previous account received as deleted.
    please help me .
    /* Formatted on 2010/06/28 14:13 (Formatter Plus v4.8.8) */
    WITH temp AS
         (SELECT '1-11TWQL' quote_id, 'COPS' ACCOUNT, 'Ordered' status,
                 TO_DATE ('12/23/2009 3:37:54',
                          'mm/dd/yyyy hh:mi:ss PM'
                         ) captured_date
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'RFS',
                 TO_DATE ('12/23/2009 3:37:50', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'Rejected',
                 TO_DATE ('12/23/2009 3:37:52', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:51', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Ordered',
                 TO_DATE ('12/23/2009 3:04:24', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'RFS',
                 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Rejected',
                 TO_DATE ('12/23/2009 3:04:22', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Validated',
                 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'RFS',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'RFS',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8Z', 'COPS', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL
          UNION ALL
          SELECT '1-249A8Z', 'COPS', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
            FROM DUAL)
    SELECT   quote_id, ACCOUNT, status, captured_date,
             DENSE_RANK () OVER (PARTITION BY quote_id ORDER BY quote_id,
              ACCOUNT) rn
    --         ,CASE DENSE_RANK () OVER (PARTITION BY quote_id ORDER BY quote_id,
    --              ACCOUNT)
    --            WHEN 1
    --               THEN 'Y'
    --            ELSE 'N'
    --         END deleted_flag
        FROM temp
    ORDER BY quote_id, captured_date;output required
    WITH temp AS
         (SELECT '1-11TWQL' quote_id, 'COPS' ACCOUNT, 'Ordered' status,
                 TO_DATE ('12/23/2009 3:37:54',
                          'mm/dd/yyyy hh:mi:ss PM'
                         ) captured_date, 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'RFS',
                 TO_DATE ('12/23/2009 3:37:50', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'Rejected',
                 TO_DATE ('12/23/2009 3:37:52', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:51', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Ordered',
                 TO_DATE ('12/23/2009 3:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'RFS',
                 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Rejected',
                 TO_DATE ('12/23/2009 3:04:22', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-11TWQL', 'D1', 'Validated',
                 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'RFS',
                 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Rejected',
                 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'COPS', 'Validated',
                 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'RFS',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'RFS',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8X', 'D1', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8Z', 'COPS', 'Validated',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL
          UNION ALL
          SELECT '1-249A8Z', 'COPS', 'Ordered',
                 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
            FROM DUAL)
    SELECT   quote_id, ACCOUNT, status, captured_date, deleted_flag
        FROM temp
    ORDER BY quote_id, captured_date;

    try to wrap your query to become an in-line view. use a case statement or decode to your derived column RN from the analytic query of DENSE RANK. either way they both will work.
    SQL> WITH temp AS
      2       (SELECT '1-11TWQL' quote_id, 'COPS' ACCOUNT, 'Ordered' status,
      3               TO_DATE ('12/23/2009 3:37:54',
      4                        'mm/dd/yyyy hh:mi:ss PM'
      5                       ) captured_date
      6          FROM DUAL
      7        UNION ALL
      8        SELECT '1-11TWQL', 'COPS', 'RFS',
      9               TO_DATE ('12/23/2009 3:37:50', 'mm/dd/yyyy hh:mi:ss PM')
    10          FROM DUAL
    11        UNION ALL
    12        SELECT '1-11TWQL', 'COPS', 'Rejected',
    13               TO_DATE ('12/23/2009 3:37:52', 'mm/dd/yyyy hh:mi:ss PM')
    14          FROM DUAL
    15        UNION ALL
    16        SELECT '1-11TWQL', 'COPS', 'Validated',
    17               TO_DATE ('12/23/2009 3:37:51', 'mm/dd/yyyy hh:mi:ss PM')
    18          FROM DUAL
    19        UNION ALL
    20        SELECT '1-11TWQL', 'D1', 'Ordered',
    21               TO_DATE ('12/23/2009 3:04:24', 'mm/dd/yyyy hh:mi:ss PM')
    22          FROM DUAL
    23        UNION ALL
    24        SELECT '1-11TWQL', 'D1', 'RFS',
    25               TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
    26          FROM DUAL
    27        UNION ALL
    28        SELECT '1-11TWQL', 'D1', 'Rejected',
    29               TO_DATE ('12/23/2009 3:04:22', 'mm/dd/yyyy hh:mi:ss PM')
    30          FROM DUAL
    31        UNION ALL
    32        SELECT '1-11TWQL', 'D1', 'Validated',
    33               TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
    34          FROM DUAL
    35        UNION ALL
    36        SELECT '1-249A8X', 'COPS', 'RFS',
    37               TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
    38          FROM DUAL
    39        UNION ALL
    40        SELECT '1-249A8X', 'COPS', 'RFS',
    41               TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
    42          FROM DUAL
    43        UNION ALL
    44        SELECT '1-249A8X', 'COPS', 'RFS',
    45               TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
    46          FROM DUAL
    47        UNION ALL
    48        SELECT '1-249A8X', 'COPS', 'Rejected',
    49               TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
    50          FROM DUAL
    51        UNION ALL
    52        SELECT '1-249A8X', 'COPS', 'Rejected',
    53               TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
    54          FROM DUAL
    55        UNION ALL
    56        SELECT '1-249A8X', 'COPS', 'Rejected',
    57               TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
    58          FROM DUAL
    59        UNION ALL
    60        SELECT '1-249A8X', 'COPS', 'Validated',
    61               TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
    62          FROM DUAL
    63        UNION ALL
    64        SELECT '1-249A8X', 'COPS', 'Validated',
    65               TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
    66          FROM DUAL
    67        UNION ALL
    68        SELECT '1-249A8X', 'COPS', 'Validated',
    69               TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
    70          FROM DUAL
    71        UNION ALL
    72        SELECT '1-249A8X', 'D1', 'Ordered',
    73               TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
    74          FROM DUAL
    75        UNION ALL
    76        SELECT '1-249A8X', 'D1', 'Ordered',
    77               TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
    78          FROM DUAL
    79        UNION ALL
    80        SELECT '1-249A8X', 'D1', 'RFS',
    81               TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
    82          FROM DUAL
    83        UNION ALL
    84        SELECT '1-249A8X', 'D1', 'RFS',
    85               TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
    86          FROM DUAL
    87        UNION ALL
    88        SELECT '1-249A8X', 'D1', 'Validated',
    89               TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
    90          FROM DUAL
    91        UNION ALL
    92        SELECT '1-249A8X', 'D1', 'Validated',
    93               TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
    94          FROM DUAL
    95        UNION ALL
    96        SELECT '1-249A8Z', 'COPS', 'Validated',
    97               TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
    98          FROM DUAL
    99        UNION ALL
    100        SELECT '1-249A8Z', 'COPS', 'Ordered',
    101               TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
    102          FROM DUAL)
    103  select vt.quote_id,
    104         vt.account,
    105         vt.status,
    106         vt.captured_date,
    107         case when vt.rn = 1 then 'N'
    108              else 'Y'
    109         end deleted_flag
    110    from (SELECT quote_id, ACCOUNT, status, captured_date,
    111                 DENSE_RANK () OVER (PARTITION BY quote_id ORDER BY quote_id, ACCOUNT) rn
    112            FROM temp
    113          ORDER BY quote_id, captured_date) vt;
    QUOTE_ID ACCOUNT STATUS    CAPTURED_DATE DELETED_FLAG
    1-11TWQL D1      Rejected  23-Dec-2009 3 Y
    1-11TWQL D1      RFS       23-Dec-2009 3 Y
    1-11TWQL D1      Validated 23-Dec-2009 3 Y
    1-11TWQL D1      Ordered   23-Dec-2009 3 Y
    1-11TWQL COPS    RFS       23-Dec-2009 3 N
    1-11TWQL COPS    Validated 23-Dec-2009 3 N
    1-11TWQL COPS    Rejected  23-Dec-2009 3 N
    1-11TWQL COPS    Ordered   23-Dec-2009 3 N
    1-249A8X COPS    Validated 23-Dec-2009 3 N
    1-249A8X COPS    Validated 23-Dec-2009 3 N
    1-249A8X COPS    Validated 23-Dec-2009 3 N
    1-249A8X COPS    RFS       05-Mar-2010 1 N
    1-249A8X COPS    Rejected  05-Mar-2010 1 N
    1-249A8X COPS    RFS       16-Mar-2010 7 N
    1-249A8X COPS    Rejected  16-Mar-2010 7 N
    1-249A8X COPS    Rejected  16-Mar-2010 7 N
    1-249A8X COPS    RFS       16-Mar-2010 7 N
    1-249A8X D1      Ordered   26-Mar-2010 1 Y
    1-249A8X D1      Ordered   26-Mar-2010 1 Y
    1-249A8X D1      RFS       26-Mar-2010 1 Y
    1-249A8X D1      RFS       26-Mar-2010 1 Y
    1-249A8X D1      Validated 26-Mar-2010 1 Y
    1-249A8X D1      Validated 26-Mar-2010 1 Y
    1-249A8Z COPS    Validated 26-Mar-2010 1 N
    1-249A8Z COPS    Ordered   26-Mar-2010 1 N
    25 rows selected
    SQL>

  • Please help me on this query

    Hi experts,
    I have data like this in a table with 5000 records.
    ID cid Name
    1 10 Ram
    1 20 Raj
    2 10 Kiran
    2 20 Kishor
    2 30 Krishna
    2 40 Karuna
    2 50 Kamesh
    2 50 Kumar
    2 50 Kamal
    2 60 Keerti
    3 10 Syam
    3 20 Suresh
    3 30 Suman
    3 40 Santosh
    3 40 Sarat
    3 50 Sirisha
    3 60 Sumanth
    4 10 Tarun
    4 20 Tanish
    4 30 Taman
    4 40 Tomas
    4 40 Teenu
    5 10 Prakash
    5 20 Pavan
    5 30 Prasad
    etc
    I want the output like
    ID CID NAME
    1 10,20 Ram,Raj
    2 10,20,30,40,50,50,50,60 Kiran,Kishor,Krishna,Karuna,Kamesh,Kamal,Keerti
    3 10,20,30,40,40,50,60 Syam,Suresh,Suman,Santosh, Sarat,Sirisha,Sumanth
    4 10,20,30,40,40 Tarun,Tanish,Taman,Tomas,Teenu
    5 10,20,30 Prakash,Pavan,Prasad
    Please help me to get the output like this
    Thanks in advance

    with t as (
               select 1 id,10 cid,'Ram' name from dual union all
               select 1,20,'Raj' from dual union all
               select 2,10,'Kiran' from dual union all
               select 2,20,'Kishor' from dual union all
               select 2,30,'Krishna' from dual union all
               select 2,40,'Karuna' from dual union all
               select 2,50,'Kamesh' from dual union all
               select 2,50,'Kumar' from dual union all
               select 2,50,'Kamal' from dual union all
               select 2,60,'Keerti' from dual union all
               select 3,10,'Syam' from dual union all
               select 3,20,'Suresh' from dual union all
               select 3,30,'Suman' from dual union all
               select 3,40,'Santosh' from dual union all
               select 3,40,'Sarat' from dual union all
               select 3,50,'Sirisha' from dual union all
               select 3,60,'Sumanth' from dual union all
               select 4,10,'Tarun' from dual union all
               select 4,20,'Tanish' from dual union all
               select 4,30,'Taman' from dual union all
               select 4,40,'Tomas' from dual union all
               select 4,40,'Teenu' from dual union all
               select 5,10,'Prakash' from dual union all
               select 5,20,'Pavan' from dual union all
               select 5,30,'Prasad' from dual
    -- end of on-the-fly data sample
    select  id,
            rtrim(xmlagg(xmlelement(e,cid,',').extract('//text()') order by cid),',') cid,
            rtrim(xmlagg(xmlelement(e,name,',').extract('//text()') order by cid),',') name
      from  t
      group by id
      order by id
            ID CID                       NAME
             1 10,20                     Ram,Raj
             2 10,20,30,40,50,50,50,60   Kiran,Kishor,Krishna,Karuna,Kamesh,Kamal,Kumar,Keerti
             3 10,20,30,40,40,50,60      Syam,Suresh,Suman,Santosh,Sarat,Sirisha,Sumanth
             4 10,20,30,40,40            Tarun,Tanish,Taman,Tomas,Teenu
             5 10,20,30                  Prakash,Pavan,Prasad
    SQL> SY.

  • solved need help in tuning this Query

    hi frs,
    i have created a query like this
    pls help
    Regards
    Rajesh
    Message was edited by:
    Rajesh.mani
    Message was edited by:
    Rajesh.mani

    Code and explain plan should be between [pre] and [/pre] or [code] and [/code] tags like this.
    [pre]Code[/pre]An now explain plan
    [code]Execution plan
    [/code]
    Cheers
    Sarma.

  • Plz help in tuning this query......

    SELECT "LAN","VEF_REF_NO","VF_TYPE_CODE","APPLICANT_TYPE","MANDATORY","OPTIONAL","COMPLETE","DT_COMPLETED","REFIRENO","ROLE","USER_ID","DT_LASTUPDATED","TEMPLATEFIRED"
    FROM T_VER_STRATEGY_DETAILS M
    WHERE VF_TYPE_CODE =1 AND
    APPLICANT_TYPE ='A' AND
    DT_LASTUPDATED=
    (SELECT MAX(DT_LASTUPDATED)
    FROM T_VER_STRATEGY_DETAILS
    WHERE LAN = M.LAN AND
    VF_TYPE_CODE =1 AND APPLICANT_TYPE ='A')
    This seems to be a correlated query.
    i tried using combined index on
    (VF_TYPE_CODE ,APPLICANT_TYPE ,DT_LASTUPDATED)
    and another index on
    (LAN,VF_TYPE_CODE ,APPLICANT_TYPE ) but the plan or cost remains unchained.
    plz help

    [url http://forums.oracle.com/forums/thread.jspa?threadID=501834&tstart=0]When your query takes too long...

  • Please help me getting this query in MDX

    Select CASE WHEN DSL.Latest_Label IS NULL THEN DS.[Label] ELSE DSL.Latest_Label END AS Label From Dim_Label AS DS LEFT OUTER JOIN
    (Select Idx,GRP_Idx,Max(Latest_Label) Latest_Label,MAX(Date_ID) Date_ID from [Dim_Label_Change] DSL te_Day = DSL.Date_Effective Where (Date_Id <= 333  ) Group by idx,GRP_Idx)
    DSL ON DS.Idx = DSL.Idx
    Thanks in Advance for the help

    My Cube has Dimensions, Fact tables and Measures , and Dimension table consists of Main and History table(Type 2 Slowly Changing Dimension).
    I would like to display the History(Latest_Label) Name based on  the date selected on SSRS Report.
    Hi SKPSR,
    According to your description, you need to get the latest history name based on a date that selected by use in SSRS report, right?
    In SSAS, we can use the LastNonEmpty function or Tail function to get the last member from a set. We cannot give you the detail MDX query based on the limited information, you can refer to the links below to see the details.
    http://msdn.microsoft.com/en-us/library/ms146056.aspx
    http://thinknook.com/ssas-lastnonempty-aggregation-function-2012-08-18/
    If the issue persists, please provide us more information about your cube structure, so that we can make further analysis.
    Regards,
    Charlie Liao
    TechNet Community Support

  • Please help me optimize this query

    Hi,
    Can you’ll please recommend me if there is any way to optimize the SQL statement below.
    I have 3 tables:
    item_master: contains master list of items
    item_rentout: items currently out on rent
    item_missing: items having special status like missing, withdrawn and so on.
    I want to find items that are currently available.
    Which is items in table item_master –(minus) items in table item_rentout –(minus) items in table in item_missing.
    This is how my sql statement is:
    select item_master.item_id from item_master where item_master.item_id not in
    ((select item_id from item_rentout) union (select item_id from item_missing where status in (‘missing’,withdrawn’)))Regards,
    Raja

    In addition to what Pointless posted (which is very valuable information!) you could always try and write a logical equivalent SQL statement. It may generate a more favorable plan.
    I have written the following that I think may work but they are untested:
    SELECT  ITEM_MASTER.ITEM_ID     FROM ITEM_MASTER
    MINUS
    SELECT  ITEM_ID FROM ITEM_RENTOUT
    MINUS
    SELECT  ITEM_ID FROM ITEM_MISSING WHERE STATUS IN ('missing','withdrawn')
    SELECT  item_master.item_id
    FROM    ITEM_MASTER IM
    WHERE   NOT EXISTS
                    SELECT  NULL
                    FROM    ITEM_RENTOUT IR
                    WHERE   IR.ITEM_ID = IM.ITEM_ID
    AND     NOT EXISTS
                    SELECT  NULL
                    FROM    ITEM_MISSING IIM
                    WHERE   IIM.ITEM_ID = IM.ITEM_ID       
            )

Maybe you are looking for

  • Trying to pass and object variable to a method

    I have yet another question. I'm trying to display my output in succession using a next button. The button works and I get what I want using test results, however what I really want to do is pass it a variable instead of using a set number. I want to

  • Dual boot: OS X Mavericks and Mountain Lion?

    Hi there, searching the internet I found a lot of video tutorials and discussions about the proper way to partition your hard drive so you can boot OS X Mavericks from your Mountain Lion system. However, having installed Mavericks right after its rel

  • Where can I find original drivers for GV PowerPort Platinum Pro card?

    I know this is going back to the dark ages for some Mac users, but I was trying to install a Global Village PowerPort Platinum Pro modem/ethernet PCMCIA card in my old PB1400 and I keep running into the same problem: I get an immediate error message

  • Itunes for IOS 8 interface issue

    How do I shut of ITunes in IOS8's tuning my iPhone screen into a photo-collage of all my music which behaves like a touch-screen land-mine that hair triggers out of what I'm listening to into something else? I know I can shake the phone like a drunke

  • EHP1 for ecc 6.0

    guys, i am trying to find the release notes for ehp1 for ecc 6.0 but cant find them. The marketplace contains only the links to ehp2, 3 and 4. Does this mean there was never an ehp1 for ecc 6.0 or are all the functionalities included in ehp2 now ?? p