Tuning when bind variables is used

I have the following query.. which has some bind variables..
When i run in TOAD by hardsocing these bind variables, the query comes out in 2-3 mins.
But when i run after replacing bind variables during run time , the query hangs.
These bind variables are indispensible as the the query run dynamically thru the java program.
Below is the query and explain plan..
Please help
select
acct_key, data_serial_nr,upline,genlgy,rmovl_cmpgn,rmovl_rsn_desc_txt,collection_status,
acct_full_nm,acct_nr,ordnry_loa_nr,rep_loa_nr,cumltv_actv_loa_nr,addr_line_1_txt,suburb_desc_txt,city_desc_txt,
pstl_cd,hm_phon_nr,bus_phon_nr,mobile_phon_nr,email_addr_txt,currnt_bal_amt,rnstmt_cmpgn,last_active_cmpgn,avg_discnt_base
from
select
acct_key, data_serial_nr,nvl(pmc.new_value,upline) upline,upline1,genlgy,rmovl_cmpgn,rmovl_rsn_desc_txt,collection_status,
acct_full_nm,acct_nr,ordnry_loa_nr,rep_loa_nr,cumltv_actv_loa_nr,addr_line_1_txt,suburb_desc_txt,city_desc_txt,
pstl_cd,hm_phon_nr,bus_phon_nr,mobile_phon_nr,email_addr_txt,currnt_bal_amt,rnstmt_cmpgn,last_active_cmpgn,avg_discnt_base
from(select /*+ use_hash (smas, da) use_hash (dad, smas) */ dmz.mrkt_id,
dlg.root_upln_acct_key acct_key,
'0004' data_serial_nr,
case when smas.ldrshp_prgrm_ind = 'Y' and smas.ldrshp_rltnshp_key in (1,3) then to_nchar(da.acct_nr)
when smas.ldrshp_prgrm_ind = 'N' and smas.ldrshp_rltnshp_key not in (1,3) and nvl(smas.upln_acct_nr,-100) = -100 then to_nchar('ZM')
when smas.ldrshp_prgrm_ind = 'Y' and smas.ldrshp_rltnshp_key in (2) then to_nchar(smas.upln_acct_nr) else to_nchar('ZM') end upline ,
case when smas.ldrshp_prgrm_ind = 'Y' and smas.ldrshp_rltnshp_key in (1,3) then da.acct_nr
when smas.ldrshp_prgrm_ind = 'N' and smas.ldrshp_rltnshp_key not in (1,3) and nvl(smas.upln_acct_nr,-100) = -100 then 'ZM'
when smas.ldrshp_prgrm_ind = 'Y' and smas.ldrshp_rltnshp_key in (2) then smas.upln_acct_nr else 'ZM' end upline1 ,
case when smas.ldrshp_prgrm_ind = 'Y' and smas.ldrshp_rltnshp_key in (1,3) then
case when dmz_appt.zone_cd='--' then null else dmz_appt.zone_cd end||smas.genlgy_detl_txt
when smas.ldrshp_prgrm_ind = 'N' and smas.ldrshp_rltnshp_key not in (1,3) and nvl(smas.upln_acct_nr,-100) = -100 then
case when dmz_appt.zone_cd='--' then null else dmz_appt.zone_cd end
when smas.ldrshp_prgrm_ind = 'Y' and smas.ldrshp_rltnshp_key in (2) then
case when dmz_appt.zone_cd='--' then null else dmz_appt.zone_cd end||substr(smas.GENLGY_DETL_TXT,1,instr(smas.GENLGY_DETL_TXT,'/',-1)-1)
else case when dmz_appt.zone_cd='--' then null else dmz_appt.zone_cd end end genlgy,
substr(da.rmovl_cmpgn_perd_id,1,4)||'-'||substr(da.rmovl_cmpgn_perd_id,7,2) rmovl_cmpgn,
(dmrr.rmovl_rsn_natv_lang_desc_txt) rmovl_rsn_desc_txt,
dmrr.RMOVL_RSN_CD,
(case when dmcs.colctn_stus_cd = 'B' then :b1
when dmcs.colctn_stus_cd = 'C' then :b2
when dmcs.colctn_stus_cd = 'N' then null end) collection_status,
'"'||initcap(trim(da.acct_last_nm||' '||
case when da.acct_mddl_nm is not null then da.acct_mddl_nm||' '||da.acct_frst_nm
else da.acct_frst_nm end))||'"' acct_full_nm,
da.acct_nr,
smas.ordnry_loa_nr,
smas.rep_loa_nr,
smas.cumltv_actv_loa_nr,
'"'||INITCAP(TO_NCHAR (dad.addr_line_1_txt))||'"' addr_line_1_txt,
'"'||INITCAP(TO_NCHAR (dad.suburb_desc_txt))||'"' suburb_desc_txt,
'"'||INITCAP (TO_NCHAR (dad.city_desc_txt))||'"' city_desc_txt,
'"'||dad.pstl_cd||'"' pstl_cd,
'"'||da.hm_phon_nr||'"' hm_phon_nr,
'"'||da.bus_phon_nr||'"' bus_phon_nr,
'"'||da.mobile_phon_nr||'"' mobile_phon_nr,
'"'||lower(da.email_addr_txt)||'"' email_addr_txt,
smas.currnt_bal_amt,
decode(substr(da.rnstmt_cmpgn_perd_id,1,4)||'-'||substr(da.rnstmt_cmpgn_perd_id,7,2),'-',null,substr(smas.rnstmt_cmpgn_perd_id,1,4)||'-'||substr(smas.rnstmt_cmpgn_perd_id,7,2)) rnstmt_cmpgn,
decode(substr(smas.last_actv_cmpgn_perd_id,1,4)||'-'||substr(smas.last_actv_cmpgn_perd_id,7,2),'-',null,substr(smas.last_actv_cmpgn_perd_id,1,4)||'-'||substr(smas.last_actv_cmpgn_perd_id,7,2)) last_active_cmpgn,
round(smas.AVG_DISCNT_BASE_AMT,2) avg_discnt_base
FROM codi.dim_acct da
join codi.dim_mrkt_zone dmz
on (da.mrkt_id = dmz.mrkt_id and da.dlvry_zone_sls_org_key = dmz.zone_key)
join codi.dim_mrkt_acct_stus dmas
on (dmas.mrkt_id = da.mrkt_id and dmas.acct_stus_key = da.acct_stus_key)
join cdw.sum_mrkt_acct_sls smas
on (da.mrkt_id = smas.mrkt_id and da.acct_key = smas.acct_key and smas.fld_sls_cmpgn_perd_id = :b3)
left join (SELECT dad1.*
FROM codi.dim_addr dad1 JOIN codi.dim_mrkt_addr_typ dmat
ON ( dad1.mrkt_id = 63
AND dad1.mrkt_id = dmat.mrkt_id
AND dad1.addr_typ_id = dmat.addr_typ_id
AND NVL (dmat.glbl_addr_typ_id, 1) = 1
) dad
on (da.mrkt_id = dad.mrkt_id and da.acct_key = dad.acct_key)
left join codi.dim_mrkt_rmovl_rsn dmrr
on (smas.mrkt_id = dmrr.mrkt_id and smas.rmovl_rsn_id = dmrr.rmovl_rsn_id and dmrr.rmovl_rsn_id <> -100)
left join codi.dim_colctn_stus dmcs
on ( smas.colctn_stus_key = dmcs.colctn_stus_key)
left join codi.dim_mrkt_zone dmz_appt
on (smas.mrkt_id = dmz_appt.mrkt_id and smas.appt_sls_org_key = dmz_appt.zone_key)
join codi.dim_ldrshp_genlgy dlg
on (smas.mrkt_id = dlg.mrkt_id and smas.acct_key = dlg.dwnln_acct_key and smas.fld_sls_cmpgn_perd_id = dlg.fld_sls_cmpgn_perd_id)
Where da.mrkt_id = :b4
and da.rmovl_cmpgn_perd_id between :b5 and :b6
and nvl(da.appt_cmpgn_perd_id,19000301) < da.rmovl_cmpgn_perd_id
and da.rmovl_cmpgn_perd_id > nvl(da.rnstmt_cmpgn_perd_id,19000301)
and dmas.acct_stus_id = 2
and ( (mrkt_id = 63 and dmas.ACCT_STUS_CD in ('C','D') ) or (dmas.mrkt_id <> 63))
and dlg.root_upln_acct_key <> -100
and dmz.zone_key <>-100) a
LEFT JOIN hz_metadata.pr_market_control pmc
ON ( a.mrkt_id = pmc.mrkt_id
AND a.upline =pmc.column_nm and
pmc.table_nm ='FID 7'
and pmc.report_level='ALL'
and pmc.rpt_lang_cd = :b7
) where '2' = case when a.mrkt_id =66 then a.RMOVL_RSN_CD else '2' end
) ORDER BY acct_key,decode(upline1,'ZM',1,upline1) ,genlgy
Plan
SELECT STATEMENT ALL_ROWS Cost: 42,324
     50 PX COORDINATOR
          49 PX SEND QC (ORDER) SYS.:TQ10004 Cost: 42,324 Bytes: 3,809 Cardinality: 1
               48 SORT ORDER BY Cost: 42,324 Bytes: 3,809 Cardinality: 1
                    47 PX RECEIVE Cost: 42,323 Bytes: 3,809 Cardinality: 1
                         46 PX SEND RANGE SYS.:TQ10003 Cost: 42,323 Bytes: 3,809 Cardinality: 1
                              45 NESTED LOOPS OUTER Cost: 42,323 Bytes: 3,809 Cardinality: 1
                                   42 VIEW Cost: 42,323 Bytes: 3,733 Cardinality: 1
                                        41 FILTER
                                             40 NESTED LOOPS OUTER Cost: 42,323 Bytes: 1,437 Cardinality: 1
                                                  37 HASH JOIN OUTER Cost: 42,322 Bytes: 1,421 Cardinality: 1
                                                       25 PX RECEIVE Cost: 20,878 Bytes: 767 Cardinality: 1
                                                            24 PX SEND HASH SYS.:TQ10002 Cost: 20,878 Bytes: 767 Cardinality: 1
                                                                 23 NESTED LOOPS Cost: 20,878 Bytes: 767 Cardinality: 1
                                                                      19 NESTED LOOPS Cost: 20,878 Bytes: 736 Cardinality: 1
                                                                           17 NESTED LOOPS OUTER Cost: 20,878 Bytes: 727 Cardinality: 1
                                                                                14 NESTED LOOPS OUTER Cost: 20,877 Bytes: 688 Cardinality: 1
                                                                                     11 NESTED LOOPS Cost: 20,877 Bytes: 681 Cardinality: 1
                                                                                          8 HASH JOIN Cost: 20,877 Bytes: 656 Cardinality: 1
                                                                                               5 BUFFER SORT
                                                                                                    4 PX RECEIVE Cost: 12,703 Bytes: 282 Cardinality: 1
                                                                                                         3 PX SEND BROADCAST SYS.:TQ10000 Cost: 12,703 Bytes: 282 Cardinality: 1
                                                                                                              2 PARTITION LIST SINGLE Cost: 12,703 Bytes: 282 Cardinality: 1 Partition #: 22
                                                                                                                   1 TABLE ACCESS FULL TABLE CODI.DIM_ACCT Cost: 12,703 Bytes: 282 Cardinality: 1 Partition #: 22
                                                                                               7 PX BLOCK ITERATOR Cost: 8,173 Bytes: 24,524,302 Cardinality: 65,573 Partition #: 24
                                                                                                    6 TABLE ACCESS FULL TABLE CDW.SUM_MRKT_ACCT_SLS Cost: 8,173 Bytes: 24,524,302 Cardinality: 65,573 Partition #: 24
                                                                                          10 TABLE ACCESS BY INDEX ROWID TABLE CODI.DIM_MRKT_ACCT_STUS Cost: 0 Bytes: 25 Cardinality: 1
                                                                                               9 INDEX UNIQUE SCAN INDEX (UNIQUE) CODI.PK_DIM_REP_STUS Cost: 0 Cardinality: 1
                                                                                     13 TABLE ACCESS BY INDEX ROWID TABLE CODI.DIM_COLCTN_STUS Cost: 0 Bytes: 7 Cardinality: 1
                                                                                          12 INDEX UNIQUE SCAN INDEX (UNIQUE) CODI.PK_DIM_COLCTN_STUS Cost: 0 Cardinality: 1
                                                                                16 TABLE ACCESS BY INDEX ROWID TABLE CODI.DIM_MRKT_RMOVL_RSN Cost: 0 Bytes: 39 Cardinality: 1
                                                                                     15 INDEX UNIQUE SCAN INDEX (UNIQUE) CODI.PK_DIM_MRKT_RMOVL_RSN Cost: 0 Cardinality: 1
                                                                           18 INDEX UNIQUE SCAN INDEX (UNIQUE) CODI.PK_DIM_MRKT_ZONE Cost: 0 Bytes: 9 Cardinality: 1
                                                                      22 PARTITION RANGE SINGLE Cost: 0 Bytes: 31 Cardinality: 1 Partition #: 33
                                                                           21 PARTITION LIST SINGLE Cost: 0 Bytes: 31 Cardinality: 1 Partition #: 34
                                                                                20 INDEX RANGE SCAN INDEX (UNIQUE) CODI.PK_DIM_LDRSHP_GENLGY Cost: 0 Bytes: 31 Cardinality: 1 Partition #: 34
                                                       36 BUFFER SORT
                                                            35 PX RECEIVE Cost: 21,442 Bytes: 249,603,678 Cardinality: 381,657
                                                                 34 PX SEND HASH SYS.:TQ10001 Cost: 21,442 Bytes: 249,603,678 Cardinality: 381,657
                                                                      33 VIEW Cost: 21,442 Bytes: 249,603,678 Cardinality: 381,657
                                                                           32 FILTER
                                                                                31 MERGE JOIN Cost: 21,442 Bytes: 35,112,444 Cardinality: 381,657
                                                                                     27 TABLE ACCESS BY INDEX ROWID TABLE CODI.DIM_ADDR Cost: 21,438 Bytes: 65,721,278 Cardinality: 801,479
                                                                                          26 INDEX RANGE SCAN INDEX CODI.FK_DIMMRKTADDRTYP_DIMADDR Cost: 999 Cardinality: 801,479
                                                                                     30 SORT JOIN Cost: 4 Bytes: 70 Cardinality: 7
                                                                                          29 TABLE ACCESS BY INDEX ROWID TABLE CODI.DIM_MRKT_ADDR_TYP Cost: 3 Bytes: 70 Cardinality: 7
                                                                                               28 INDEX RANGE SCAN INDEX CODI.FK_DIMMRKT_DIMMRKTADDRTYP Cost: 1 Cardinality: 8
                                                  39 TABLE ACCESS BY INDEX ROWID TABLE CODI.DIM_MRKT_ZONE Cost: 0 Bytes: 16 Cardinality: 1
                                                       38 INDEX UNIQUE SCAN INDEX (UNIQUE) CODI.PK_DIM_MRKT_ZONE Cost: 0 Cardinality: 1
                                   44 TABLE ACCESS BY INDEX ROWID TABLE HZ_METADATA.PR_MARKET_CONTROL Cost: 0 Bytes: 76 Cardinality: 1
                                        43 INDEX RANGE SCAN INDEX (UNIQUE) HZ_METADATA.PK_PR_MARKET_CONTROL Cost: 0 Cardinality: 1

