NVL in select query

I have query as below
select a.id,
(select dep from table2 where table2.name=table1.name )
from table1
The second value is null as table2.name=table1.name has no value for table1
if i use NVL as below
select a.id,
(select NVL(dep,0) from table2 where table2.name=table1.name )
from table1
it is not fetching 0 in place of dep.Please help.I ned to use NVL here and show value 0 if the select returns null/blank

Hi,
It looks like you've got NVL in the wrong place. Try this:
SELECT  a.id
,     NVL ( ( SELECT  dep
             FROM      table2
          WHERE      table2.name     = table1.name
         , 0
         )     AS dep
FROM    table1
;If a scalar sub-query finds no rows, then it returns NULL, regarless of what is in the SELECT clause of the scalar sub-query.
You might want to avoid the scalar sub-query altogether, and use an outer join instead:
SELECT     a.id
,     NVL (b.dep, 0)     AS dep
FROM              table1  a
LEFT OUTER JOIN  table2  b  ON  a.name     = b.name
;I find this clearer and easier, and it might be more efficient, too.
Also, it won't raise an error if table2.name is not unique.
Edited by: Frank Kulash on Feb 1, 2011 12:43 PM

Similar Messages

  • Error in procedure with cursor which has a select query in NVL

    cursor has a select statement in the NVL functiion
    sample query in given
    SELECT fu.user_name Core_ID,
    fu.description User_Name,
    fu.LAST_LOGON_DATE LAST_LOGON_DATE,
    TRUNC(SYSDATE) - TRUNC(fu.LAST_LOGON_DATE) DAYS_SINCE_LAST_LOGON,
    NVL((SELECT 'YES' FROM custmot.moto_rma_approvers mra
    WHERE mra.primary_approver = fu.user_name),'NO') PRIMARY_RMA_APPROVER,
    NVL((SELECT 'YES' FROM custmot.moto_rma_approvers mra
    WHERE mra.secondary_approver = fu.user_name), 'YES', 'ALL RESPONSIBILITIES',
    DECODE(fu.employee_id, NULL, 'USER ACCOUNT', 'ALL RESPONSIBILITIES' ))) END_DATE_WHAT
    FROM apps.fnd_user fu
    This query runs fine when it is run seperately. But when its defined in cursor in a procedure it throws up the following error.
    "Encountered the symbol "SELECT" when expecting one of the following:
    ( - + mod not null others <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> avg
    count c"
    can you please help us with this

    I noticed your statement has one additional end-bracket at the end. Probably this is just a typo. It should read like this:
    SELECT fu.user_name core_id,
           fu.description user_name,
           fu.last_logon_date last_logon_date,
           TRUNC (SYSDATE) - TRUNC (fu.last_logon_date) days_since_last_logon,
           NVL ((SELECT 'YES'
                   FROM custmot.moto_rma_approvers mra
                  WHERE mra.primary_approver = fu.user_name), 'NO')
                                                             primary_rma_approver,
           NVL ((SELECT 'YES'
                   FROM custmot.moto_rma_approvers mra
                  WHERE mra.secondary_approver = fu.user_name),
                'YES',
                'ALL RESPONSIBILITIES',
                DECODE (fu.employee_id,
                        NULL, 'USER ACCOUNT',
                        'ALL RESPONSIBILITIES'
               ) end_date_what
      FROM apps.fnd_user fuIf that doesn't help, you may make your cursor dynamic:
       OPEN c FOR 'SELECT fu.user_name core_id,
           fu.description user_name,
           fu.last_logon_date last_logon_date,
           TRUNC (SYSDATE) - TRUNC (fu.last_logon_date) days_since_last_logon,
           NVL ((SELECT ''YES''
                   FROM custmot.moto_rma_approvers mra
                  WHERE mra.primary_approver = fu.user_name), ''NO'')
                                                             primary_rma_approver,
           NVL ((SELECT ''YES''
                   FROM custmot.moto_rma_approvers mra
                  WHERE mra.secondary_approver = fu.user_name),
                ''YES'',
                ''ALL RESPONSIBILITIES'',
                DECODE (fu.employee_id,
                        NULL, ''USER ACCOUNT'',
                        ''ALL RESPONSIBILITIES''
               ) end_date_what
      FROM apps.fnd_user fu';

  • Needed help to improve the performance of a select query?

    Hi,
    I have been preparing a report which involves data to be fetched from 4 to 5 different tables and calculation has to performed on some columns also,
    i planned to write a single cursor to populate 1 temp table.i have used INLINE VIEW,EXISTS more frequently in the select query..please go through the query and suggest me a better way to restructure the query.
    cursor c_acc_pickup_incr(p_branch_code varchar2, p_applDate date, p_st_dt date, p_ed_dt date) is
    select sca.branch_code "BRANCH",
    sca.cust_ac_no "ACCOUNT",
    to_char(p_applDate, 'YYYYMM') "YEARMONTH",
    sca.ccy "CURRENCY",
    sca.account_class "PRODUCT",
    sca.cust_no "CUSTOMER",
    sca.ac_desc "DESCRIPTION",
    null "LOW_BAL",
    null "HIGH_BAL",
    null "AVG_CR_BAL",
    null "AVG_DR_BAL",
    null "CR_DAYS",
    null "DR_DAYS",
    --null                                 "CR_TURNOVER",       
    --null                                 "DR_TURNOVER",       
    null "DR_OD_DAYS",
    (select sum(gf.limit_amount * (scal.linkage_percentage / 100)) +
    (case when (p_applDate >= sca.tod_limit_start_date and
    p_applDate <= nvl(sca.tod_limit_end_date, p_applDate)) then
    sca.tod_limit else 0 end) dd
    from getm_facility gf, sttm_cust_account_linkages scal
    where gf.line_code || gf.line_serial = scal.linked_ref_no
    and cust_ac_no = sca.cust_ac_no) "OD_LIMIT",
    --sc.credit_rating                      "CR_GRADE",        
    null "AVG_NET_BAL",
    null "UNAUTH_OD_AMT",
    sca.acy_blocked_amount "AMT_BLOCKED",
    (select sum(amt)
    from ictb_entries_history ieh
    where ieh.acc = sca.cust_ac_no
    and ieh.brn = sca.branch_code
    and ieh.drcr = 'D'
    and ieh.liqn = 'Y'
    and ieh.entry_passed = 'Y'
    and ieh.ent_dt between p_st_dt and p_ed_dt
    and exists (
    select * from ictm_pr_int ipi, ictm_rule_frm irf
    where ipi.product_code = ieh.prod
    and ipi.rule = irf.rule_id
    and irf.book_flag = 'B')) "DR_INTEREST",
    (select sum(amt)
    from ictb_entries_history ieh
    where ieh.acc = sca.cust_ac_no
    and ieh.brn = sca.branch_code
    and ieh.drcr = 'C'
    and ieh.liqn = 'Y'
    and ieh.entry_passed = 'Y'
    and ieh.ent_dt between p_st_dt and p_ed_dt
    and exists (
    select * from ictm_pr_int ipi, ictm_rule_frm irf
    where ipi.product_code = ieh.prod
    and ipi.rule = irf.rule_id
    and irf.book_flag = 'B')) "CR_INTEREST",
    (select sum(amt) from ictb_entries_history ieh
    where ieh.brn = sca.branch_code
    and ieh.acc = sca.cust_ac_no
    and ieh.ent_dt between p_st_dt and p_ed_dt
    and exists (
    select product_code
    from ictm_product_definition ipd
    where ipd.product_code = ieh.prod
    and ipd.product_type = 'C')) "FEE_INCOME",
    sca.record_stat "ACC_STATUS",
    case when (trunc(sca.ac_open_date,'MM') = trunc(p_applDate,'MM')
    and not exists (select 1
    from ictm_tdpayin_details itd
    where itd.multimode_payopt = 'Y'
    and itd.brn = sca.branch_code
    and itd.acc = sca.cust_ac_no
    and itd.multimode_offset_brn is not null
    and itd.multimode_tdoffset_acc is not null))
    then 1 else 0 end "NEW_ACC_FOR_THE_MONTH",
    case when (trunc(sca.ac_open_date,'MM') = trunc(p_applDate,'MM')
    and trunc(sc.cif_creation_date,'MM') = trunc(p_applDate,'MM')
    and not exists (select 1
    from ictm_tdpayin_details itd
    where itd.multimode_payopt = 'Y'
    and itd.brn = sca.branch_code
    and itd.acc = sca.cust_ac_no
    and itd.multimode_offset_brn is not null
    and itd.multimode_tdoffset_acc is not null))
    then 1 else 0 end "NEW_ACC_FOR_NEW_CUST",
    (select 1 from dual
    where exists (select 1 from ictm_td_closure_renew itcr
    where itcr.brn = sca.branch_code
    and itcr.acc = sca.cust_ac_no
    and itcr.renewal_date = sysdate)
    or exists (select 1 from ictm_tdpayin_details itd
    where itd.multimode_payopt = 'Y'
    and itd.brn = sca.branch_code
    and itd.acc = sca.cust_ac_no
    and itd.multimode_offset_brn is not null
    and itd.multimode_tdoffset_acc is not null)) "RENEWED_OR_ROLLOVER",
    (select maturity_date from ictm_acc ia
    where ia.brn = sca.branch_code
    and ia.acc = sca.cust_ac_no) "MATURITY_DATE",
    sca.ac_stat_no_dr "DR_DISALLOWED",
    sca.ac_stat_no_cr "CR_DISALLOWED",
    sca.ac_stat_block                     "BLOCKED_ACC",       Not Reqd
    sca.ac_stat_dormant "DORMANT_ACC",
    sca.ac_stat_stop_pay "STOP_PAY_ACC", --New
    sca.ac_stat_frozen "FROZEN_ACC",
    sca.ac_open_date "ACC_OPENING_DT",
    sca.address1 "ADD_LINE_1",
    sca.address2 "ADD_LINE_2",
    sca.address3 "ADD_LINE_3",
    sca.address4 "ADD_LINE_4",
    sca.joint_ac_indicator "JOINT_ACC",
    sca.acy_avl_bal "CR_BAL",
    0 "DR_BAL",
    0 "CR_BAL_LCY", t
    0 "DR_BAL_LCY",
    null "YTD_CR_MOVEMENT",
    null "YTD_DR_MOVEMENT",
    null "YTD_CR_MOVEMENT_LCY",
    null "YTD_DR_MOVEMENT_LCY",
    null "MTD_CR_MOVEMENT",
    null "MTD_DR_MOVEMENT",
    null "MTD_CR_MOVEMENT_LCY",
    null "MTD_DR_MOVEMENT_LCY",
    'N' "BRANCH_TRFR", --New
    sca.provision_amount "PROVISION_AMT",
    sca.account_type "ACCOUNT_TYPE",
    nvl(sca.tod_limit, 0) "TOD_LIMIT",
    nvl(sca.sublimit, 0) "SUB_LIMIT",
    nvl(sca.tod_limit_start_date, global.min_date) "TOD_START_DATE",
    nvl(sca.tod_limit_end_date, global.max_date) "TOD_END_DATE"
    from sttm_cust_account sca, sttm_customer sc
    where sca.branch_code = p_branch_code
    and sca.cust_no = sc.customer_no
    and ( exists (select 1 from actb_daily_log adl
    where adl.ac_no = sca.cust_ac_no
    and adl.ac_branch = sca.branch_code
    and adl.trn_dt = p_applDate
    and adl.auth_stat = 'A')
    or exists (select 1 from catm_amount_blocks cab
    where cab.account = sca.cust_ac_no
    and cab.branch = sca.branch_code
    and cab.effective_date = p_applDate
    and cab.auth_stat = 'A')
    or exists (select 1 from ictm_td_closure_renew itcr
    where itcr.acc = sca.cust_ac_no
    and itcr.brn = sca.branch_code
    and itcr.renewal_date = p_applDate)
    or exists (select 1 from sttm_ac_stat_change sasc
    where sasc.cust_ac_no = sca.cust_ac_no
    and sasc.branch_code = sca.branch_code
    and sasc.status_change_date = p_applDate
    and sasc.auth_stat = 'A')
    or exists (select 1 from cstb_acc_brn_trfr_log cabtl
    where cabtl.branch_code = sca.branch_code
    and cabtl.cust_ac_no = sca.cust_ac_no
    and cabtl.process_status = 'S'
    and cabtl.process_date = p_applDate)
    or exists (select 1 from sttbs_provision_history sph
    where sph.branch_code = sca.branch_code
    and sph.cust_ac_no = sca.cust_ac_no
    and sph.esn_date = p_applDate)
    or exists (select 1 from sttms_cust_account_dormancy scad
    where scad.branch_code = sca.branch_code
    and scad.cust_ac_no = sca.cust_ac_no
    and scad.dormancy_start_dt = p_applDate)
    or sca.maker_dt_stamp = p_applDate
    or sca.status_since = p_applDate
    l_tb_acc_det ty_tb_acc_det_int;
    l_brnrec cvpks_utils.rec_brnlcy;
    l_acbr_lcy sttms_branch.branch_lcy%type;
    l_lcy_amount actbs_daily_log.lcy_amount%type;
    l_xrate number;
    l_dt_rec sttm_dates%rowtype;
    l_acc_rec sttm_cust_account%rowtype;
    l_acc_stat_row ty_r_acc_stat;
    Edited by: user13710379 on Jan 7, 2012 12:18 AM

    I see it more like shown below (possibly with no inline selects
    Try to get rid of the remaining inline selects ( left as an exercise ;) )
    and rewrite traditional joins as ansi joins as problems might arise using mixed syntax as I have to leave so I don't have time to complete the query
    select sca.branch_code "BRANCH",
           sca.cust_ac_no "ACCOUNT",
           to_char(p_applDate, 'YYYYMM') "YEARMONTH",
           sca.ccy "CURRENCY",
           sca.account_class "PRODUCT",
           sca.cust_no "CUSTOMER",
           sca.ac_desc "DESCRIPTION",
           null "LOW_BAL",
           null "HIGH_BAL",
           null "AVG_CR_BAL",
           null "AVG_DR_BAL",
           null "CR_DAYS",
           null "DR_DAYS",
    --     null "CR_TURNOVER",
    --     null "DR_TURNOVER",
           null "DR_OD_DAYS",
           w.dd "OD_LIMIT",
    --     sc.credit_rating "CR_GRADE",
           null "AVG_NET_BAL",
           null "UNAUTH_OD_AMT",
           sca.acy_blocked_amount "AMT_BLOCKED",
           x.dr_int "DR_INTEREST",
           x.cr_int "CR_INTEREST",
           y.fee_amt "FEE_INCOME",
           sca.record_stat "ACC_STATUS",
           case when trunc(sca.ac_open_date,'MM') = trunc(p_applDate,'MM')
                 and not exists(select 1
                                  from ictm_tdpayin_details itd
                                 where itd.multimode_payopt = 'Y'
                                   and itd.brn = sca.branch_code
                                   and itd.acc = sca.cust_ac_no
                                   and itd.multimode_offset_brn is not null
                                   and itd.multimode_tdoffset_acc is not null
                then 1
                else 0
           end "NEW_ACC_FOR_THE_MONTH",
           case when (trunc(sca.ac_open_date,'MM') = trunc(p_applDate,'MM')
                 and trunc(sc.cif_creation_date,'MM') = trunc(p_applDate,'MM')
                 and not exists(select 1
                                  from ictm_tdpayin_details itd
                                 where itd.multimode_payopt = 'Y'
                                   and itd.brn = sca.branch_code
                                   and itd.acc = sca.cust_ac_no
                                   and itd.multimode_offset_brn is not null
                                   and itd.multimode_tdoffset_acc is not null
                then 1
                else 0
           end "NEW_ACC_FOR_NEW_CUST",
           (select 1 from dual
             where exists(select 1
                            from ictm_td_closure_renew itcr
                           where itcr.brn = sca.branch_code
                             and itcr.acc = sca.cust_ac_no
                             and itcr.renewal_date = sysdate
                or exists(select 1
                            from ictm_tdpayin_details itd
                           where itd.multimode_payopt = 'Y'
                             and itd.brn = sca.branch_code
                             and itd.acc = sca.cust_ac_no
                             and itd.multimode_offset_brn is not null
                             and itd.multimode_tdoffset_acc is not null
           ) "RENEWED_OR_ROLLOVER",
           m.maturity_date "MATURITY_DATE",
           sca.ac_stat_no_dr "DR_DISALLOWED",
           sca.ac_stat_no_cr "CR_DISALLOWED",
    --     sca.ac_stat_block "BLOCKED_ACC", --Not Reqd
           sca.ac_stat_dormant "DORMANT_ACC",
           sca.ac_stat_stop_pay "STOP_PAY_ACC", --New
           sca.ac_stat_frozen "FROZEN_ACC",
           sca.ac_open_date "ACC_OPENING_DT",
           sca.address1 "ADD_LINE_1",
           sca.address2 "ADD_LINE_2",
           sca.address3 "ADD_LINE_3",
           sca.address4 "ADD_LINE_4",
           sca.joint_ac_indicator "JOINT_ACC",
           sca.acy_avl_bal "CR_BAL",
           0 "DR_BAL",
           0 "CR_BAL_LCY", t
           0 "DR_BAL_LCY",
           null "YTD_CR_MOVEMENT",
           null "YTD_DR_MOVEMENT",
           null "YTD_CR_MOVEMENT_LCY",
           null "YTD_DR_MOVEMENT_LCY",
           null "MTD_CR_MOVEMENT",
           null "MTD_DR_MOVEMENT",
           null "MTD_CR_MOVEMENT_LCY",
           null "MTD_DR_MOVEMENT_LCY",
           'N' "BRANCH_TRFR", --New
           sca.provision_amount "PROVISION_AMT",
           sca.account_type "ACCOUNT_TYPE",
           nvl(sca.tod_limit, 0) "TOD_LIMIT",
           nvl(sca.sublimit, 0) "SUB_LIMIT",
           nvl(sca.tod_limit_start_date, global.min_date) "TOD_START_DATE",
           nvl(sca.tod_limit_end_date, global.max_date) "TOD_END_DATE"
      from sttm_cust_account sca,
           sttm_customer sc,
           (select sca.cust_ac_no
                   sum(gf.limit_amount * (scal.linkage_percentage / 100)) +
                       case when p_applDate >= sca.tod_limit_start_date
                             and p_applDate <= nvl(sca.tod_limit_end_date, p_applDate)
                            then sca.tod_limit else 0
                       end
                      ) dd
              from sttm_cust_account sca
                   getm_facility gf,
                   sttm_cust_account_linkages scal
             where gf.line_code || gf.line_serial = scal.linked_ref_no
               and cust_ac_no = sca.cust_ac_no
             group by sca.cust_ac_no
           ) w,
           (select acc,
                   brn,
                   sum(decode(drcr,'D',amt)) dr_int,
                   sum(decode(drcr,'C',amt)) cr_int
              from ictb_entries_history ieh
             where ent_dt between p_st_dt and p_ed_dt
               and drcr in ('C','D')
               and liqn = 'Y'
               and entry_passed = 'Y'
               and exists(select null
                            from ictm_pr_int ipi,
                                 ictm_rule_frm irf
                           where ipi.rule = irf.rule_id
                             and ipi.product_code = ieh.prod 
                             and irf.book_flag = 'B'
             group by acc,brn
           ) x,
           (select acc,
                   brn,
                   sum(amt) fee_amt
              from ictb_entries_history ieh
             where ieh.ent_dt between p_st_dt and p_ed_dt
               and exists(select product_code
                            from ictm_product_definition ipd
                           where ipd.product_code = ieh.prod
                             and ipd.product_type = 'C'
             group by acc,brn
           ) y,
           ictm_acc m,
           (select sca.cust_ac_no,
                   sca.branch_code
                   coalesce(nvl2(coalesce(t1.ac_no,t1.ac_branch),'exists',null),
                            nvl2(coalesce(t2.account,t2.account),'exists',null),
                            nvl2(coalesce(t3.acc,t3.brn),'exists',null),
                            nvl2(coalesce(t4.cust_ac_no,t4.branch_code),'exists',null),
                            nvl2(coalesce(t5.cust_ac_no,t5.branch_code),'exists',null),
                            nvl2(coalesce(t6.cust_ac_no,t6.branch_code),'exists',null),
                            nvl2(coalesce(t7.cust_ac_no,t7.branch_code),'exists',null),
                            decode(sca.maker_dt_stamp,p_applDate,'exists'),
                            decode(sca.status_since,p_applDate,'exists')
                           ) existence
              from sttm_cust_account sca
                   left outer join
                   (select ac_no,ac_branch
                      from actb_daily_log
                     where trn_dt = p_applDate
                       and auth_stat = 'A'
                   ) t1
                on (sca.cust_ac_no = t1.ac_no
               and  sca.branch_code = t1.ac_branch
                   left outer join
                   (select account,account
                      from catm_amount_blocks
                     where effective_date = p_applDate
                       and auth_stat = 'A'
                   ) t2
                on (sca.cust_ac_no = t2.account
               and  sca.branch_code = t2.branch
                   left outer join
                   (select acc,brn
                      from ictm_td_closure_renew itcr
                     where renewal_date = p_applDate
                   ) t3
                on (sca.cust_ac_no = t3.acc
               and  sca.branch_code = t3.brn
                   left outer join
                   (select cust_ac_no,branch_code
                      from sttm_ac_stat_change
                     where status_change_date = p_applDate
                       and auth_stat = 'A'
                   ) t4
                on (sca.cust_ac_no = t4.cust_ac_no
               and  sca.branch_code = t4.branch_code
                   left outer join
                   (select cust_ac_no,branch_code
                      from cstb_acc_brn_trfr_log
                     where process_date = p_applDate
                       and process_status = 'S'
                   ) t5
                on (sca.cust_ac_no = t5.cust_ac_no
               and  sca.branch_code = t5.branch_code
                   left outer join
                   (select cust_ac_no,branch_code
                      from sttbs_provision_history
                     where esn_date = p_applDate
                   ) t6
                on (sca.cust_ac_no = t6.cust_ac_no
               and  sca.branch_code = t6.branch_code
                   left outer join
                   (select cust_ac_no,branch_code
                      from sttms_cust_account_dormancy
                     where dormancy_start_dt = p_applDate
                   ) t7
                on (sca.cust_ac_no = t7.cust_ac_no
               and  sca.branch_code = t7.branch_code
           ) z
    where sca.branch_code = p_branch_code
       and sca.cust_no = sc.customer_no
       and sca.cust_ac_no = w.cust_ac_no
       and sca.cust_ac_no = x.acc
       and sca.branch_code = x.brn
       and sca.cust_ac_no = y.acc
       and sca.branch_code = y.brn
       and sca.cust_ac_no = m.acc
       and sca.branch_code = m.brn
       and sca.cust_ac_no = z.sca.cust_ac_no
       and sca.branch_code = z.branch_code
       and z.existence is not nullRegards
    Etbin

  • Help regarding a select Query

    hi All,
    I have one requirement.I wonder whether i can do it in a single SQL Statement or not.
    I have tab1 with columns c1,c2,c3,c4,....,Logon_time
    I have tab2 with columns C1,c2,c3,c4.....,Logoff_time
    All the columns are same for two tables except that logon_time and logoff_time as mentioned above.
    tab1 will have all the information of user who logon to database.
    tab2 will have all the information of user who logoff from DB.
    Now i i have to generate a report which shows all the user info and logon Duration.For that i can use logoff_time - logon_time.but the challenge here is logoff_time dont contain rows for the users who logon to database byt yet to logoff.
    So for them logoff_time-logon_time showing -ve Duration.
    So I want Duration as logoff_time-logon_time for all the rows.But for those users who yet to logoff i want duration as "YET to Logoff"
    Is this possible with single Select Query.
    Thanks
    Pramod

    Hi, Pramod,
    You need to join tab_1 to tab_2. Since not every row in tab_1 will have a matching row in tab_2, make it an outer join.
    How do you know which row in tab_1 matches which row in tab_2?
    I assume there's some column (let's say c1) that identifies a user. A user can have several sessions going at the same time, however.
    The following query matches the n-th logon_time in tab_1 with the n-th logoff_time in tab_2 for the same user:
    WITH     numbered_tab_1     AS
         SELECT  c1, c2, c3, c4, ..., logon_time
         ,     ROW_NUMBER () OVER ( PARTITION BY  c1     -- or whatever identifies user
                                   ORDER BY          logon_time
                           ) AS r_num
         FROM     tab_1
    ,     numbered_tab_2     AS
         SELECT  c1, c2, c3, c4, ..., logon_time
         ,     ROW_NUMBER () OVER ( PARTITION BY  c1     -- or whatever identifies user
                                   ORDER BY          logoff_time
                           ) AS r_num
         FROM     tab_2
    SELECT     t1.c1, t1.c2, t1.c3, t1.c4, ..., t1.logon_time     -- or whatever you want
    ,     t2.c1, t2.c2, t2.c3, t2.c4, ..., t2.logoff_time
    ,     NVL ( TO_CHAR (24 * (t2.logff_time - t1.logon_time))    -- duration in hours
             , 'Yet to Logoff'
             )         AS duration
    FROM             numbered_tab_1     t1
    LEFT OUTER JOIN     numbered_tab_2     t2     ON   t1.c1     = t2.c1
                                     AND  t1.r_num  = t2.r_num
    ;I can test this if you'll post some sample data and the results you want from that data.
    The query above matches logons and logoffs only by user and time
    For example, say I log on at 10:00.
    At 10:45, I open another window and log on again, but log off at 10:50 after 5 minutes.
    At 11:30 I log off the first session.
    If you were interested in sessions that lasted over 1 hour, the query above would not be accurate. It would show one session starting at 10:00 and ending at 10:50, and another session starting at 10:45 and ending at 11:30. To know that the first session to end was the second sessiion in order of beginning, you would have to have another column, say a unique session id.
    If you're only interested in the number of sessions, or the total time connected per user, then the query above will be good enough.
    Edited by: Frank Kulash on Jul 6, 2009 12:07 PM

  • Select Query failing on a  table that has per sec heavy insertions.

    Hi
    Problem statement
    1- We are using 11g as an database.
    2- We have a table that is partitioned on the date as range partition.
    3- The insertion of data is very high.i.e. several hundreds records per sec. in the current partitioned.
    4- The data is continuously going in the current partitioned as and when buffer is full or per sec timer expires.
    5-- We have to make also select query on the same table and on the current partitioned say for the latest 500 records.
    6- Effecient indexes are also created on the table.
    Solutions Tried.
    1- After analyzing by tkprof it is observed that select and execute is working fine but fetch is taking too much time to show the out put. Say it takes 1 hour.
    2- Using the 11g sql advisior and SPM several baseline is created but the success rate of them is observed also too low.
    please suggest any solution to this issue
    1- i.e. Redisgn of table.
    2- Any better way to quey to fix the fetch issue.
    3- Any oracle seetings or parameter changes to fix the fetch issue.
    Thanks in advance.
    Regards
    Vishal Sharma

    I am uploading the latest stats please let me know how can improve as this is taking 25 minutes
    ####TKPROF output#########
    SQL ID : 2j5w6bv437cak
    select almevttbl.AlmEvtId, almevttbl.AlmType, almevttbl.ComponentId,
      almevttbl.TimeStamp, almevttbl.Severity, almevttbl.State,
      almevttbl.Category, almevttbl.CauseCode, almevttbl.UnitType,
      almevttbl.UnitId, almevttbl.UnitName, almevttbl.ServerName,
      almevttbl.StrParam, almevttbl.ExtraStrParam, almevttbl.ExtraStrParam2,
      almevttbl.ExtraStrParam3, almevttbl.ParentCustId, almevttbl.ExtraParam1,
      almevttbl.ExtraParam2, almevttbl.ExtraParam3,almevttbl.ExtraParam4,
      almevttbl.ExtraParam5, almevttbl.SRCIPADDRFAMILY,almevttbl.SrcIPAddress11,
      almevttbl.SrcIPAddress12,almevttbl.SrcIPAddress13,almevttbl.SrcIPAddress14,
      almevttbl.DESTIPADDRFAMILY,almevttbl.DestIPAddress11,
      almevttbl.DestIPAddress12,almevttbl.DestIPAddress13,
      almevttbl.DestIPAddress14,  almevttbl.DestPort, almevttbl.SrcPort,
      almevttbl.SessionDir, almevttbl.CustomerId, almevttbl.ProfileId,
      almevttbl.ParentProfileId, almevttbl.CustomerName, almevttbl.AttkDir,
      almevttbl.SubCategory, almevttbl.RiskCategory, almevttbl.AssetValue,
      almevttbl.IPSAction, almevttbl.l4Protocol,almevttbl.ExtraStrParam4 ,
      almevttbl.ExtraStrParam5,almevttbl.username,almevttbl.ExtraStrParam6,
      IpAddrFamily1,IPAddrValue11,IPAddrValue12,IPAddrValue13,IPAddrValue14,
      IpAddrFamily2,IPAddrValue21,IPAddrValue22,IPAddrValue23,IPAddrValue24
    FROM
           AlmEvtTbl PARTITION(ALMEVTTBLP20100323) WHERE AlmEvtId IN ( SELECT  * FROM
      ( SELECT /*+ FIRST_ROWS(1000) INDEX (AlmEvtTbl AlmEvtTbl_Index) */AlmEvtId
      FROM AlmEvtTbl PARTITION(ALMEVTTBLP20100323) where       ((AlmEvtTbl.Customerid
      = 0 or AlmEvtTbl.ParentCustId = 0))  ORDER BY AlmEvtTbl.TIMESTAMP DESC) 
      WHERE ROWNUM  <  602) order by timestamp desc
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.10       0.17          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch       42   1348.25    1521.24       1956   39029545          0         601
    total       44   1348.35    1521.41       1956   39029545          0         601
    Misses in library cache during parse: 1
    Optimizer mode: FIRST_ROWS
    Parsing user id: 82 
    Rows     Row Source Operation
        601  PARTITION RANGE SINGLE PARTITION: 24 24 (cr=39029545 pr=1956 pw=1956 time=11043 us cost=0 size=7426 card=1)
        601   TABLE ACCESS BY LOCAL INDEX ROWID ALMEVTTBL PARTITION: 24 24 (cr=39029545 pr=1956 pw=1956 time=11030 us cost=0 size=7426 card=1)
        601    INDEX FULL SCAN ALMEVTTBL_INDEX PARTITION: 24 24 (cr=39029377 pr=1956 pw=1956 time=11183 us cost=0 size=0 card=1)(object id 72557)
        601     FILTER  (cr=39027139 pr=0 pw=0 time=0 us)
    169965204      COUNT STOPKEY (cr=39027139 pr=0 pw=0 time=24859073 us)
    169965204       VIEW  (cr=39027139 pr=0 pw=0 time=17070717 us cost=0 size=13 card=1)
    169965204        PARTITION RANGE SINGLE PARTITION: 24 24 (cr=39027139 pr=0 pw=0 time=13527031 us cost=0 size=48 card=1)
    169965204         TABLE ACCESS BY LOCAL INDEX ROWID ALMEVTTBL PARTITION: 24 24 (cr=39027139 pr=0 pw=0 time=10299895 us cost=0 size=48 card=1)
    169965204          INDEX FULL SCAN ALMEVTTBL_INDEX PARTITION: 24 24 (cr=1131414 pr=0 pw=0 time=3222624 us cost=0 size=0 card=1)(object id 72557)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                      42        0.00          0.00
      SQL*Net message from client                    42       11.54        133.54
      db file sequential read                      1956        0.20         28.00
      latch free                                     21        0.00          0.01
      latch: cache buffers chains                     9        0.01          0.02
    SQL ID : 0ushr863b7z39
    SELECT /* OPT_DYN_SAMP */ /*+ ALL_ROWS IGNORE_WHERE_CLAUSE
      NO_PARALLEL(SAMPLESUB) opt_param('parallel_execution_enabled', 'false')
      NO_PARALLEL_INDEX(SAMPLESUB) NO_SQL_TUNE */ NVL(SUM(C1),0), NVL(SUM(C2),0)
    FROM
    (SELECT /*+ IGNORE_WHERE_CLAUSE NO_PARALLEL("PLAN_TABLE") FULL("PLAN_TABLE")
      NO_PARALLEL_INDEX("PLAN_TABLE") */ 1 AS C1, CASE WHEN
      "PLAN_TABLE"."STATEMENT_ID"=:B1 THEN 1 ELSE 0 END AS C2 FROM
      "SYS"."PLAN_TABLE$" "PLAN_TABLE") SAMPLESUB
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.01          1          3          0           1
    total        3      0.00       0.01          1          3          0           1
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 82     (recursive depth: 1)
    Rows     Row Source Operation
          1  SORT AGGREGATE (cr=3 pr=1 pw=1 time=0 us)
          0   TABLE ACCESS FULL PLAN_TABLE$ (cr=3 pr=1 pw=1 time=0 us cost=29 size=138856 card=8168)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      db file sequential read                         1        0.01          0.01
    SQL ID : bjkdb51at8dnb
    EXPLAIN PLAN SET STATEMENT_ID='PLUS30350011' FOR select almevttbl.AlmEvtId,
      almevttbl.AlmType, almevttbl.ComponentId, almevttbl.TimeStamp,
      almevttbl.Severity, almevttbl.State, almevttbl.Category,
      almevttbl.CauseCode, almevttbl.UnitType, almevttbl.UnitId,
      almevttbl.UnitName, almevttbl.ServerName, almevttbl.StrParam,
      almevttbl.ExtraStrParam, almevttbl.ExtraStrParam2, almevttbl.ExtraStrParam3,
       almevttbl.ParentCustId, almevttbl.ExtraParam1, almevttbl.ExtraParam2,
      almevttbl.ExtraParam3,almevttbl.ExtraParam4,almevttbl.ExtraParam5,
      almevttbl.SRCIPADDRFAMILY,almevttbl.SrcIPAddress11,almevttbl.SrcIPAddress12,
      almevttbl.SrcIPAddress13,almevttbl.SrcIPAddress14,
      almevttbl.DESTIPADDRFAMILY,almevttbl.DestIPAddress11,
      almevttbl.DestIPAddress12,almevttbl.DestIPAddress13,
      almevttbl.DestIPAddress14,  almevttbl.DestPort, almevttbl.SrcPort,
      almevttbl.SessionDir, almevttbl.CustomerId, almevttbl.ProfileId,
      almevttbl.ParentProfileId, almevttbl.CustomerName, almevttbl.AttkDir,
      almevttbl.SubCategory, almevttbl.RiskCategory, almevttbl.AssetValue,
      almevttbl.IPSAction, almevttbl.l4Protocol,almevttbl.ExtraStrParam4 ,
      almevttbl.ExtraStrParam5,almevttbl.username,almevttbl.ExtraStrParam6,
      IpAddrFamily1,IPAddrValue11,IPAddrValue12,IPAddrValue13,IPAddrValue14,
      IpAddrFamily2,IPAddrValue21,IPAddrValue22,IPAddrValue23,IPAddrValue24 FROM 
           AlmEvtTbl PARTITION(ALMEVTTBLP20100323) WHERE AlmEvtId IN ( SELECT  * FROM
      ( SELECT /*+ FIRST_ROWS(1000) INDEX (AlmEvtTbl AlmEvtTbl_Index) */AlmEvtId
      FROM AlmEvtTbl PARTITION(ALMEVTTBLP20100323) where       ((AlmEvtTbl.Customerid
      = 0 or AlmEvtTbl.ParentCustId = 0))  ORDER BY AlmEvtTbl.TIMESTAMP DESC) 
      WHERE ROWNUM  <  602) order by timestamp desc
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.28       0.26          0          0          0           0
    Execute      1      0.01       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        2      0.29       0.27          0          0          0           0
    Misses in library cache during parse: 1
    Optimizer mode: FIRST_ROWS
    Parsing user id: 82 
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       1        0.00          0.00
      SQL*Net message from client                     1        0.00          0.00
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse       13      0.71       0.96          3         10          0           0
    Execute     14      0.20       0.29          4        304         26          21
    Fetch       92   2402.17    2714.85       3819   70033708          0        1255
    total      119   2403.09    2716.10       3826   70034022         26        1276
    Misses in library cache during parse: 10
    Misses in library cache during execute: 6
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                      49        0.00          0.00
      SQL*Net message from client                    48       29.88        163.43
      db file sequential read                      1966        0.20         28.10
      latch free                                     21        0.00          0.01
      latch: cache buffers chains                     9        0.01          0.02
      latch: session allocation                       1        0.00          0.00
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse      940      0.51       0.73          1          2         38           0
    Execute   3263      1.93       2.62          7       1998         43          23
    Fetch     6049      1.32       4.41        214      12858         36       13724
    total    10252      3.78       7.77        222      14858        117       13747
    Misses in library cache during parse: 172
    Misses in library cache during execute: 168
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      db file sequential read                        88        0.04          0.62
      latch: shared pool                              8        0.00          0.00
      latch: row cache objects                        2        0.00          0.00
      latch free                                      1        0.00          0.00
      latch: session allocation                       1        0.00          0.00
       34  user  SQL statements in session.
    3125  internal SQL statements in session.
    3159  SQL statements in session.
    Trace file: ora11g_ora_2064.trc
    Trace file compatibility: 11.01.00
    Sort options: default
           6  sessions in tracefile.
          98  user  SQL statements in trace file.
        9111  internal SQL statements in trace file.
        3159  SQL statements in trace file.
          89  unique SQL statements in trace file.
       30341  lines in trace file.
        6810  elapsed seconds in trace file.
    ###################################### AutoTrace Output#################  
    Statistics
           3901  recursive calls
              0  db block gets
       39030275  consistent gets
           1970  physical reads
            140  redo size
         148739  bytes sent via SQL*Net to client
            860  bytes received via SQL*Net from client
             42  SQL*Net roundtrips to/from client
             73  sorts (memory)
              0  sorts (disk)
            601  rows processed

  • Preceding error in select query

    Hi,
    I am executing select query using db link
    and getting an error : ora:-01401: inserted value too large for column ora:-02063 preceding line from catalyst_promo
    Below is my query. can anybody please suggest what is the error
    SELECT GLOM.*
    ,NVL2(FLAGS.PLAN_ID,INITCAP('YES'),INITCAP('NO')) AS MULTI_COMP_KEYS
    FROM
    (SELECT *
    FROM (SELECT
    OA.PLAN_ID
    , OA.MATERIAL_GROUP_CD
    FROM MSRPROMO.OUTPUT_ASSIGNMENT OA
    GROUP BY OA.PLAN_ID
    , OA.MATERIAL_GROUP_CD
    HAVING SUM(1) > 1)) FLAGS
    ,(SELECT CALIPER
    ,WT
    ,DIMS
    ,ATTRIBUTES
    ,PLAN_ID
    ,MATERIAL_GROUP_CD
    ,FORMAT_TXT
    ,FORECAST_QTY
    ,COMPUTER_KEY
    ,CAT_PACKAGE_KEY
    ,MAIL_CLASS_CD
    ,MAIL_TYPE_CD
    ,PLAN_NAME
    ,PLAN_DESC
    ,DISTRIBUTION_CYCLE_CD
    ,FIRST_CONTACT_DT
    ,CAMPAIGN_NUMBER
    ,COMPONENT_ITEM
    ,ITEM_TYPE
    ,LTRSHP_INSTRUCTION
    ,MFG_INSTRUCTION
    FROM (
    SELECT NVL(o102882.CAT_CALIPER_NBR,o102882.ADJUSTED_CALIPER_NBR) AS CALIPER
    ,NVL(o102882.CAT_WEIGHT_NBR,o102882.ADJUSTED_WEIGHT_NBR) AS WT
    ,CONCAT(o102882.CAT_FINAL_DEPTH_NBR,CONCAT(' x ',o102882.CAT_FINAL_WIDTH_NBR)) AS DIMS
    ,DECODE(o102913.ATTRIBUTE_CODE,'Number Colors Front',
    CONCAT('Colors Front: ',o102913.ATTRIBUTE_VALUE),'Number Colors Back',
    CONCAT('Colors Back: ',o102913.ATTRIBUTE_VALUE),'Dimension - Depth',
    CONCAT('Dim-Length: ',o102913.ATTRIBUTE_VALUE),'Dimension - Width',
    CONCAT('Dim-Width: ',o102913.ATTRIBUTE_VALUE),'Customer Dimension - Depth',
    CONCAT('Dim-Length: ',o102913.ATTRIBUTE_VALUE),'Customer Dimension - Width',
    CONCAT('Dim-Width: ',o102913.ATTRIBUTE_VALUE),'Number Windows Front',
    CONCAT('Windows Front: ',o102913.ATTRIBUTE_VALUE),'Number Windows Back',
    CONCAT('Windows Back: ',o102913.ATTRIBUTE_VALUE),'Material Type',
    CONCAT('Material Type: ',o102913.ATTRIBUTE_VALUE),'Dimension - Final Depth',
    CONCAT('Dim-Final Length: ',o102913.ATTRIBUTE_VALUE),'Dimension - Final Width',
    CONCAT('Dim-Final Width: ',o102913.ATTRIBUTE_VALUE),'') AS ATTRIBUTES
    ,O102864.PLAN_ID
    ,o102864.MATERIAL_GROUP_CD
    ,o102864.FORMAT_TXT
    ,o102864.FORECAST_QTY
    ,o102880.COMPUTER_KEY
    ,o102882.CAT_PACKAGE_KEY
    ,o102882.MAIL_CLASS_CD
    ,o102882.MAIL_TYPE_CD
    ,o102907.PLAN_NAME
    ,o102907.PLAN_DESC
    ,o102907.DISTRIBUTION_CYCLE_CD
    ,o102907.FIRST_CONTACT_DT
    ,o297532.CAMPAIGN_NUMBER
    ,o102928.COMPONENT_ITEM
    ,o102928.ITEM_TYPE
    ,o102919.LTRSHP_INSTRUCTION
    ,o102921.MFG_INSTRUCTION
    FROM MSRPROMO.MATERIAL_GROUP o102864,
    MSRPROMO.OUTPUT_ASSIGNMENT o102880,
    MSRPROMO.OUTPUT_INSTRUCTION o102882,
    MSRPROMO.PROMOTION_PLAN o102907,
    /*RDIGEST.RDAIS_ATTRIBUTE_VALUES@"CATALYST_PROMO.US.RDIGEST.COM" o102913,*/
    (SELECT /*+DRIVING_SITE(RDAIS3) */
    RDAIS3.SPEC_TYPE_CODE
    , RDAIS3.SPEC_ID
    , RDAIS3.TEMPLATE_ID
    , RDAIS3.ATTRIBUTE_CODE
    , (CASE WHEN RDAIS3.ATTRIBUTE_VALUE = CONVERT(CONVERT(RDAIS3.ATTRIBUTE_VALUE,'AL16UTF16'),'UTF8','AL16UTF16')
    THEN RDAIS3.ATTRIBUTE_VALUE
    ELSE (CASE WHEN RDAIS3.ATTRIBUTE_VALUE IS NULL
    THEN NULL
    ELSE '*** Attribute Value Multi-Byte Error ***' END) END) AS ATTRIBUTE_VALUE
    , (CASE WHEN RDAIS3.ATTRIBUTE_VALUE = CONVERT(CONVERT(RDAIS3.ATTRIBUTE_VALUE,'AL16UTF16'),'UTF8','AL16UTF16')
    THEN 0
    ELSE (CASE WHEN RDAIS3.ATTRIBUTE_VALUE IS NULL
    THEN 0 ELSE 1 END) END) AS ATTRIBUTE_ERR_CNT
    , RDAIS3.SPEC_LEVEL
    , RDAIS3.SEQ
    , RDAIS3.LAST_UPDATE_LOGIN
    , RDAIS3.LAST_UPDATED_BY
    , RDAIS3.LAST_UPDATE_DATE
    , RDAIS3.CREATED_BY
    , RDAIS3.CREATION_DATE
    FROM RDIGEST.RDAIS_ATTRIBUTE_VALUES@"CATALYST_PROMO.US.RDIGEST.COM" RDAIS3
    ,(SELECT /*+DRIVING_SITE(RDAIS2) */
    DISTINCT RDAIS2.ITEM_SPEC_ID
    FROM RDIGEST.RDAIS_ITEM_SPECS@"CATALYST_PROMO.US.RDIGEST.COM" RDAIS2
    ,(SELECT /*+DRIVING_SITE(RDAIS1) */
    DISTINCT RDAIS1.OBJECT_ID
    FROM RDIGEST.RDAIS_ORG_ASSIGNMENTS@"CATALYST_PROMO.US.RDIGEST.COM" RDAIS1
    WHERE RDAIS1.OBJECT_TYPE_CODE = 1
    AND RDAIS1.ORGANIZATION_ID in(55,162)) DRV
    WHERE DRV.OBJECT_ID = RDAIS2.ITEM_SPEC_ID) DRIVER
    WHERE DRIVER.ITEM_SPEC_ID = RDAIS3.SPEC_ID) o102913,
    /* RDIGEST.RDAIS_ITEM_SPECS@"CATALYST_PROMO.US.RDIGEST.COM" o102917, */
    (SELECT /*+DRIVING_SITE(RDAIS2) */
    RDAIS2.ITEM_SPEC_ID
    , RDAIS2.TEMPLATE_ID
    , RDAIS2.LOCAL_MKTG_KEY
    , (CASE WHEN RDAIS2.DESCRIPTION = CONVERT(CONVERT(RDAIS2.DESCRIPTION,'AL16UTF16'),'UTF8','AL16UTF16')
    THEN RDAIS2.DESCRIPTION
    ELSE (CASE WHEN RDAIS2.DESCRIPTION IS NULL
    THEN NULL
    ELSE '*** Item Specs Description Multi-Byte Error ***' END) END) AS DESCRIPTION
    , (CASE WHEN RDAIS2.DESCRIPTION = CONVERT(CONVERT(RDAIS2.DESCRIPTION,'AL16UTF16'),'UTF8','AL16UTF16')
    THEN 0
    ELSE (CASE WHEN RDAIS2.DESCRIPTION IS NULL
    THEN 0 ELSE 1 END) END) AS ITEM_SPECS_ERR_CNT
    , RDAIS2.COPIED_FROM_KEY
    , RDAIS2.TEMPLATE_NAME
    , RDAIS2.SPEC_LEVEL
    , RDAIS2.PKG_TYPE
    , RDAIS2.SEGMENT1
    , RDAIS2.SEGMENT2
    , RDAIS2.SEGMENT3
    , RDAIS2.SEGMENT4
    , RDAIS2.SEGMENT5
    , RDAIS2.SEGMENT6
    , RDAIS2.VALIDATION_STATUS
    , RDAIS2.DATE_INTERFACED
    , RDAIS2.ERROR_FLAG
    , RDAIS2.INVENTORY_ITEM_ID
    , RDAIS2.MFG_SPEC_ID
    , RDAIS2.ATTRIBUTE1
    , RDAIS2.ATTRIBUTE2
    , RDAIS2.ATTRIBUTE3
    , RDAIS2.ATTRIBUTE4
    , RDAIS2.ATTRIBUTE5
    , RDAIS2.ATTRIBUTE6
    , RDAIS2.ATTRIBUTE7
    , RDAIS2.ATTRIBUTE8
    , RDAIS2.ATTRIBUTE9
    , RDAIS2.ATTRIBUTE10
    , RDAIS2.ATTRIBUTE11
    , RDAIS2.ATTRIBUTE12
    , RDAIS2.ATTRIBUTE13
    , RDAIS2.ATTRIBUTE14
    , RDAIS2.ATTRIBUTE15
    , RDAIS2.ATTRIBUTE16
    , RDAIS2.ATTRIBUTE17
    , RDAIS2.ATTRIBUTE18
    , RDAIS2.ATTRIBUTE19
    , RDAIS2.ATTRIBUTE20
    , RDAIS2.ATTRIBUTE21
    , RDAIS2.ATTRIBUTE22
    , RDAIS2.ATTRIBUTE23
    , RDAIS2.ATTRIBUTE24
    , RDAIS2.ATTRIBUTE25
    , RDAIS2.ATTRIBUTE26
    , RDAIS2.ATTRIBUTE27
    , RDAIS2.ATTRIBUTE28
    , RDAIS2.ATTRIBUTE29
    , RDAIS2.ATTRIBUTE30
    , RDAIS2.COMPLETE_FLAG
    , RDAIS2.LAST_UPDATE_LOGIN
    , RDAIS2.LAST_UPDATED_BY
    , RDAIS2.LAST_UPDATE_DATE
    , RDAIS2.CREATED_BY
    , RDAIS2.CREATION_DATE
    FROM RDIGEST.RDAIS_ITEM_SPECS@"CATALYST_PROMO.US.RDIGEST.COM" RDAIS2
    ,(SELECT /*+DRIVING_SITE(RDAIS1) */
    DISTINCT RDAIS1.OBJECT_ID
    FROM RDIGEST.RDAIS_ORG_ASSIGNMENTS@"CATALYST_PROMO.US.RDIGEST.COM" RDAIS1
    WHERE RDAIS1.OBJECT_TYPE_CODE = 1
    AND RDAIS1.ORGANIZATION_ID =55) DRIVER
    WHERE DRIVER.OBJECT_ID = RDAIS2.ITEM_SPEC_ID) o102917,
    /* RDIGEST.RDAIS_LTRSHP_INSTRUCTIONS@"CATALYST_PROMO.US.RDIGEST.COM" o102919, */
    (SELECT /*+DRIVING_SITE(RDAIS3) */
    RDAIS3.OBJECT_ID
    , (CASE WHEN RDAIS3.LTRSHP_INSTRUCTION = CONVERT(CONVERT(RDAIS3.LTRSHP_INSTRUCTION,'AL16UTF16'),'UTF8','AL16UTF16')
    THEN RDAIS3.LTRSHP_INSTRUCTION
    ELSE (CASE WHEN RDAIS3.LTRSHP_INSTRUCTION IS NULL
    THEN NULL
    ELSE '*** Letter Shop Instruction Multi-Byte Error ***' END) END) AS LTRSHP_INSTRUCTION
    , (CASE WHEN RDAIS3.LTRSHP_INSTRUCTION = CONVERT(CONVERT(RDAIS3.LTRSHP_INSTRUCTION,'AL16UTF16'),'UTF8','AL16UTF16')
    THEN 0
    ELSE (CASE WHEN RDAIS3.LTRSHP_INSTRUCTION IS NULL
    THEN 0 ELSE 1 END) END) AS LTRSHP_INST_ERR_CNT
    , RDAIS3.LAST_UPDATE_LOGIN
    , RDAIS3.LAST_UPDATED_BY
    , RDAIS3.LAST_UPDATE_DATE
    , RDAIS3.CREATED_BY
    , RDAIS3.CREATION_DATE
    FROM RDIGEST.RDAIS_LTRSHP_INSTRUCTIONS@"CATALYST_PROMO.US.RDIGEST.COM" RDAIS3
    ,(SELECT /*+DRIVING_SITE(RDAIS2) */
    DISTINCT RDAIS2.ITEM_SPEC_ID
    FROM RDIGEST.RDAIS_ITEM_SPECS@"CATALYST_PROMO.US.RDIGEST.COM" RDAIS2
    ,(SELECT /*+DRIVING_SITE(RDAIS1) */
    DISTINCT RDAIS1.OBJECT_ID
    FROM RDIGEST.RDAIS_ORG_ASSIGNMENTS@"CATALYST_PROMO.US.RDIGEST.COM" RDAIS1
    WHERE RDAIS1.OBJECT_TYPE_CODE = 1
    AND RDAIS1.ORGANIZATION_ID =55) DRV
    WHERE DRV.OBJECT_ID = RDAIS2.ITEM_SPEC_ID) DRIVER
    WHERE DRIVER.ITEM_SPEC_ID = RDAIS3.OBJECT_ID) o102919,
    /* RDIGEST.RDAIS_MFG_INSTRUCTIONS@"CATALYST_PROMO.US.RDIGEST.COM" o102921, */
    (SELECT /*+DRIVING_SITE(RDAIS3) */
    RDAIS3.OBJECT_ID
    , (CASE WHEN RDAIS3.MFG_INSTRUCTION = CONVERT(CONVERT(RDAIS3.MFG_INSTRUCTION,'AL16UTF16'),'UTF8','AL16UTF16')
    THEN RDAIS3.MFG_INSTRUCTION
    ELSE (CASE WHEN RDAIS3.MFG_INSTRUCTION IS NULL
    THEN NULL
    ELSE '*** Manufacturing Instruction Multi-Byte Error ***' END) END) AS MFG_INSTRUCTION
    , (CASE WHEN RDAIS3.MFG_INSTRUCTION = CONVERT(CONVERT(RDAIS3.MFG_INSTRUCTION,'AL16UTF16'),'UTF8','AL16UTF16')
    THEN 0
    ELSE (CASE WHEN RDAIS3.MFG_INSTRUCTION IS NULL
    THEN 0 ELSE 1 END) END) AS MFG_INST_ERR_CNT
    , RDAIS3.LAST_UPDATE_LOGIN
    , RDAIS3.LAST_UPDATED_BY
    , RDAIS3.LAST_UPDATE_DATE
    , RDAIS3.CREATED_BY
    , RDAIS3.CREATION_DATE
    FROM RDIGEST.RDAIS_MFG_INSTRUCTIONS@"CATALYST_PROMO.US.RDIGEST.COM" RDAIS3
    ,(SELECT /*+DRIVING_SITE(RDAIS2) */
    DISTINCT RDAIS2.ITEM_SPEC_ID
    FROM RDIGEST.RDAIS_ITEM_SPECS@"CATALYST_PROMO.US.RDIGEST.COM" RDAIS2
    ,(SELECT /*+DRIVING_SITE(RDAIS1) */
    DISTINCT RDAIS1.OBJECT_ID
    FROM RDIGEST.RDAIS_ORG_ASSIGNMENTS@"CATALYST_PROMO.US.RDIGEST.COM" RDAIS1
    WHERE RDAIS1.OBJECT_TYPE_CODE = 1
    AND RDAIS1.ORGANIZATION_ID =55
    ) DRV
    WHERE DRV.OBJECT_ID = RDAIS2.ITEM_SPEC_ID) DRIVER
    WHERE DRIVER.ITEM_SPEC_ID = RDAIS3.OBJECT_ID) o102921,
    /* RDIGEST.RDA_CDBS_EXPLOSION_ITEM_TEMP@"CATALYST_PROMO.US.RDIGEST.COM" o102928, */
    (SELECT /*+DRIVING_SITE(RDA1) DRIVING_SITE(RDA2) */
    RDA1.SYSTEM_CODE /* KEY */
    , RDA1.PLAN /* KEY */
    , RDA1.MATLGRP /* KEY */
    , RDA1.PACKAGE /* KEY */
    , RDA1.INVENTORY_ITEM_ID /* KEY */
    , RDA1.COMPONENT_ITEM
    , RDA1.ITEM_TYPE
    , RDA1.CREATED_BY
    , RDA1.CREATION_DATE
    , RDA1.LAST_UPDATED_BY
    , RDA1.LAST_UPDATE_DATE
    FROM RDIGEST.RDA_CDBS_EXPLOSION_ITEM_TEMP@"CATALYST_PROMO.US.RDIGEST.COM" RDA1
    ,RDIGEST.RDA_CDBS_EXPLOSION_TEMP@"CATALYST_PROMO.US.RDIGEST.COM" RDA2
    WHERE RDA2.ORGANIZATION_ID =55
    AND RDA2.SYSTEM_CODE = RDA1.SYSTEM_CODE
    AND RDA2.PLAN = RDA1.PLAN
    AND RDA2.MATLGRP = RDA1.MATLGRP
    AND RDA2.PACKAGE = RDA1.PACKAGE) o102928,
    ( SELECT
    RDAIS.CAMPAIGN_NUMBER
    , RDAIS.SEQ_NUMBER
    , RDAIS.LEVEL_NUM
    , RDAIS.TYPE
    , RDAIS.CODE
    , RDAIS.DESCRIPTION
    , RDAIS.QUANTITY
    , RDAIS.EFFECTIVE_IN
    , RDAIS.EFFECTIVE_OUT
    , RDAIS.CREATED_BY
    , RDAIS.CREATION_DATE
    , RDAIS.LAST_UPDATE_DATE
    , RDAIS.LAST_UPDATED_BY
    , RDAIS.LAST_UPDATE_LOGIN
    , RDAIS.VALIDATION_STATUS
    , RDAIS.DATE_INTERFACED
    , RDAIS.SEQ_NUM
    , RDAIS.ERROR_FLAG
    , RDAIS.ATTRIBUTE1, RDAIS.ATTRIBUTE2, RDAIS.ATTRIBUTE3, RDAIS.ATTRIBUTE4, RDAIS.ATTRIBUTE5
    , RDAIS.ATTRIBUTE6, RDAIS.ATTRIBUTE7, RDAIS.ATTRIBUTE8, RDAIS.ATTRIBUTE9, RDAIS.ATTRIBUTE10
    FROM RDIGEST.RDA_CAMPAIGN_STRUCTURE@"CATALYST_PROMO.US.RDIGEST.COM" RDAIS
    ,(SELECT /*+DRIVING_SITE(RPC1) */
    DISTINCT RPC1.CAMPAIGN_NUMBER
    FROM RDIGEST.RPC_CAMPAIGNS@"CATALYST_PROMO.US.RDIGEST.COM" RPC1
    WHERE RPC1.ORGANIZATION_ID in (54,161)) RPC2
    WHERE RDAIS.CAMPAIGN_NUMBER = RPC2.CAMPAIGN_NUMBER
    ) o297532
    WHERE ( (O102864.MATERIAL_GROUP_CD = O102880.MATERIAL_GROUP_CD)
    AND (O102880.COMPUTER_KEY = O102882.COMPUTER_KEY)
    AND (O102882.CAT_PACKAGE_KEY = O102928.PACKAGE)
    AND (O102907.PLAN_ID = O102864.PLAN_ID)
    AND (O102917.ITEM_SPEC_ID = O102913.SPEC_ID)
    AND (O102917.ITEM_SPEC_ID = O102919.OBJECT_ID(+))
    AND (O102917.ITEM_SPEC_ID = O102921.OBJECT_ID(+))
    AND (O102928.INVENTORY_ITEM_ID = O102917.INVENTORY_ITEM_ID)
    AND (O102907.PLAN_NAME = O297532.DESCRIPTION)
    AND (O102907.PLAN_NAME = o102928.PLAN))
    AND (O297532.EFFECTIVE_OUT IS NULL )
    AND (O102864.PLAN_ID = O102880.PLAN_ID)
    AND (( SUBSTR(O102882.CAT_PACKAGE_KEY,1,2) ) != 'CK'))
    GROUP BY CALIPER
    ,WT
    ,DIMS
    ,ATTRIBUTES
    ,PLAN_ID
    ,MATERIAL_GROUP_CD
    ,FORMAT_TXT
    ,FORECAST_QTY
    ,COMPUTER_KEY
    ,CAT_PACKAGE_KEY
    ,MAIL_CLASS_CD
    ,MAIL_TYPE_CD
    ,PLAN_NAME
    ,PLAN_DESC
    ,DISTRIBUTION_CYCLE_CD
    ,FIRST_CONTACT_DT
    ,CAMPAIGN_NUMBER
    ,COMPONENT_ITEM
    ,ITEM_TYPE
    ,LTRSHP_INSTRUCTION
    ,MFG_INSTRUCTION) GLOM
    WHERE GLOM.PLAN_ID = FLAGS.PLAN_ID(+)
    AND GLOM.MATERIAL_GROUP_CD = FLAGS.MATERIAL_GROUP_CD(+);

    I shorted my query , still getting same error " ORA-01401: inserted value too large for column ORA-02063: presceding line from CATALYST_PROMO"
    I am sure there is some issue in CONVERT, can anybody please help
    create table O102921 nologging as
    (SELECT /*+DRIVING_SITE(RDAIS3) */
    RDAIS3.OBJECT_ID
    ,(CASE WHEN RDAIS3.MFG_INSTRUCTION = CONVERT(CONVERT(RDAIS3.MFG_INSTRUCTION,'AL16UTF16'),'UTF8','AL16UTF16')
    THEN RDAIS3.MFG_INSTRUCTION
    ELSE (CASE WHEN RDAIS3.MFG_INSTRUCTION IS NULL
    THEN NULL
    ELSE '*** Manufacturing Instruction Multi-Byte Error ***' END) END) AS MFG_INSTRUCTION
    , (CASE WHEN RDAIS3.MFG_INSTRUCTION = CONVERT(CONVERT(RDAIS3.MFG_INSTRUCTION,'AL16UTF16'),'UTF8','AL16UTF16')
    THEN 0
    ELSE (CASE WHEN RDAIS3.MFG_INSTRUCTION IS NULL
    THEN 0 ELSE 1 END) END) AS MFG_INST_ERR_CNT
    , RDAIS3.LAST_UPDATE_LOGIN
    , RDAIS3.LAST_UPDATED_BY
    , RDAIS3.LAST_UPDATE_DATE
    , RDAIS3.CREATED_BY
    , RDAIS3.CREATION_DATE
    FROM RDIGEST.RDAIS_MFG_INSTRUCTIONS@"CATALYST_PROMO.US.RDIGEST.COM" RDAIS3
    ,(SELECT /*+DRIVING_SITE(RDAIS2) */
    DISTINCT RDAIS2.ITEM_SPEC_ID
    FROM RDIGEST.RDAIS_ITEM_SPECS@"CATALYST_PROMO.US.RDIGEST.COM" RDAIS2
    ,(SELECT /*+DRIVING_SITE(RDAIS1) */
    DISTINCT RDAIS1.OBJECT_ID
    FROM RDIGEST.RDAIS_ORG_ASSIGNMENTS@"CATALYST_PROMO.US.RDIGEST.COM" RDAIS1
    WHERE RDAIS1.OBJECT_TYPE_CODE = 1
    AND RDAIS1.ORGANIZATION_ID = 162) DRV
    WHERE DRV.OBJECT_ID = RDAIS2.ITEM_SPEC_ID) DRIVER
    WHERE DRIVER.ITEM_SPEC_ID = RDAIS3.OBJECT_ID );

  • Sum and nvl in a query

    Greedings,
    how is it possible in reports to give a nvl in a query that im getting a summation? For example in my follow query im trying to return d.bas_amount in case VARIANCE is null. Thanks for any help in advance
    Sum(((select d.bas_amount from so_budgets d1 where d1.acnt_code = d.acnt_code
    and Trim(d.period) BETWEEN :P_FROM AND :P_TO AND ROWNUM=1)-
    (SELECT kl.amount FROM & a01_a_salfldg @oracle_to_sun kl WHERE Trim(kl.accnt_code)=Trim(a.acnt_code) AND kl.period between :P_FROM AND :P_TO AND ROWNUM=1))) AS VARIANCE
    ----------------------

    i'm not sure if this works ... but try to add a NVL():
    NVL(SUM((  (SELECT d.bas_amount
                       FROM   so_budgets d1
                       WHERE  d1.acnt_code = d.acnt_code
                       AND    TRIM(d.period) BETWEEN :p_from AND :p_to
                       AND    ROWNUM = 1)
                    - (SELECT kl.amount
                       FROM   a01_a_salfldg kl
                       WHERE  TRIM(kl.accnt_code) = TRIM(a.acnt_code)
                       AND    kl.period BETWEEN :p_from AND :p_to
                       AND    ROWNUM = 1)
               (SELECT d.bas_amount
                FROM   so_budgets d1
                WHERE  d1.acnt_code = d.acnt_code
                AND    TRIM(d.period) BETWEEN :p_from AND :p_to
                AND    ROWNUM = 1)) AS VARIANCE

  • Please help me what other way i can tune this select query..

    Hello Guru,
    I have a select query which retrieve data from 10 tables and around 4 tables having 2-4 Lac record and rest are having 80,000 - 1 Lac record.
    It is taking around 7-8 seconds to fetch 55000 record.
    I was strictly told by the client that i should not use HINTS in my query. My query is below. Please help me what other way i can tune this select query..
    select
    CT.CUST_ID
    ,CT.ROMANISED_SURNAME
    ,CT.SURNAME
    ,CT.ROMANISED_GIVEN_NAME
    ,CT.GIVEN_NAME
    ,CT.ROMANISED_MIDDLE_NAME
    ,CT.MIDDLE_NAME
    ,CT.ROMANISED_NAME_SUFFIX
    ,CT.NAME_SUFFIX
    ,CT.ROMANISED_TITLE
    ,CT.TITLE
    ,CT.ROMANISED_NAME_INITIALS
    ,CT.NAME_INITIALS
    ,CT.NAME_TEXT
    ,CT.CUST_JRNY_ID
    ,RK.REMARK_TYPE
    ,RK.REMARK_ID+CT.CUST_ID as REMARK_ID
    ,RK.REMARK_STATUS
    ,RK.REMARK_TEXT
    ,RK.HOST_ONLY_IND
    ,RK.SUPERVISORY_IND
    ,RK.CUST_COMM_IND
    ,RK.REMARK_SEQ
    ,RK.REMARK_CODE
    ,RK.DEFAULT_CUST_REL_IND
    ,RK.DEFAULT_FLIGHT_SEG_REL_IND
    ,RK.IATA_CODE
    ,RK.ICAO_CODE
    ,CJ.RECORD_LOCATOR "SITA_RECORD_LOCATOR"
    ,Cjv.Record_Locator "ORIGINATOR_RECORD_LOCATOR"
    ,FS.TRAVELLING_GROUP_CODE
    ,CG.GROUP_NAME
    FROM FLIGHT_LEG FL
    ,CUST_FLIGHT_LEG CFL
    ,CUST CT
    ,CUST_REMARK CTR
    ,REMARK RK
    ,FLIGHT_SEG_FLIGHT_LEG FSFL
    ,FLIGHT_SEG FS
    ,CUST_JRNY CJ
    ,CUST_JRNY_VERSION CJV
    ,CUST_GROUP CG
    WHERE FL.OPR_FLIGHT_NUMBER = 1--I_OPR_FLIGHT_NUMBER
    and FL.HISTORY_VERSION_NUMBER = 0
    and FL.DEPARTURE_STATION_CODE = 'DEL'--I_DEPARTURE_STATION_CODE
    and FL.DEPARTURE_DATETIME = TO_DATE('10-DEC-2012 18.45.00', 'DD-MON-YYYY HH24.MI.SS')
    and FL.OPR_SERVICE_PROVIDER_CODE= 'AI'--i_opr_service_provider_code
    and FL.OPR_FLIGHT_SUFFIX = 'A'--NVL(I_OPR_FLIGHT_SUFFIX, FL.OPR_FLIGHT_SUFFIX)
    AND FL.FLIGHT_LEG_ID = CFL.FLIGHT_LEG_ID
    AND CFL.CUST_ID = CT.CUST_ID
    AND FL.FLIGHT_LEG_ID=FSFL.FLIGHT_LEG_ID
    AND FSFL.FLIGHT_SEG_ID=FS.FLIGHT_SEG_ID
    AND CT.CUST_ID = CTR.CUST_ID(+)
    AND CTR.REMARK_ID = RK.REMARK_ID(+)
    AND FL.CUST_JRNY_ID = CJ.CUST_JRNY_ID
    and CJ.CUST_JRNY_ID = CJV.CUST_JRNY_ID
    AND CG.CUST_JRNY_ID(+) = CT.CUST_JRNY_ID
    AND CFL.HISTORY_VERSION_NUMBER = 0
    AND CT.HISTORY_VERSION_NUMBER = 0
    AND NVL(CTR.HISTORY_VERSION_NUMBER,0) = 0
    AND NVL(RK.HISTORY_VERSION_NUMBER,0) = 0
    AND FS.HISTORY_VERSION_NUMBER = 0
    AND FSFL.HISTORY_VERSION_NUMBER = 0
    -- AND CJ.HISTORY_VERSION_NUMBER = 0
    and CJV.VERSION_NUMBER = 0 --- Need to check
    AND NVL(CG.HISTORY_VERSION_NUMBER,0) = 0
    order by CT.CUST_JRNY_ID,CT.CUST_ID;
    The Tables having record:
    select COUNT(*) from FLIGHT_LEG -----241756
    select COUNT(*) from CUST_FLIGHT_LEG---632585
    select COUNT(*) from CUST---240015
    select COUNT(*) from CUST_REMARK---73724
    select COUNT(*) from REMARK---73654
    select COUNT(*) from FLIGHT_SEG_FLIGHT_LEG---241789
    select COUNT(*) from FLIGHT_SEG----260004
    select COUNT(*) from CUST_JRNY----74288
    select COUNT(*) from CUST_JRNY_VERSION----74477
    select COUNT(*) from CUST_GROUP----55819
    Thanks,
    HP..

    Plan hash value: 3771714931
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Pstart| Pstop |
    | 0 | SELECT STATEMENT | | 10239 | 2949K| | 7515 (1)| 00:01:31 | | |
    | 1 | SORT ORDER BY | | 10239 | 2949K| 3160K| 7515 (1)| 00:01:31 | | |
    |* 2 | HASH JOIN | | 10239 | 2949K| | 6864 (1)| 00:01:23 | | |
    | 3 | PARTITION HASH ALL | | 73687 | 1079K| | 417 (1)| 00:00:06 | 1 | 512 |
    |* 4 | TABLE ACCESS FULL | CUST_JRNY_VERSION | 73687 | 1079K| | 417 (1)| 00:00:06 | 1 | 512 |
    |* 5 | HASH JOIN | | 10239 | 2799K| | 6445 (1)| 00:01:18 | | |
    | 6 | PARTITION HASH ALL | | 73654 | 863K| | 178 (1)| 00:00:03 | 1 | 512 |
    | 7 | TABLE ACCESS FULL | CUST_JRNY | 73654 | 863K| | 178 (1)| 00:00:03 | 1 | 512 |
    |* 8 | FILTER | | | | | | | | |
    |* 9 | HASH JOIN RIGHT OUTER | | 10239 | 2679K| | 6267 (1)| 00:01:16 | | |
    | 10 | PARTITION HASH ALL | | 55315 | 756K| | 137 (1)| 00:00:02 | 1 | 512 |
    | 11 | TABLE ACCESS FULL | CUST_GROUP | 55315 | 756K| | 137 (1)| 00:00:02 | 1 | 512 |
    |* 12 | FILTER | | | | | | | | |
    |* 13 | HASH JOIN OUTER | | 10240 | 2540K| 2056K| 6129 (1)| 00:01:14 | | |
    |* 14 | FILTER | | | | | | | | |
    |* 15 | HASH JOIN RIGHT OUTER | | 10242 | 1930K| | 5531 (1)| 00:01:07 | | |
    | 16 | INDEX FAST FULL SCAN | CUST_REMARK_PK | 73677 | 935K| | 190 (0)| 00:00:03 | | |
    |* 17 | HASH JOIN | | 10257 | 1802K| | 5339 (1)| 00:01:05 | | |
    |* 18 | HASH JOIN | | 10257 | 701K| | 3516 (1)| 00:00:43 | | |
    |* 19 | HASH JOIN | | 3963 | 220K| | 2476 (1)| 00:00:30 | | |
    |* 20 | HASH JOIN | | 3963 | 181K| | 1300 (1)| 00:00:16 | | |
    | 21 | PARTITION HASH ALL | | 3963 | 131K| | 728 (1)| 00:00:09 | 1 | 512 |
    |* 22 | TABLE ACCESS FULL | FLIGHT_LEG | 3963 | 131K| | 728 (1)| 00:00:09 | 1 | 512 |
    |* 23 | INDEX FAST FULL SCAN| FLIGHT_SEG_FLIGHT_LEG_PK | 240K| 3059K| | 571 (1)| 00:00:07 | | |
    | 24 | PARTITION HASH ALL | | 259K| 2531K| | 1175 (1)| 00:00:15 | 1 | 512 |
    |* 25 | TABLE ACCESS FULL | FLIGHT_SEG | 259K| 2531K| | 1175 (1)| 00:00:15 | 1 | 512 |
    | 26 | PARTITION HASH ALL | | 631K| 8011K| | 1037 (1)| 00:00:13 | 1 | 512 |
    |* 27 | TABLE ACCESS FULL | CUST_FLIGHT_LEG | 631K| 8011K| | 1037 (1)| 00:00:13 | 1 | 512 |
    | 28 | PARTITION HASH ALL | | 239K| 25M| | 1822 (1)| 00:00:22 | 1 | 512 |
    |* 29 | TABLE ACCESS FULL | CUST | 239K| 25M| | 1822 (1)| 00:00:22 | 1 | 512 |
    | 30 | PARTITION HASH ALL | | 73623 | 4385K| | 243 (1)| 00:00:03 | 1 | 512 |
    | 31 | TABLE ACCESS FULL | REMARK | 73623 | 4385K| | 243 (1)| 00:00:03 | 1 | 512 |
    Predicate Information (identified by operation id):
    2 - access("CJ"."CUST_JRNY_ID"="CJV"."CUST_JRNY_ID")
    4 - filter("CJV"."VERSION_NUMBER"=0)
    5 - access("FL"."CUST_JRNY_ID"="CJ"."CUST_JRNY_ID")
    8 - filter(NVL("CG"."HISTORY_VERSION_NUMBER",0)=0)
    9 - access("CG"."CUST_JRNY_ID"(+)="CT"."CUST_JRNY_ID")
    12 - filter(NVL("RK"."HISTORY_VERSION_NUMBER",0)=0)
    13 - access("CTR"."REMARK_ID"="RK"."REMARK_ID"(+))
    14 - filter(NVL("CTR"."HISTORY_VERSION_NUMBER",0)=0)
    15 - access("CT"."CUST_ID"="CTR"."CUST_ID"(+))
    17 - access("CFL"."CUST_ID"="CT"."CUST_ID")
    18 - access("FL"."FLIGHT_LEG_ID"="CFL"."FLIGHT_LEG_ID")
    19 - access("FSFL"."FLIGHT_SEG_ID"="FS"."FLIGHT_SEG_ID")
    20 - access("FL"."FLIGHT_LEG_ID"="FSFL"."FLIGHT_LEG_ID")
    22 - filter("FL"."DEPARTURE_STATION_CODE"='DEL' AND "FL"."DEPARTURE_DATETIME"=TO_DATE(' 2012-12-10 18:45:00', 'syyyy-mm-dd
    hh24:mi:ss') AND "FL"."OPR_SERVICE_PROVIDER_CODE"='AI' AND "FL"."OPR_FLIGHT_NUMBER"=1 AND "FL"."OPR_FLIGHT_SUFFIX"='A' AND
    "FL"."HISTORY_VERSION_NUMBER"=0)
    23 - filter("FSFL"."HISTORY_VERSION_NUMBER"=0)
    25 - filter("FS"."HISTORY_VERSION_NUMBER"=0)
    27 - filter("CFL"."HISTORY_VERSION_NUMBER"=0)
    29 - filter("CT"."HISTORY_VERSION_NUMBER"=0)

  • Select Query Problem

    Hi Experts,
    I am having a select query in which I am using a variable in the where condition but it is giving error. Please suggest how to use variable in the select query.
    The query I am using is a s below.
    select * from zexc_rec into table it_ZEXC_REC
          where
           LIFNR in S_LIFNR and
          DOCNO in S_DOCNO and
          DOCTYP in doc_typ and
          DATE1 in S_DATE1 and
          MATNR in S_MATNR.
    Here doc_typ is a variable.
    Thanks.

    Rahul,
    use RANGES type variable instead of variable . It acts as a select-options variable. Thn use this variable in SELECT query with IN.
    Eg :
    RANGES r_t510 FOR t510-lgart.
        r_t510-low = '1600'. 
        APPEND r_t510.
        r_t510-low = '3190'. 
        APPEND r_t510.
    Note  : can be use SIGN, OPTIONS properties too in RANGES type.
    More deatils go through on HELP of RANGES
    Rgds,
    Ranjith

  • Oracle 11g :SELECT query blocked..??

    Hi Experts,
    could you please explain why the below SQL query is blocked?
    SELECT 1 FROM DUAL is blocking the SQL statement on GTTAPPUSR@gttccuatcriba04 ( SID=469 ) blocked SQL -> DELETE FROM GTTDB.PURCHASE_ENTRY_ID=:1
    SELECT 1 FROM DUAL is blocking the SQL statement on GTTAPPUSR@gttccuatcriba04 ( SID=367 ) blocked SQL -> DELETE FROM GTTDB.PURCHASE_ENTRY_ID=:1
    I am scratching my head without any solution when I had a look at the db today. Thanks in advance for your help.
    Regards,
    Boris
    Edited by: user12075620 on Dec 4, 2012 8:58 AM

    The SELECT statement is not blocking the UPDATE. As I said in the previous reply, the string that this query produces does not match the logic.
    This query is (at least on the surface) correctly identifying that session 1 is blocking session 2. Session 1 holds some lock that session 2 is waiting on. So far, so good. Since session 2 is waiting on the lock, we can easily enough see what session 2 is running (the UPDATE statement). But since session 1 is not blocked, it is potentially off running a ton of other SQL statements (or no SQL statement at all). The query is looking to see what session 1 is running currently. It has no way of determining what session 1 ran at some point in the past to acquire the lock in the first place.
    Going back to my KING example,
    At noon, session 1 runs
    UPDATE emp
       SET sal = sal * 2
    WHERE ename = 'KING'Session 1 now has a lock on the KING row in the EMP table. But session 1 neither commits nor rolls back, it is still in a transaction. Session 1 might not have any more activity for a long time-- the user might go off to lunch, for example (obviously, applications should not be designed to allow users to maintain open transactions indefinitely, but not all applications are designed correctly). Or it might start running other queries. Let's say that session 1 now runs a query that is going to go for an hour
    SELECT *
      FROM giant_view_with_lots_of_computationsNow, at 12:45, session 2 comes in and runs
    UPDATE emp
       SET bonus = 100
    WHERE ename = 'KING'Session 2 is blocked. Session 2 is running the UPDATE statement. Session 1 still holds the lock but it is running some completely unrelated SQL statement.
    If we run the query you posted, the query will correctly report that session 1 is running the query against the GIANT_VIEW_WITH_LOTS_OF_COMPUTATIONS but incorrectly imply that this SELECT query is the source of the lock. It is not. It simply happens to be the query that the session that does hold the lock happens to be executing at the current moment (why the application seems to be running a lot of queries that select a constant from dual is a separate question).
    Justin

  • Oracle SQL Select query takes long time than expected.

    Hi,
    I am facing a problem in SQL select query statement. There is a long time taken in select query from the Database.
    The query is as follows.
    select /*+rule */ f1.id,f1.fdn,p1.attr_name,p1.attr_value from fdnmappingtable f1,parametertable p1 where p1.id = f1.id and ((f1.object_type ='ne_sub_type.780' )) and ( (f1.id in(select id from fdnmappingtable where fdn like '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#%')))order by f1.id asc
    This query is taking more than 4 seconds to get the results in a system where the DB is running for more than 1 month.
    The same query is taking very few milliseconds (50-100ms) in a system where the DB is freshly installed and the data in the tables are same in both the systems.
    Kindly advice what is going wrong??
    Regards,
    Purushotham

    SQL> @/alcatel/omc1/data/query.sql
    2 ;
    9 rows selected.
    Execution Plan
    Plan hash value: 3745571015
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | SORT ORDER BY | |
    | 2 | NESTED LOOPS | |
    | 3 | NESTED LOOPS | |
    | 4 | TABLE ACCESS FULL | PARAMETERTABLE |
    |* 5 | TABLE ACCESS BY INDEX ROWID| FDNMAPPINGTABLE |
    |* 6 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    |* 7 | TABLE ACCESS BY INDEX ROWID | FDNMAPPINGTABLE |
    |* 8 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    Predicate Information (identified by operation id):
    5 - filter("F1"."OBJECT_TYPE"='ne_sub_type.780')
    6 - access("P1"."ID"="F1"."ID")
    7 - filter("FDN" LIKE '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#
    8 - access("F1"."ID"="ID")
    Note
    - rule based optimizer used (consider using cbo)
    Statistics
    0 recursive calls
    0 db block gets
    0 consistent gets
    0 physical reads
    0 redo size
    0 bytes sent via SQL*Net to client
    0 bytes received via SQL*Net from client
    0 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    9 rows processed
    SQL>

  • Select query differences between oracle 9 and oracle 8.

    Hi,
    I have a problem using the select query between oracle 7 and oracle 9i I don't have the same result :
    ex:
    With oracle7
    SQL> select 'champ1','champ2' from DUAL;
    'CHAMP 'CHAMP
    champ1 champ2
    With Oracle 9
    SQL> select 'champ1','champ2' from DUAL;
    'CHAMP1' 'CHAMP2'
    champ1 champ2
    So Can someone tell me how to solve this problem ? Is there a parameter in oracle 9 to set?
    Thanx.

    Whenever you are posting anything over internet forums like this - you should be very careful about not just posting the details which requires to solve the problem - also should be sensible about your question.
    This is not at all desired when you are posting such question. It may be because - you may not well aware of the fact.
    My suggestion is -> First Go through the basics Of SQL in general.
    Then go for any specific product like Oracle/ SQL Server/ Sybase etc.
    And, finally learn the advanced commands of that DB.
    You asked it - may be you thought the difference in output in terms of lines. But, that is not your actual output. That is the graphical display part only.
    Anyway,
    You can get the quite familier output by first type the following command ->
    set lin 310Regards.
    Satyaki De.

  • Select Query resulting in Scientific Notation

    Hello all,
    I am running a Select query through a batch file that extracts data from an Oracle database. Several of the fields that I am extracting from contain numbers that are up to 38 digits long. When I extract the data, it converts the numbers into scientific notation and it is important for me to have the entire field. Is there something I can change to my query that will pull the data in its entire form? This is what I'm running now:
    select * FROM ML.APPT where APPTDATE >= to_date('01/1/2010','mm/dd/yyyy'
    I apologize in advance if this has been answered already.
    Thanks!

    >
    When the extractor finishes, it returns the data into a flat file.
    don't quite understand the TO_CHAR function. Does this function mean I need to say something like this: select "TO_CHAR('column name', 99999999999999999999999999999999999999" FROM ML.APPT where APPTDATE >= to_date('01/1/2010','mm/dd/yyyy')
    >
    Yes- if the tool you use to extract the data (your 'extractor') is converting the numeric data to a string then it is responsible for creating the string in the proper format. If the number is an integer that can have as many digits as you have '9's in your sample format string then that is what you need to do.
    Here is how sql*plus (Oracle's tool) will display the data using default settings
    SQL> select 12345678901234567890123456789012345678 no_format,
      2  to_char(12345678901234567890123456789012345678, '99999999999999999999999999
    999999999999') with_format
      3   from dual;
    NO_FORMAT WITH_FORMAT
    1.2346E+37  12345678901234567890123456789012345678
    SQL>
    ----- TOAD will display something similiar but the default uses more decimal digits in the scientific notation data
    NO_FORMAT,WITH_FORMAT
    1.23456789012346E37, 12345678901234567890123456789012345678You can either format the numeric data in the query using TO_CHAR or the 'extractor' can do it when it converts the data to a string.

  • Select-options in SELECT query - syntax error

    Hi all,
      I get the error below when I try to use the select options in a SELECT query . Please help me.
    "The IN operator with "SO_AWART" is followed neither by an internal
    table nor by a value list."
    The code i have used(Logical database  PNP is used):
    TABLES: pernr,
            catsdb.
    INCLUDE ztime_cwtr_top.    " global Data
    INCLUDE ztime_cwtr_f01.
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
    SELECT-OPTIONS SO_AWART FOR CATSDB-AWART.
    PARAMETERS P_THRES TYPE I.
    SELECTION-SCREEN END OF BLOCK B1.
    Get data from CATSDB table. Workdates within the date interval are considered.
      SELECT pernr workdate awart catsquantity beguz enduz status
      FROM catsdb
      INTO TABLE it_catsdb
      WHERE pernr  = pernr-pernr    AND
           workdate GE pn-begda     AND
           workdate LE pn-endda     AND
           status   IN ('20', '30') AND
           awart    IN  so_awart .
          awart    IN ('1100', '1137', '1138', '1139', '1140',
                      '1147', '1148', '1149', '1157', '2003' ).
    when I give the values directly i do not get any syntax error, but when I use select options in the where condition I get the syntax error.
    I have tried different options like using only the select-options in the where condition.
    Thanks in advance.....
    Madhu

    Solved.
    Code with syntax error:
    include z...top .
    include z...fo1.
    select-options: xxxxxxx
    Code  with no syntax error:
    select-options: xxxxxxx
    include z...top .
    include z...fo1.
    Thanks for all your help,
    Madhu

  • Query in Select query operation

    Please excuse me for posting this again.
    I'm stuck up with this for 3 days. Lenghty post pls do read and help me.
    How is the select query going to be changed in the SAP so that the original database behind it understands it. I want to know the operation of IN operation in where clause where in we can use ranges.
    I'm asking this because I'm facing a problem using Native SQL.
    Query is like this:
    EXEC SQl.
    OPEN C1 for
    SELECT field1 from table@domain where field2 IN :ABAP_VAR.
    ENDEXEC.
    EXEC SQL.
    FETCH C1 NEXT INTO :VAR1 , :VAR2
    ENDEXEC.
    Oracle usually recognises this statement IN ( '2222' , '3658' , '6895' )
    But here this field that is build dynamically like this is not recognising them as seperate fileds but instead it is taking them as a single string and not selecting anything.
    But if a single value is passed it is fetching the data into the cursor. And the code is working fine.
    Any help in this is highly appreciable.

    "if a in r_range" is is effectively: does the value held in 'a' comply with the values held in range 'r_range'. Ranges can hold NE, patterns etc so this can get quite complex.
    You can see that it is very different from the SQL type IN.
    If your range hold several values you could unstrip it into a string varaible so that it ended up having a value something like: ( '2222' , '3658' , '6895' ). Not sure if you need the '(' but it would be something like this:
    eg,
    assuming your range is simple and only holds 'I' and 'EQ' values:
    data v_string type string.
    loop at r_range.
    concatenate v_string '@''' r_range-low  '''@' into v_string.
    endloop.
    REPLACE
      ALL OCCURRENCES OF '@'
      IN v_string
      WITH ' '.
    Then you can use:
    SELECT field1 from table@domain where field2 IN :v_string.

Maybe you are looking for

  • How to Compress non-image object in Acrobat 9 Pro/Acrobat X Pro

    Hi, I am newbie and don't know where to post this question exactly. Forgive me if I am incorrect. How can we compress "non-image object" in "Acrobat 9 Pro/Acrobat X Pro" Thanks in advance for your suggestion & help. Thanks & Regards, Raja. S

  • To make a call to a fixed number from a j2me application

    hi all, i am working on a mobile application. i want to have an option for the user to make a call to a fixed number by pressing the call button from within the application. as far i understand we can use canvas to detect a key press and the platform

  • My screen is completely dimmed out. I can barely see my screen now. Please fix this

    I was working on my assingments, and after some time my screens brightness has gone very low. I just cannot see my desktop, but my laptop is working just fine. Please fix this display issue. So, now I work on my laptop by connecting a HDMI cable from

  • Utl_encode.text_encode - QUOTED_PRINTABLE

    Hi. I´m using utl_encode.text_encode to format e-mails that I need to send in my program. QUOTED_PRINTABLE := 2; wresult := utl_encode.text_encode(nvl(wline, ' '), 'WE8ISO8859P1', QUOTED_PRINTABLE);The problem is that when last char of the line is a

  • Search crashes

    OracleJSP: oracle.jsp.provider.JspCompileException: Errors compiling:/u01/app/oracle/product/IAS904/j2ee/OC4J_Portal/application-deployments/wwwotn/wwwotn/persistence/_pages//_searchotnerr.java Line # Error 219 [jsp src:line #:498] cannot resolve sym