I suggest you read this, otherwise you won't get much help...
HOW TO: Post a SQL statement tuning request - template posting

Similar Messages

  • Formula node forbid to run VI when undefined variable is used

    On all LabVIEW version, we can use Formula node to evaluate mathematical formulas.
    We can define input and output variable freely and calculate using some variety of formula.
    But when we use undefined variable as output, can execute VIs with no errors.
    We think it is a problem because when programmer makes a typo, they cannot notice the mistake.
    When undefined variable is used as output variable, LabVIEW should forbid to run VI.

    I think you are going to get the same (or similar) answers than to my suggestion(s) to make VI outputs potentially "required" and the same for some functions (built-in VIs):
    http://forums.ni.com/t5/LabVIEW-Idea-Exchange/Allow-required-outputs-in-VIs/idc-p/3157058
    http://forums.ni.com/t5/LabVIEW-Idea-Exchange/quot-Function-terminal-not-connected-quot-detection-plus/idi-p/1858573
    In general, I agree with you, there is a potential for problems. Not really for the reason you are mentioning, because a typo will break the VI (unless you have two output variables with very similar names - unlike in your example - such as y and y0). But it could make for some frustrating debugging session.

  • Can bind variable be used for the table in an explicit cursor

    I have an application that accesses a table on several different servers. I created a ref cursor variable for the cursor and a varchar2 variable to define my query. variable i_server is an parameter of my procedure. Is it possible to rewrite the v_query using bind variables for the table/server? I have include v_query below.
    v_query := 'SELECT rp.usr_id, rp.sun_sft_cat, rp.sun_start, rp.sun_hrs,' ||
    ' rp.mon_sft_cat, rp.mon_start, rp.mon_hrs,' ||
    ' rp.tue_sft_cat, rp.tue_start, rp.tue_hrs,' ||
    ' rp.wed_sft_cat, rp.wed_start, rp.wed_hrs,' ||
    ' rp.thu_sft_cat, rp.thu_start, rp.thu_hrs,' ||
    ' rp.fri_sft_cat, rp.fri_start, rp.fri_hrs,' ||
    ' rp.sat_sft_cat, rp.sat_start, rp.sat_hrs,' ||
    ' rp.sun_sft, rp.mon_sft, rp.tue_sft, rp.wed_sft,' ||
    ' rp.thu_sft, rp.fri_sft, rp.sat_sft, nvl(ei.wip_permanent_sched_seq, 0)' ||
    ' FROM ' || i_server || ' rp, wip_emp_information ei,' ||
    ' wip_emp_status wes, wip_emp_status_type west ' ||
    ' WHERE rp.usr_id = ei.employee_id' ||
    ' AND wes.employee_id = ei.employee_id' ||
    ' AND wes.status_type = west.status_type' ||
    ' AND west.description = ''WAREHOUSE EMPLOYEE''' ||
    ' AND wes.effective_date = (SELECT MAX(wes2.effective_date)' ||
    ' FROM wip_emp_status wes2' ||
    ' WHERE wes2.status_type = wes.status_type' ||
    ' AND wes2.employee_id = wes.employee_id' ||
    ' AND wes2.effective_date <= trunc(SYSDATE))' ||
    ' AND wes.status = ''Y'' AND rp.wk = 1'; -- wk = 1 is next week's schedule
    OPEN rp_sched_cursor FOR v_query;

    If your intention is to do this:
    v_query := 'SELECT rp.usr_id, rp.sun_sft_cat, rp.sun_start, rp.sun_hrs,' ||
    ' rp.mon_sft_cat, rp.mon_start, rp.mon_hrs,' ||
    ' rp.tue_sft_cat, rp.tue_start, rp.tue_hrs,' ||
    ' rp.wed_sft_cat, rp.wed_start, rp.wed_hrs,' ||
    ' rp.thu_sft_cat, rp.thu_start, rp.thu_hrs,' ||
    ' rp.fri_sft_cat, rp.fri_start, rp.fri_hrs,' ||
    ' rp.sat_sft_cat, rp.sat_start, rp.sat_hrs,' ||
    ' rp.sun_sft, rp.mon_sft, rp.tue_sft, rp.wed_sft,' ||
    ' rp.thu_sft, rp.fri_sft, rp.sat_sft, nvl(ei.wip_permanent_sched_seq, 0)' ||
    ' FROM ' || :b0 || ' rp, wip_emp_information ei,' ||      --- Note the bindvariable...
    ' wip_emp_status wes, wip_emp_status_type west ' ||
    ' WHERE rp.usr_id = ei.employee_id' ||
    ' AND wes.employee_id = ei.employee_id' ||
    ' AND wes.status_type = west.status_type' ||
    ' AND west.description = ''WAREHOUSE EMPLOYEE''' ||
    ' AND wes.effective_date = (SELECT MAX(wes2.effective_date)' ||
    ' FROM wip_emp_status wes2' ||
    ' WHERE wes2.status_type = wes.status_type' ||
    ' AND wes2.employee_id = wes.employee_id' ||
    ' AND wes2.effective_date <= trunc(SYSDATE))' ||
    ' AND wes.status = ''Y'' AND rp.wk = 1'; -- wk = 1 is next week's schedule
    OPEN rp_sched_cursor FOR v_query USING i_server;Then the answer is: no, you cannot do that.
    But my question then would be: why would you want to do that?
    I assume you don't have that many "different servers". One cursor per server won't hurt you.

  • How to have the BIND variables value using the TKPROF utility.

    WE have a JAVA application and Oracle 9i database.We need to figure out what all select/update/insert sql staements are firing if i am doing one complete processing in my JAVA front application.
    Initally I have planned for using TKPROF utility after makeing AUTO_TRCE=TRUE in the database.But the problem is that all select/insert/update sql statements are using the BIND variables in the JAVA code and same is coming/printing on the trace file also.
    can we print out the BIND variables values also,while making the TRACE ON?
    eg: trace is generaitng the all insert statements like below.
    insert into TEST(Column1,Column2) values(:1,:2);
    I want to know the value of :1 and :2 bind variables.
    If you have any cluse about it please let me know.
    Mitesh Shah

    Thanks Guys,
    I got the BIND variable values in the TRACE file.Previously i was searching on the OUtputfile.
    I am pasting the same trce file format.Can you please verify it.Is i am looking the correct file and corect location.
    PARSING IN CURSOR #2 len=1571 dep=0 uid=66 oct=3 lid=66 tim=18446744071740803342 hv=1462188955 ad='123434f0'
    SELECT PARENTIDKEY,CONTRACTKEY,COMPANYKEY,BACKENDKEY,DATAREP,BANKHOLDINGID,BANKID,CARRIERPARTYID,PRODUCTID,ID,PREMIUMINDEXRATE,ILLUSTRATEDMATURITYLOW,ILLUSTRATEDMATURITYHIGH,SPECIALHANDLING,CARRIERCOMMCODE,MONEYTRANSFERTYPE,FIRSTBILLSKIPMONTH,CONTESTABILITYENDDATE,DEDUCTIONDATE,MARKETVALADJUSTIND,FREEAVAILABLEAMT,ADVANCINGREJECTEDIND,RATEDIND,OTHERINSUREDIND,ENDORSEMENTIND,BENEFICIARYIND,CASECONTROLNUMBERASSUMING,OWNERLEGALNAME,STAMPDUTY,COMMISSIONANNUALIZEDIND,NONSTDCOMMTAKEN,LAPSETAXABLEGAIN,GOVTALLOTMENTSUSPENSEACCTAMT,LASTNOGOODCHECKREASON,LASTNOGOODCHECKDATE,LASTCOIDATE,LASTDEDUCTEDEXPENSECHARGES,LASTDEDUCTEDCOICHARGES,STATEMENTBASIS,LASTNOTICETYPE,LASTNOTICEDATE,PAYMENTDUEDATE,LASTBANKCHANGEDATE,EFTENDDATE,BANKBRANCHNAME,BANKNAME,PAYMENTDRAFTDAY,BANKACCTTYPE,CREDITCARDTYPE,CREDITCARDEXPDATE,ACCTHOLDERNAME,ROUTINGNUMBER,ACCOUNTNUMBER,PAYMENTMETHOD,ANNUALPAYMENTAMT,PAYMENTAMT,PAYMENTMODE,LASTCOIANNIVDATE,BILLINGSTOPDATE,BILLEDTODATE,FINALPAYMENTDATE,GRACEPERIODENDDATE,PAIDTODATE,STATUSCHANGEDATE,REINSTATEMENTDATE,TERMDATE,ISSUEDATE,EFFDATE,DOWNLOADDATE,DURATION,POLFEE,POLICYVALUE,COMMISSIONROLLOVERPCT,COMMISSIONOPTIONSELECTED,REPLACEMENTTYPE,CUSIPNUM,CONVERTTOPRIVATEIND,PORTABILITYIND,REINSURANCEIND,BILLNUMBER,JURISDICTION,ISSUETYPE,ISSUENATION,STATUSREASON,PRIORPOLICYSTATUS,POLICYSTATUS,SHORTNAME,ADMINISTERINGCARRIERCODE,PLANNAME,FILEDFORMNUMBER,FORMNO,CARRIERCODE,PRODUCTCODE,PRODUCTTYPE,LINEOFBUSINESS,CERTIFICATENO,POLNUMBER,CARRIERADMINSYSTEM FROM "POLICY" WHERE PARENTIDKEY = :1 AND CONTRACTKEY = :2 AND COMPANYKEY = :3 AND BACKENDKEY = :4
    END OF STMT
    PARSE #2:c=0,e=1298,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=0,tim=18446744071740803336
    BINDS #2:
    bind 0: dty=1 mxl=4000(4000) mal=00 scl=00 pre=00 oacflg=01 oacfl2=0 size=4000 offset=0
    bfp=082a5a9c bln=4000 avl=09 flg=05
    value="Holding_1"
    bind 1: dty=1 mxl=4000(4000) mal=00 scl=00 pre=00 oacflg=01 oacfl2=0 size=4000 offset=0
    bfp=082a4af0 bln=4000 avl=10 flg=05
    value="DUL001138U"
    bind 2: dty=1 mxl=4000(4000) mal=00 scl=00 pre=00 oacflg=01 oacfl2=0 size=4000 offset=0
    bfp=069bb890 bln=4000 avl=02 flg=05
    value="00"
    bind 3: dty=1 mxl=4000(4000) mal=00 scl=00 pre=00 oacflg=01 oacfl2=0 size=4000 offset=0
    bfp=069ba8e4 bln=4000 avl=04 flg=05
    value="CLIF"
    **********************************************************************************

  • High number of execution while using bind variables

    Hi,
    The below query is going for 79000 executions when bind variables are used.
    Select COUNT ( InID) From InD   PPR BO95_PPR where  IND.PPR = PPR. PPRName AND   ( ( ( ( ( (  AGD = :1 ) AND (  AGUD is null ) ) AND (  MW is null ) ) AND ( ( (  Status = :2 ) OR (  Status = :3 ) ) ) ) AND  BD = :4 ) )
    Bind variable values are as follows
    :1 = 10
    :2 = Down
    :3 = Run
    :4 = 10
    | Id  | Operation                     | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT              |                      |     1 |    54 |    74   (3)| 00:00:01 |
    |   1 |  SORT AGGREGATE               |                      |     1 |    54 |            |          |
    |   2 |   NESTED LOOPS                |                      | 79543 |  4194K|    74   (3)| 00:00:01 |
    |   3 |    TABLE ACCESS BY INDEX ROWID| PPR     |     1 |    15 |     1   (0)| 00:00:01 |
    |*  4 |     INDEX RANGE SCAN          | IDX_PPR_BD     |     1 |       |     1   (0)| 00:00:01 |
    |   5 |    INLIST ITERATOR            |                      |       |       |            |          |
    |*  6 |     INDEX RANGE SCAN          | IDX_InD_ASABMP | 79543 |  3029K|    73   (3)| 00:00:01 |
    ------------------------------------------------------------------------------------------------------When I replace the bind variables with hard coded values, the row returned is 29000 only.
    Why is it different?
    Thanks

    Huh?
    How are you comparing 79000 executions with 29000 rows?
    Your question:
    a). Doesn't make sense
    b). Lacks information (version of Oracle, doesn't show how you determine 79,000 executions and 29,000 rows)
    c). Lacks information about how the query is being submitted/executed - the client determines how many times it's executed, and bind variables wouldn't impact this.
    John

  • Possible for Oracle to consider constraints when using bind variable?

    Consider the following table with a check constraint listing the possible values of the column
    create table TEST_TABLE(
    my_column varchar2(10));
    insert into TEST_TABLE select 'VALUE1' from dba_objects;
    alter table TEST_TABLE
    add constraint TEST_TABLE_CHK1
    check (my_column in ('VALUE1', 'VALUE2'));
    begin dbms_stats.gather_table_stats(ownname=>user,tabname=>'TEST_TABLE');END;Let's see the number of logical I/O's needed for the following SQL statements.
    (The value was obtained by the delta ofselect m.value from v$mystat m, v$statname n
    where name='session logical reads' and m.statistic#=n.statistic#)
    If string lateral is used:
    declare
       n number;
    begin
      select count(*) into n from test_table where my_column='VALUE1';
    end;
    Consistent Gets: 21
    declare
       n number;
    begin
      select count(*) into n from test_table where my_column='VALUE2';
    end;
    Consistent Gets: 21
    declare
       n number;
    begin
      select count(*) into n from test_table where my_column='VALUE3';
    end;
    Consistent Gets: 0Oracle can eliminate the table if it knows the queried value can't satisfy the constraint. Good.
    (Actually, the execution plan for the last query included the 'FILTER' operation.)
    However, if bind variable is used:
    declare
       n number;
       x varchar2(10);
    begin
      x := 'VALUE1';
      select count(*) into n from test_table where my_column=x;
    end;
    Consistent Gets: 21
    declare
       n number;
       x varchar2(10);
    begin
      x := 'VALUE3';
      select count(*) into n from test_table where my_column=x;
    end;
    Consistent Gets: 21Oracle can't eliminate the table using the constraint. I can understand that because bind variables are used, Oracle can't directly eliminate the table when generating the execution plan. However, is it possible to eliminate the table, or at least employ some shortcut in runtime? If not, will this be a performance loss compared with using values laterals when check constraint exists?
    (And is it possible to use autotrace on PL/SQL block in sqlplus?)
    Oracle:
         10.2.0.4 SE
         11.2.0.2 SE
    OS:
         RHEL5

    However, is it possible to eliminate the table, or at least employ some shortcut in runtime? I can't see how to do this. Oracle has a sqltext that has an embedded bind variable in it. And for this sqltext it has an execution plan in the shared pool that will be used irrespective of the actual bound values at runtime.
    Maybe in 11G, with adaptive cursor sharing / plan bind awareness, Oracle might be smart enough to introduce a second execution plan for the VALUE3 case.
    If not, will this be a performance loss compared with using values laterals when check constraint exists?Only if you submit the dumb query and search for records with VALUE3... Normally your application code would not hold/generate these queries.
    Will it?
    For columns whose values are bound by a CHECK constraint, one might even consider to never use bind variables, since very likely you will have few versions of queries that use these columns.
    Not?
    Edited by: Toon Koppelaars on Jun 22, 2011 1:20 PM

  • Using bind variables (in & out) with dynamic sql

    I got a table that holds pl/sql code snippets to do validations on a set of data. what the code basically does is receiving a ID and returning a number of errors found.
    To execute the code I use dynamic sql with two bind variables.
    When the codes consists of a simpel query, it works like a charm, for example with this code:
    BEGIN
       SELECT COUNT (1)
       INTO :1
       FROM articles atl
       WHERE ATL.CSE_ID = :2 AND cgp_id IS NULL;
    END;however when I get to some more complex validations that need to do calculations or execute multiple queries, I'm running into trouble.
    I've boiled the problem down into this:
    DECLARE
       counter   NUMBER;
       my_id     NUMBER := 61;
    BEGIN
       EXECUTE IMMEDIATE ('
          declare
             some_var number;
          begin
          select 1 into some_var from dual
          where :2 = 61;
          :1 := :2;
          end;
          USING OUT counter, IN my_id;
       DBMS_OUTPUT.put_line (counter || '-' || my_id);
    END;this code doesn't really make any sense, but it's just to show you what the problem is. When I execute this code, I get the error
    ORA-6537 OUT bind variable bound to an IN position
    The error doesn't seem to make sense, :2 is the only IN bind variable, and it's only used in a where clause.
    As soon as I remove that where clause , the code will work again (giving me 61-61, in case you liked to know).
    Any idea whats going wrong? Am I just using the bind variables in a way you're not supposed to use them?
    I'm using Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit

    Correction. With execute immediate binding is by position, but binds do not need to be repeated. So my statement above is incorrect..
    You need to bind it once only - but bind by position. And the bind must match how the bind variable is used.
    If the bind variable never assigns a value in the code, bind as IN.
    If the bind variable assigns a value in the code, bind as OUT.
    If the bind variable assigns a value and is used a variable in any other statement in the code, bind as IN OUT.
    E.g.
    SQL> create or replace procedure FooProc is
      2          cnt     number;
      3          id      number := 61;
      4  begin
      5          execute immediate
      6  'declare
      7          n       number;
      8  begin
      9          select
    10                  1 into n
    11          from dual
    12          where :var1 = 61;       --// var1 is used as IN
    13 
    14          :var2 := n * :var1;     --// var2 is used as OUT and var1 as IN
    15          :var2 := -1 * :var2;    --// var2 is used as OUT and IN
    16  end;
    17  '
    18          using
    19                  in out id, in out cnt;  --// must reflect usage above
    20 
    21          DBMS_OUTPUT.put_line ( 'cnt='||cnt || ' id=' || id);
    22  end;
    23  /
    Procedure created.
    SQL>
    SQL> exec FooProc
    cnt=-61 id=61
    PL/SQL procedure successfully completed.
    SQL>

  • How to use sql "IN" operator with named bind variable in where clause ?

    Can one bind variable be used for the "IN" list ('1','2','3') ?

    rob,
    No worries. Glad it helped. Glad to see also that you're doing things right and trying to use bind variables ;)
    May I suggest adding "SOLVED" to the title of the original post?
    Best,
    John

  • How to use bind variables using in  clause in SQL

    Hi
    Can any one help me in regards Bind variables usage using in clause in sql for String data?
    thans

    Are you looking for a dynamic IN list? As in something like this:
    SELECT ... FROM .. WHERE some_col IN (<dynamic list of stuff that is always changing>)If so check this out:
    [ How can I do a variable IN list?|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425]

  • Re-using bind variables in Pro*C

    Using dynamic SQL method 4. Application originally written back in, oh 1999-ish, using Oracle 7. We've upgraded to Oracle 10g. I've looked through the old manuals ( Pro*C Supplement to the ORACLE Precompilers Guide Version 1.5) for an answer to a question and can't find it in the old manuals. I haven't tried looking through the online manuals for the newer version yet, so if the answer is readily available there I apologize.
    The question is, "Can a bind variable be used more than once within a SQL command?"
    Example: find all employees whose first or last name is not Lee.
    SELECT first_name, last_name
    FROM employee
    WHERE first_name <> :criteria1
    AND last_name <> :criteria2;
    In an example like this, both bind variables contains the same value (Lee). Is it still required to have separate bind variables? Or could I re-use a bind variable, like this:
    SELECT first_name, last_name
    FROM employee
    WHERE first_name <> :criteria1
    AND last_name <> :criteria1;
    Obviously, this is a simplified example. In my application, there are some large unioned SQL statements that re-use the user's id over a dozen times. It would be nice to use just one bind variable repeatedly, rather than having ":userid1, :userid2, :userid3, ..., userid12".
    Thanks in advance,
    Darren

    Got it... you mean, do I ever use a bind variable to store the result of a SQL statement (query). Answer is no, the bind variables are always criteria that are used by the SQL. Output is obtained by using FETCH.
    So I ought to be safe then.
    Thank you,
    Darren

  • Where clause with Bind Variable in ViewObject

    As per recomendations from Jdev team they say that using Bind varialbles in where clause will improve the performance (Option 1) But it is causing us to create more view objects.
    Example : Lets say we have a View Object EmpVO
    Option 1:
    ViewObject vo=context.getViewObject("EmpVO");
    vo.setWhereClause("EMPNO=?");
    vo.setWhereClauseParam(0,st);
    (or)
    Option 2:
    vo.setWhereClause("EMPNO="+st);
    If we want to use same View Object "EmpVO" in another Action Class
    ViewObject vo1=context.getViewObject("EmpVO");
    vo1.setWhereClause("DEPTNO=?");
    vo1.setWhereClauseParam(0,str);
    It this case it throws an error saying BIND VARIABLE already exits. So we have to make another View Object.
    Where as if we did not use bind variable but used Option 2 approach the same view object can be used in multiple pages.(at the expense of performance as per Jdev team)
    Are we doing something wrong here or are there other ways to use the same view object when using bind variable in where clause.
    Thanks

    I haven't been using BC4J for a while, but I seem to recall that the recommendations are that you don't set the where clause at runtime: You're supposed to define your view with the bind parameter already in it.
    So you'd probably define an EmpsForEmpNoVO and type "EMPNO = ?" in the where box. (There are other ways of finding a single row/entity and one of those may well be more efficient. Perhaps a better example of where you might want a view of employees is WHERE DEPTNO = ?.)
    IIRC, all instances of a particular type of view share the same definition, so you have to be careful if you alter that at runtime. However, I think everything's set up so that you can have many different (and separate) resultsets for a single view (instance) - meaning that it's possible to "run" a view for (e.g.) two different ids. (It's definitely possible to create two different instances of a view from its definition - and the resultsets will definitely be separate then. I think there's a "create" method on the application module; I remember that "find..." always returns the same instance of the view.)
    Hope that's a push in the right direction (since no-one else had replied - and I hope not too much has changed since 9.0.3)....
    Mike.

  • Bind Variables

    Hi
    I have read happily the article The Values That Bind By Mark A. Williams (Oracle Magazine September/October 2005 ). Immediately I rushed to implement the article on over developers . The problem is that we have a SQL query using the in operators . For example : select col1,col2 ..coln from table where x in (value1,value2 ….).
    I such a case how can you \use the bind variables technique , which fit the queries in which each variable can have one value (e.g. select country_name
    from hr.countries
    where country_id = :country_id)
    I asked the following questions:
    ODP support Oracle spatial or at list using objects??
    Will ODP support oracle spetial???
    The answer are listed below.
    I tried using ODP bind variables technique using fixed array size and bind variables technique in ODP (the redundant vars were fulfilled with dummy values) . I used trace and tkprof (with SYS=NO) opposite oracle 9.2.0.5 and pare was equal to parse an fetch meaning : no reuse of execution plans.
    Do you have any IDEA????
    Best Regards
    David Yitzhak
    BSC (Information System), MBA
    .Net developer and Oracle and SQL Server Applicative /Infrastructure DBA
    From: Alex Keh [[email protected]]
    Sent: &#1497;&#1493;&#1501; &#1513;&#1504;&#1497; 10 &#1488;&#1493;&#1511;&#1496;&#1493;&#1489;&#1512; 2005 23:50
    To: Ischack David; [email protected]
    Subject: Re: Securing a .NET Application on the Oracle Database
    David,
    In your example ("select col1,col2 ..coln from table where x in (value1,value2 ….)"), x is the name of a column, which does not need to have a bind variable. You can just put in a .NET variable representing the string value of the column name and concatenate the SQL statement together.
    We are planning to supprt objects and VARRAYs around January/February. From these, you can build your own Spatial data types. Today, most .NET Spatial users employ XML when using their Spatial data in .NET.
    Alex
    ----- Original Message -----
    From: Ischack David
    To: [email protected]
    Sent: Sunday, October 09, 2005 2:27 PM
    Subject: Securing a .NET Application on the Oracle Database
    Some questions about bind variables , objects , Oracle spatial and ODP
    Hi
    I have read happily the article The Values That Bind By Mark A. Williams (Oracle Magazine September/October 2005 ). Immediately I rushed to implement the article on over developers . The problem is that we have a SQL query using the in operators . For example : select col1,col2 ..coln from table where x in (value1,value2 ….).
    I such a case how can you \use the bind variables technique , which fit the queries in which each variable can have one value (e.g. select country_name
    from hr.countries
    where country_id = :country_id)
    ODP support Oracle spatial or at list using objects??
    Will ODP support oracle spetial???
    Best Regards
    David Itshak
    BSC (Information System), MBA
    .Net developer and Oracle and SQL Server Applicative /Infrastructure DBA
    From: John Cook [[email protected]]
    Sent: &#1497;&#1493;&#1501; &#1513;&#1500;&#1497;&#1513;&#1497; 11 &#1488;&#1493;&#1511;&#1496;&#1493;&#1489;&#1512; 2005 4:15
    To: Ischack David
    Subject: Re: Some questions about bind variables , objects , Oracle spatialand ODP
    The situation you have described with multiple bind values is one I have considered. It's a problem. I think I can code a generic implementation, but doing so would take time away from activities that I get paid for.
    I haven't worked with Oracle Spatial.
    We'll have more articles on ODP.NET in the months ahead. I'm glad you liked Mark's article.
    ----- Original Message -----
    From: "Ischack David"
    To: [email protected]
    Subject: Some questions about bind variables , objects , Oracle spatial and ODP
    Date: Sun, 9 Oct 2005 23:27:24 +0200
    Some questions about bind variables , objects , Oracle spatial and ODP
    Hi

    Hi
    I have read happily the article The Values That Bind By Mark A. Williams (Oracle Magazine September/October 2005 ). Immediately I rushed to implement the article on over developers . The problem is that we have a SQL query using the in operators . For example : select col1,col2 ..coln from table where x in (value1,value2 ….).
    I such a case how can you \use the bind variables technique , which fit the queries in which each variable can have one value (e.g. select country_name
    from hr.countries
    where country_id = :country_id)
    I asked the following questions:
    ODP support Oracle spatial or at list using objects??
    Will ODP support oracle spetial???
    The answer are listed below.
    I tried using ODP bind variables technique using fixed array size and bind variables technique in ODP (the redundant vars were fulfilled with dummy values) . I used trace and tkprof (with SYS=NO) opposite oracle 9.2.0.5 and pare was equal to parse an fetch meaning : no reuse of execution plans.
    Do you have any IDEA????
    Best Regards
    David Yitzhak
    BSC (Information System), MBA
    .Net developer and Oracle and SQL Server Applicative /Infrastructure DBA
    From: Alex Keh [[email protected]]
    Sent: &#1497;&#1493;&#1501; &#1513;&#1504;&#1497; 10 &#1488;&#1493;&#1511;&#1496;&#1493;&#1489;&#1512; 2005 23:50
    To: Ischack David; [email protected]
    Subject: Re: Securing a .NET Application on the Oracle Database
    David,
    In your example ("select col1,col2 ..coln from table where x in (value1,value2 ….)"), x is the name of a column, which does not need to have a bind variable. You can just put in a .NET variable representing the string value of the column name and concatenate the SQL statement together.
    We are planning to supprt objects and VARRAYs around January/February. From these, you can build your own Spatial data types. Today, most .NET Spatial users employ XML when using their Spatial data in .NET.
    Alex
    ----- Original Message -----
    From: Ischack David
    To: [email protected]
    Sent: Sunday, October 09, 2005 2:27 PM
    Subject: Securing a .NET Application on the Oracle Database
    Some questions about bind variables , objects , Oracle spatial and ODP
    Hi
    I have read happily the article The Values That Bind By Mark A. Williams (Oracle Magazine September/October 2005 ). Immediately I rushed to implement the article on over developers . The problem is that we have a SQL query using the in operators . For example : select col1,col2 ..coln from table where x in (value1,value2 ….).
    I such a case how can you \use the bind variables technique , which fit the queries in which each variable can have one value (e.g. select country_name
    from hr.countries
    where country_id = :country_id)
    ODP support Oracle spatial or at list using objects??
    Will ODP support oracle spetial???
    Best Regards
    David Itshak
    BSC (Information System), MBA
    .Net developer and Oracle and SQL Server Applicative /Infrastructure DBA
    From: John Cook [[email protected]]
    Sent: &#1497;&#1493;&#1501; &#1513;&#1500;&#1497;&#1513;&#1497; 11 &#1488;&#1493;&#1511;&#1496;&#1493;&#1489;&#1512; 2005 4:15
    To: Ischack David
    Subject: Re: Some questions about bind variables , objects , Oracle spatialand ODP
    The situation you have described with multiple bind values is one I have considered. It's a problem. I think I can code a generic implementation, but doing so would take time away from activities that I get paid for.
    I haven't worked with Oracle Spatial.
    We'll have more articles on ODP.NET in the months ahead. I'm glad you liked Mark's article.
    ----- Original Message -----
    From: "Ischack David"
    To: [email protected]
    Subject: Some questions about bind variables , objects , Oracle spatial and ODP
    Date: Sun, 9 Oct 2005 23:27:24 +0200
    Some questions about bind variables , objects , Oracle spatial and ODP
    Hi

  • Bind Variable : required - no message, not required - error

    hi
    Please consider the example application created using JDeveloper 11.1.1.6.0
    at http://www.consideringred.com/files/oracle/2012/RequiredOrNotBVarApp-v0.01.zip
    It has these View Objects defined
    - EmployeesReqNoValueBVarVO which has a required Bind Variable, and where clause "last_name like '%' || :LastNameBVar || '%'"
    - EmployeesNotReqNoValueBVarVO which has a NOT required Bind Variable, and where clause "(:LastNameBVar is null or last_name like '%' || :LastNameBVar || '%')"
    The Bind Variable in both View Objects does NOT have a value (no default value, not programmatically set, not entered by the user, ...).
    This "no value set" aspect could be the result of a "development error", but the resulting observed behaviour is at least "peculiar".
    - scenario (sc1) : run "try tryEmployeesReqNoValueBVarVO", see a table filled with rows and NO message about the required Bind Variable
    - scenario (sc2) : run "try tryEmployeesNotReqNoValueBVarVO", see "No data to display." in the table and the "Missing IN or OUT parameter at index:: 1" error for the NOT required Bind Variable for a where clause that can deal with null values
    - question (q1) How can be explained that scenario (sc1) does not result in an error message about the required Bind Variable (and scenario (sc2) does result in an error message about the NOT required Bind Variable)?
    - question (q2) What does the "Required" checkbox for a Bind Variable really mean for Bind Variables used in a where clause of a View Object?
    If the described behaviour can be reproduced (using RequiredOrNotBVarApp-v0.01.zip), confirmations are welcome.
    (Aspects of these scenario's could be related to forum thread "Bind variable required/not required: strange behaviour".)
    many thanks
    Jan Vervecken

    Thanks for your reply Frank.
    Frank Nimphius wrote:
    ... your query actually is dependent on the existence of the bind variable because the bind variable is used in the where clause part. ...Sure, and the Bind Variable does exist (in both (sc1) and (sc2)).
    ... This has nothing to do with whether the bind variable value is checked for NULL and if the value it contains is NULL performs an "all you can eat" type of query. Because the existing, NOT required Bind Variable has not been given a value in scenario (sc2), the check for NULL only makes more explicit that NULL is a valid value for the SQL statement.
    ... Non required bind variables are used in the context of view criteria to avoid missing IN or OUT parameters. ...The "Required" checkbox for a Bind Variable is also available/enabled when the Bind Variable is not used in a View Criteria (in both (sc1) and (sc2)).
    ... In the case of a view criteria, the VO query may be executed without the view criteria applied and for this reason should not fail only because the defined bind variable is not provided. ...No View Criteria in the scenario's (sc1) and (sc2) I descirbe.
    ... If you run the query in the tester, you get
    (java.sql.SQLException) Missing IN or OUT parameter at index:: 1
    and no query is executed at all for EmployeesNotReqNoValueBVarVOSure, that matches scenario (sc2), but the Bind Variable can be configured as NOT required, how can it be missing?
    The JDeveloper help page "Create or Edit Bind Variables Dialog - Variable Page" says:
    "... Alternatively, you can use the SQL Statement page of the Edit View Objects dialog to enter a parameterized WHERE clause. Note that the bind variables you enter in a parameterized SQL WHERE clause will require a valid value at runtime or a runtime exception error will be thrown. ..."
    So, null as a valid value, seems to explain the behaviour in scenario (sc1).
    "... In contrast, when you create a view criteria filter condition that references a named bind variable, you can specify whether the value is required or optional. ..."
    But, the "Required" checkbox is also available (to uncheck) for Bind Variables that are not used in a View Criteria.
    Specifically for the "Required" checkbox the help page says : "... Select if you want to make the value of a name bind variable required for any usage the references the named bind variable. For example, when the value is required (default), all view criteria items that reference the named bind variable will fail to execute unless a valid value is supplied at runtime. Alternatively, you can leave the value not required and use the Create View Criteria dialog to specify whether or not individual view criteria items require the value. ..."
    Again, the focus is on View Criteria, although it can also be unchecked (configuring as NOT Required) for Bind Variables that are not used in a View Criteria (which does not seem to be something you should do).
    But, still, there is a perspective here that makes this possibly very confusing:
    - a View Object where clause with a required Bind Variable, no value set --> results in rows, and NO message about a missing value
    - a View Object where clause with a NOT required Bind Variable, no value set --> results in no rows, and a message about a missing value
    regards
    Jan

  • Exception caused by bind variables in ORDER BY clause and VO RANGE_PAGING

    Hi,
    I'm using a ViewObject in RANGE_PAGING mode and discovered a problem when using bind variables in the ORDER BY clause of my statement:
    SELECT * FROM (SELECT /*+ FIRST_ROWS */ IQ.*, ROWNUM AS Z_R_N FROM (
      SELECT * FROM T_TABLE WHERE (attr1 = :1) ORDER BY decode (attr2, :2, 1, null, 0, -1) desc, attr3 ) IQ 
      WHERE ROWNUM < :2) WHERE Z_R_N > :3 When a bind variable is used in the ORDER BY CLAUSE and the method VO.getEstimatedRowCount() is call then the DB issued an SQL error:
    java.sql.SQLException: Ungültiger Spaltenindex (eng.: invalid column index)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:137)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:174)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:239)
         at oracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:4612)The numbering of the bind variables indicates that the last two bind variables have the wrong numbering (??)
    When I rewrite the SQL into the following statement, the SQL error does not occur but I have not verified yet that the VO delivers the correct range of data because the numbering of the bind variables is not correct.
    SELECT * FROM (SELECT /*+ FIRST_ROWS */ IQ.*, ROWNUM AS Z_R_N FROM (
      SELECT *, decode (attr2, :1, 1, null, 0, -1) as ATTR_FOR_SORTING FROM T_TABLE WHERE (attr1 = :2) ORDER BY ATTR_FOR_SORTING  desc, attr3 ) IQ 
      WHERE ROWNUM < :2) WHERE Z_R_N > :3I'm working with JDev 10.1.2 and Oracle DB 9203.
    Any comments are welcome!
    Thanks,
    Markus

    You are using the bind variable :2 twice. Did you try
    SELECT * FROM (SELECT /*+ FIRST_ROWS */ IQ.*, ROWNUM AS Z_R_N FROM (
      SELECT * FROM T_TABLE WHERE (attr1 = :1) ORDER BY decode (attr2, :2, 1, null, 0, -1) desc, attr3 ) IQ 
      WHERE ROWNUM < :4) WHERE Z_R_N > :3
    setWhereClauseParm(0, "a"); // :1
    setWhereClauseParm(1, "b"); // :2
    setWhereClauseParm(2, "c"); // :3
    setWhereClauseParm(3, "b"); // :2setting the fourth parameter the same as the second one?
    I remeber reading something about using bind variables twice causing problems, but I#m not sure about it.

  • Bind variable not declared - please help

    Hello,
    I have wrote a PL/SQL script to update some order_id's in a table. I have declared all my variables but get an error -- bind variable not declared. Can anyone tell me what the problem might be?
    DECLARE
             last_ship      DATE ;
             last_order     NUMBER;
             last_cust      NUMBER;
    VARIABLE curr_item      NUMBER;
    VARIABLE curr_order     NUMBER;
             aorder_id      CHAR(6);
             aitem_id       CHAR(2);
             acust_id       NUMBER(6);
             aship_date     DATE;
    CURSOR c1 IS
          SELECT 
                  order_id,
                  item_id,
                  ship_date,
                  cust_id
          FROM
                  test_sales
          ORDER BY
                  1,2,3,4,5;
    BEGIN
          SELECT
                  MAX(order_id)
          INTO
                   curr_order
          FROM
                   sales_order;
    OPEN c1;
         LOOP
             FETCH c1 INTO aorder_id, aitem_id, aship_date, acust_id;
             EXIT WHEN c1%NOTFOUND;
               last_cust      := c1.cust_id;          -- Saves the last values to check if processing same order
               last_order     := c1.aorder_id;        --
               last_ship      := c1.aship_date;       --
               IF c1.aorder_id = last_order AND c1.cust_id = last_cust AND c1.ship_date = last_ship THEN
                  curr_item   := curr_item  +1;
                  UPDATE test_sales SET c1.aorder_id = :curr_order;
                  UPDATE test_sales SET c1.aitem_id  = :curr_item;
               ELSE
                  curr_order := curr_order + 1;
                  curr_item  := 1;
                  UPDATE test_sales SET c1.aorder_id =  :curr_order;
                  UPDATE test_sales SET c1.aitem_id  = :curr_item;
               END IF; 
        END LOOP;
    CLOSE c1;
    END;
    /Cheers
    Mike

    check yours code you are direct accesing cusrsor named directly which is not allowed
      1  DECLARE
      2  vemp  emp.empno%TYPE;
      3  vemp1 emp.empno%TYPE;
      4  CURSOR c1 IS SELECT empno FROM emp;
      5  BEGIN
      6   OPEN c1;
      7    LOOP
      8     FETCH c1 INTO vemp;
      9     EXIT WHEN c1%NOTFOUND;
    10     vemp1:=c1.empno;
    11    END LOOP;
    12   CLOSE c1;
    13* END;
    SQL> /
       vemp1:=c1.empno;
    ERROR at line 10:
    ORA-06550: line 10, column 14:
    PLS-00225: subprogram or cursor 'C1' reference is out of scope
    ORA-06550: line 10, column 4:
    PL/SQL: Statement ignored
    SQL> DECLARE
      2  vemp emp.empno%TYPE;
      3  CURSOR c1 IS SELECT empno FROM emp;
      4  BEGIN
      5   OPEN c1;
      6    LOOP
      7     FETCH c1 INTO vemp;
      8     EXIT WHEN c1%NOTFOUND;
      9    END LOOP;
    10   CLOSE c1;
    11  END;
    12  .
    SQL> /
    PL/SQL procedure successfully completed.Yours code
    OPEN c1;
    LOOP
    FETCH c1 INTO aorder_id, aitem_id, aship_date, acust_id;
    EXIT WHEN c1%NOTFOUND;
    last_cust:= c1.cust_id;
    last_order:= c1.aorder_id;
    END LOOP;
    CLOSE c1;
    END;You sholud move it c1.cust_id within fetch statment or
    bind the cursor name with another local cursor variable
    then fetch into this local bind variable and use cursor
    via this variable
    e.g
    DECLARE
    CUSRSOR c1 IS SELECT cust_id,aorderid
        FROM <TABLE>;
    c2      c1%ROWTYPE;
    OPEN c1;
    LOOP
    FETCH c1 INTO c2;
    aorder_id:=c2.aorderid;
    last_cust:= c1.cust_id;
    last_order:= c1.aorder_id;
    END LOOP;
    CLOSE c1;
    END;Khurram

Maybe you are looking for