Bind variables in query

Hi,
I have a query that is taking up so much memory of the shared pool that I get this Oracle error message: ORA-04031: unable to allocate 1120 bytes of shared memory ("shared pool","SELECT DECODE(NULL,NULL,'Sta...","sql area","strdef & evalk : evalks")
From reading on asktom, I understand that I need to check for bind variables in my SQL statement, as these are the main cause of poor performance. I'm not sure how to correct my SQL statement. I thought I was already using bind variables. Here's my code:
DECLARE
   q VARCHAR2(32767);
BEGIN
q:='SELECT '||
'DECODE(NULL,NULL,''Station to Station'') as col1, '||
'sum(s_to_s_norm) as col2, '||
'sum(s_to_s_pre) as col3,  '||
'sum(s_to_s_norm)+sum(s_to_s_pre) as col4, '||
'sum(s_to_s_busy) as col5, '||
'sum(s_to_s_LT) as col6, '||
'sum(s_to_s_GT) as col7, '||
'sum(s_to_s_busy)+sum(s_to_s_LT)+sum(s_to_s_GT) as col8, '||
'sum(s_to_s_norm)+sum(s_to_s_pre)+sum(s_to_s_busy)+sum(s_to_s_LT)'||
'+sum(s_to_s_GT) as col9, '||
'DECODE(NULL,NULL,1) as col10 '||
'FROM traffic_sum_view '||
'WHERE TO_DATE('||:SORTFIELD||') '||
'BETWEEN TO_DATE(substr(:STARTDATE,1,19),''dd-MON-YYYY hh24:mi'') '||
'AND TO_DATE(substr(:STOPDATE,1,19),''dd-MON-YYYY hh24:mi'') '||
'AND switch_id = ''' ||:P1_SWITCH_ID|| ''';';
return q;
end;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Hi,
I have a query that is taking up so much memory of
the shared pool that I get this Oracle error message:
ORA-04031: unable to allocate 1120 bytes of shared
memory ("shared pool","SELECT
DECODE(NULL,NULL,'Sta...","sql area","strdef & evalk
: evalks")
From reading on asktom, I understand that I need to
check for bind variables in my SQL statement, as
these are the main cause of poor performance. I'm
not sure how to correct my SQL statement. I thought
I was already using bind variables. Here's my code:
DECLARE
q VARCHAR2(32767);
IN
q:='SELECT '||
'DECODE(NULL,NULL,''Station to Station'') as col1,
'||
'sum(s_to_s_norm) as col2, '||
'sum(s_to_s_pre) as col3,  '||
'sum(s_to_s_norm)+sum(s_to_s_pre) as col4, '||
'sum(s_to_s_busy) as col5, '||
'sum(s_to_s_LT) as col6, '||
'sum(s_to_s_GT) as col7, '||
'sum(s_to_s_busy)+sum(s_to_s_LT)+sum(s_to_s_GT) as
col8, '||
'sum(s_to_s_norm)+sum(s_to_s_pre)+sum(s_to_s_busy)+sum
(s_to_s_LT)'||
'+sum(s_to_s_GT) as col9, '||
'DECODE(NULL,NULL,1) as col10 '||
'FROM traffic_sum_view '||
'WHERE TO_DATE('||:SORTFIELD||') '||
'BETWEEN
TO_DATE(substr(:STARTDATE,1,19),''dd-MON-YYYY
hh24:mi'') '||
'AND TO_DATE(substr(:STOPDATE,1,19),''dd-MON-YYYY
hh24:mi'') '||
'AND switch_id = ''' ||:P1_SWITCH_ID|| ''';';
return q;
end;Bind variables are ENCOURAGED in SQL Selects!! They allow the database to reuse your query as apposed to recompiling the code each time.. Where on AskTom did you see a statement advising against Bind Variables??
Thank you,
Tony Miller
UTMB/EHN

Similar Messages

  • How to use bind variables in "query result" "validation rule"

    I have created a validation rule on my entity object. rules=compareValidator attribute=InvoiceNumber operator=NotEquals queryResult=SELECT ...
    In this query, I would like to reference entity attributes from the current instance of the entity when the value fires, for example SELECT invoice_number where invoice_id != :invoiceId
    How can I reference a bind variable inside the query result compare validator validation rule?
    THanks,
    Jerry.

    bump

  • How to assign sessionscope variable to the bind variable in Query of VO

    Hi all,
    I want to know how to assign a sessionscope variable in the binvariable of Query in VO
    My sessionscope variable holds the value of currently selected column in the table. eg:empname of the currently selected column which is in empdetails table...
    I want display the schemes available for the selected employee in the next table..The schemes are in another table named empschemes which has the empname and empschemes as column
    I have created a vo for empschemes table with bind variable 'scheme_bind'..I need to set the sessionscope variable '#{sessionScope.empname}" to the bind variable.
    Its urgent,..Pls do reply asap
    Thanks in advance
    Nasrin

    HI,
    You can use
    adf.context.sessionScope.get("YourSessionVariable")this code for assigning VO's bind variable value.write this code where you create bind variable and do not forget click on expression radio button.
    Rafat

  • Problem binding variable to query in procedure

    Hi folks,
    I'm having an issue binding a variable to a query.  For example the following works in my procedure;
    DECLARE V_PLANT NVARCHAR(4) := 'ACME';
    tempVar = select field1 from myView where Plant = :V_PLANT;
    When I debug my procedure I can see the variable V_PLANT = 'ACME' and tempVar contains 1 single value (field1) record.
    Now, alternatively, if I try passing my variable like this it is not working (get error: no data found);
    DECLARE V_PLANT NVARCHAR(4) := 'ACME';
    ABCVariable NVARCHAR(45) := '';
    select field1 into ABCVariable from myView where Plant = :V_PLANT;
    However if I hard code the plant variable as a literal string like this I indeed get data;
    DECLARE V_PLANT NVARCHAR(4) := 'ACME';
    ABCVariable NVARCHAR(45) := '';
    select field1 into newVariable from myView where Plant = 'ACME';
    Result is I have a value of 'ACME' in ABCVariable.  It seems when I'm using SELECT INTO syntax I can no longer use variables in the where condition.
    Any suggestions?
    Thanks,
    -Patrick

    Hi Patrick
    I cannot reproduce this problem:
    create procedure get_article_by_label (IN v_article_label varchar)
    language sqlscript
    as
    begin
        declare v_article_id integer := -1;
        select max(article_id) into v_article_id
        from efashion.article_lookup
        where UPPER(article_label) like '%' || UPPER(:v_article_label) || '%';
        select * from efashion.article_lookup
        where article_id = :v_article_id;
    end;
    call get_article_by_label ('Leather Belt');
    ARTICLE_ID  ARTICLE_LABEL           CATEGORY            SALE_PRICE  FAMILY_NAME FAMILY_CODE
    143848      Patchwork Leather Belt  Belts,bags,wallets  88.9        Accessories F60       
    As you see I use the input variable in the WHERE condition, and reuse the found ID to select data again.
    Not sure though, why it doesn't work in your case.
    Is the target variable in your working example also ABCVariable or indeed newVariable?
    - Lars

  • How to use SYSDATE as a default value of a bind variable in a query report?

    Hi,
    I want to use SYSDATE as default value for a bind variable in Query based report.
    I don't see any way to do it, someone helps?
    Thanks a lot.
    Paulo.

    You can aslo use #sysdate directly.
    Hi,
    The way I'm doing in my report is, I have a database function (f_ret_sysdate) with the following code
    create function f_ret_sysdate return varchar2
    begin
    return to_char(sysdate,'mm/dd/yyyy');
    end;
    Now, in the 'Customization Form Display Options' section of the report I'm calling this function as #f_ret_sysdate in the default value field of corresponding bind variable to display SYSDATE with the format.
    Hope this helps!...
    -Krishnamurthy

  • ORA-01006 Using Bind Variables In A Dynamic SQL Contains Query

    I have the following dynamic SQL query :-
    declare
    TYPE typ_sql IS REF CURSOR;
    ltyp_sql typ_sql;
    lv_sql VARCHAR2(100);
    begin
    lv_sql := 'SELECT arx_id FROM arx WHERE CONTAINS ';
    lv_sql := lv_sql || (arx_full,''(:b1) WITHIN ui'') > 0';
    open ltyp_sql FOR v_sql USING ln_id;
    fetch ......
    close ......
    end;
    When the code tries to open the cursor it gives the above error. I presume it is the way Oracle is expanding the bind variable but I cannot find anything in the docs to say why this is happening or whether you can do this or not using bind variables ( CONTAINS query ). Any help would be appreciated, thanks,
    Stuart.

    lv_sql || '(arx_full, :b1 || '' within ui'') > 0';

  • Help need in Binding variable with ViewObject

    hi All,
    iam very new to Oracle ADF . Iam using Jdeveloper 11.1.1.3.0 for developing ADF Application.
    i have created a view object with binding variable "emp_name".
    query :: select * from emp_adf where name:=emp_name
    i need to get this value from my page(jspx).
    please help me how to proceed further.
    My requriement:
    page should have one text filed and after submitting the value it should query the DB and result should come.
    If any one gives little demo or article for this ,it will be really helpful for me.
    Regards,
    Suresh kumar.

    I think below links would be useful for you.
    http://download.oracle.com/docs/cd/E15523_01/web.1111/b31974/bcquerying.htm#CEGDGIJH
    http://jobinesh.blogspot.com/2010/10/how-to-set-bind-variable-values-at.html
    ~Abhijit

  • 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

  • Is it possible to set bind variable for picklist?? for messageChoice

    we are trying to develop one new page in local JDeveloper.
    we have requirement for passing a bind variable to a picklist. is it possible?
    Item Type : messageChoice
    Query:
    SELECT DISTINCT TO_CHAR (effective_date, 'YYYY') TYPE
    FROM pay_assignment_actions a, pay_payroll_actions b
    WHERE a.payroll_action_id = b.payroll_action_id
    AND assignment_id =
    (SELECT assignment_id
    FROM per_assignments_x
    WHERE person_id = :person_id AND primary_flag = 'Y'
    AND assignment_type = 'E')
    AND a.action_status = 'C'
    AND b.payroll_action_id IN (SELECT payroll_action_id
    FROM pay_payroll_actions_v
    WHERE action_type IN ('P'))
    AND b.payroll_action_id IN (SELECT payroll_action_id
    FROM xxilo_pre_payments)
    ORDER BY 1 DESC
    processRequest() code:
    PayslipAMImpl am=(PayslipAMImpl)pageContext.getApplicationModule(webBean);
    YearPicklistVOImpl yvo=(YearPicklistVOImpl)am.getYearPicklistVO1();
    Number t = new Number(pageContext.getEmployeeId());
    yvo.setWhereClauseParams(null);
    yvo.setWhereClauseParam(0,t);
    for this query & code we are getting
    ERROR:
    java.sql.SQLException: Missing IN or OUT parameter at index:: 1
    if we hardcoded person_id in query to some value then we are getting results without any error.

    user603084 ,
    In the query you have specifies bind variable as :person_id , but in your VO execution code you are setting value for bind variable :1
    yvo.setWhereClauseParam(0,t);
    You need to change the bind variable in query , like :1
    and then execute the query of VO, as you have done. Also do executeQuery, after setting bind variables.
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Using bind variable in dynamic where clause and concatenate with query

    Hi,
    In my procedure i am framing where clause dynamically with bind variable,When i am concatenate this with my sql query for REF CURSOR i got sql command not properly ended exception.
    Is it possible to pass values to the bind variable through the dynamic variable/value?
    Please advise
    Thanks in advance
    Siva
    IF in_applicationId IS NOT NULL THEN
              optional_where := optional_where || ' AND a.APPLICATION_ID like '||':e%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id'||',in_applicationId';
         END IF;
    My query is like this
    open Out_Main FOR SelectQuery USING optional_using

    Thanks for reply,
    In my procedure, i suppose to frame the where clause with bind dynamically according to the input parameters. so that i am framing the values of the bind variables also dynamically like this,
    Please advise...
    IF in_assignedAppFlag IS NOT NULL THEN
              IF in_assignedAppFlag = 'Y' THEN
                   optional_where := optional_where || ' AND b.ASSIGNED_TO = :b' ;
              optional_using := ' in_appFuncGroup'||',in_currentUserID';          
              ELSe
                   IF in_isSupervisor = 0 THEN
                        optional_where := optional_where || ' AND (b.ASSIGNED_TO = :b'||' OR b.ASSIGNED_TO = ''-1'' OR b.ASSIGNED_TO IS NULL)';
              optional_using := ' in_appFuncGroup'||',in_currentUserID';
                   END IF;
              END IF;
         ELSE
              IF in_isSupervisor = 0 THEN
                   optional_where := optional_where || ' AND (b.ASSIGNED_TO = :b'||' OR b.ASSIGNED_TO = ''-1'' OR b.ASSIGNED_TO IS NULL)';
                   optional_using := ' in_appFuncGroup'||',in_currentUserID';
              END IF;
         END IF;
         IF in_appFuncGroup IS NOT NULL THEN
              optional_where := optional_where || ' AND e.APP_FUNC_GROUP= :c';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup';
         END IF;
         IF in_queue_id IS NOT NULL THEN
              optional_where := optional_where || ' AND b.QUEUE_ID = :d';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id';
         END IF;
         IF in_applicationId IS NOT NULL THEN
              optional_where := optional_where || ' AND a.APPLICATION_ID like '||':e%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id'||',in_applicationId';
         END IF;
         IF in_sourceCode IS NOT NULL THEN
              optional_where := optional_where || ' AND e.APP_SOURCE_CODE like '||':f%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode';
         END IF;
         IF in_logo IS NOT NULL THEN
              optional_where := optional_where || ' AND appProds.PRODUCT_TYPE like '||':g%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo';
         END IF;
         IF in_firstName IS NOT NULL THEN
              optional_where := optional_where || ' AND upper(a.FIRST_NAME) like upper(:h%)';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName';
         END IF;
         IF in_surName IS NOT NULL THEN
              optional_where := optional_where || ' AND upper(a.SURNAME) like upper(:i%)';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName'||',in_surName';
         END IF;
         IF in_retreival_id IS NOT NULL THEN
              optional_where := optional_where || ' AND e.RETREIVAL_ID like :j%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName'||',in_surName'||',in_retreival_id';
         END IF;

  • Query with bind variable, how can use it in managed bean ?

    Hi
    I create query with bind variable (BindControlTextValue), this query return description of value that i set in BindControlTextValue variable, how can i use this query in managed bean? I need to set this value in String parameter in managed bean.
    Thanks

    Put the query in a VO and execute it the usual way.
    If you need to, you can write a parameterized method in VOImpl that executes the VO query with the parameter and then call that method from the UI (as a methodAction binding) either through the managed bean or via a direct button click on the page.

  • LOV query with bind variable

    Hi,
    I have a LOV with a query has a bind variable:
    select comp_plan_id,name from cn_comp_plans_all
    where sysdate between start_date and nvl(end_date,sysdate+1)
    and org_id = : 1
    So I create a CO for this LOV , and in processRequest(), I pass the value of this bind varible.
    Now in the base page,
    if comp plan crteria is blank, this LOV works fine.
    if comp plan criteria has value: 2007 PTE COMP PLAN 1001
    I get this error:
    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM (select comp_plan_id,name from cn_comp_plans_all
    where sysdate between start_date and nvl(end_date,sysdate+1)
    and org_id =:1) QRSLT WHERE (( UPPER(NAME) like :2 AND (NAME like :3 OR NAME like :4 OR NAME like :5 OR NAME like :6)))
    Because '2007 PTE COMP PLAN 1001' has 5 tokens, the generated query automatically add 'Name' 5 times.
    Can anyone help?
    thanks
    Lei

    Complete error is:
    java.sql.SQLException: Invalid column type
    Exception Details.
    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM (select comp_plan_id,name,org_id from cn_comp_plans_all
    where sysdate between start_date and nvl(end_date,sysdate+1)
    and org_id = :1) QRSLT WHERE (( UPPER(NAME) like :2 AND (NAME like :3 OR NAME like :4 OR NAME like :5 OR NAME like :6)))
         at oracle.apps.fnd.framework.OAException.wrapperException(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageErrorHandler.prepareException(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageErrorHandler.processErrors(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
         at OA.jspService(_OA.java:75)
         at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
         at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:453)
         at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:591)
         at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:515)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:711)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:368)
         at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:866)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:448)
         at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:216)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:117)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:110)
         at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
         at java.lang.Thread.run(Thread.java:595)
    ## Detail 0 ##
    java.sql.SQLException: Invalid column type
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:138)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:175)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:240)
         at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:7895)
         at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7572)
         at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8183)
         at oracle.jdbc.driver.OraclePreparedStatement.setObjectAtName(OraclePreparedStatement.java:8206)
         at oracle.jbo.server.OracleSQLBuilderImpl.bindParamValue(OracleSQLBuilderImpl.java:3916)
         at oracle.jbo.server.BaseSQLBuilderImpl.bindParametersForStmt(BaseSQLBuilderImpl.java:3335)
         at oracle.jbo.server.ViewObjectImpl.bindParametersForCollection(ViewObjectImpl.java:13746)
         at oracle.jbo.server.QueryCollection.buildResultSet(QueryCollection.java:801)
         at oracle.jbo.server.QueryCollection.executeQuery(QueryCollection.java:666)
         at oracle.jbo.server.ViewObjectImpl.executeQueryForCollection(ViewObjectImpl.java:3655)
         at oracle.jbo.server.OAJboViewObjectImpl.executeQueryForCollection(Unknown Source)
         at oracle.apps.fnd.framework.server.OAViewObjectImpl.executeQueryForCollection(Unknown Source)
         at oracle.jbo.server.ViewRowSetImpl.execute(ViewRowSetImpl.java:742)
         at oracle.jbo.server.ViewRowSetImpl.executeQueryForMasters(ViewRowSetImpl.java:891)
         at oracle.jbo.server.ViewRowSetImpl.executeQueryForMode(ViewRowSetImpl.java:805)
         at oracle.jbo.server.ViewRowSetImpl.executeQuery(ViewRowSetImpl.java:799)
         at oracle.jbo.server.ViewObjectImpl.executeQuery(ViewObjectImpl.java:3575)
         at oracle.apps.fnd.framework.server.OAViewObjectImpl.executeQuery(Unknown Source)
         at oracle.apps.fnd.framework.server.OAViewObjectImpl.initQuery(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.setCriteriaOnVO(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAListOfValuesHelper.processRequestAfterController(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAListOfValuesHelper.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.beans.layout.OAListOfValuesBean.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.beans.OABodyBean.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
         at OA.jspService(_OA.java:75)
         at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
         at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:453)
         at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:591)
         at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:515)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:711)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:368)
         at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:866)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:448)
         at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:216)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:117)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:110)
         at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
         at java.lang.Thread.run(Thread.java:595)

  • Report Query with Bind variables working very slowly

    Hi everyone,
    I'm having a hard time with one of my Reports.
    Basically the query looks like this:
    Select *
    from x,y,z
    where x.lang_id = :P1_LANG
    and y.name = :P1_LANG;
    I have a textfield and a Select List on my Page which have to have a value before the report is shown.
    Now to the problem, when I input a value into these Application Items the Report takes ages (3-5 min). But when I replace the Bind variables (:P1_LANG and :P1_LANG) with the actual values it takes mere seconds.
    Anyone got an idea why this might be?
    I'm at my wits end -.-
    Edited by: DocD on Oct 27, 2009 3:01 AM

    Hi
    This could be for a number of reasons and unfortunately there is no quick answer...
    When you run a query for the first time, the execution plan is worked out by the Cost Based Optimiser (I'm assuming you're using 10g or above here). This is referred to as a hard parse. Next time the same SQL text is used then the execution plan may still be in the shared pool - in this case the same execution plan is used rather than being calculated again.
    The great thing about using bind variables is that even with different inputs, the SQL text is the same so the execution plan can be shared for different inputs. One downside is that if the first time the query is executed using bind variables, out of the ordinary values are input, bind variable peeking can lead to a sub optimal execution plan being calculated for the query and then shared in other situations (where more 'normal' values are input).
    However, it could be down to a host of other things too. So your first check is to make sure that you have executed both queries a number of times. If you are still getting the same performance issues then plan post the full query, table creation scripts and execution plan for both querys.
    Cheers
    Ben

  • Report query with bind variable

    Trying to create a report query for xsl-fo print. For output format I pick "derive from item" then pick the item name from the list, on the next screen, I paste the query with the bind variable. on the next step test query, I always get "data not found" regardless what value I type in. This is the same query that I ran under sql commands without any issues.
    Does anyone run into the same issue as I have when attempted to create a query with bind var ? There is no problem creating a query without bind varibles. . thanks.
    Munshar

    Hi, please did you get any solution to this issue? I am having similar challenge right now.
    select     EMP.DEPTNO as DEPTNO,
         DEPT.DNAME as DNAME,
         EMP.EMPNO as EMPNO,
         EMP.ENAME as ENAME,
         EMP.JOB as JOB,
         EMP.MGR as MGR,
         EMP.HIREDATE as HIREDATE,
         EMP.SAL as SAL
    from     SCOTT.DEPT DEPT,
         SCOTT.EMP EMP
    where EMP.DEPTNO=DEPT.DEPTNO
    and      DEPT.DNAME =upper(:dname)
    This run perfectly in sql developer, toad, and even inside publisher if I login directly to publisher to create report.
    Generating this same query in shared component query builder and testing it returns no data found. If I remove the last line, it works. but with the last line, it return no data found. It seems no one has been able to provide solution to this issue

  • Using a query with bind variable with columns defined as raw

    Hi,
    We are on Oracle 10.2.0.4 on Solaris 8. I have a table that has 2 columns defined as raw(18). I have a query from the front end that queries these two raw columns and it uses bind vairables. The query has a performance issue that I need to reproduce but my difficulty is that how to test the query in sqlplus using bind variables (the syntax for bind vairables fails for columns with raw datatype).
    SQL> DESC TEST
    Name                                      Null?    Type
    ID1                                                RAW(18)
    ID2                                                RAW(18)
    SQL> variable b1  RAW(18);
    Usage: VAR[IABLE] [ <variable> [ NUMBER | CHAR | CHAR (n [CHAR|BYTE]) |
                        VARCHAR2 (n [CHAR|BYTE]) | NCHAR | NCHAR (n) |
                        NVARCHAR2 (n) | CLOB | NCLOB | REFCURSOR |
                        BINARY_FLOAT | BINARY_DOUBLE ] ]
    The above is the error I get - i cant declare a variable as raw.
    SQL> variable b2  RAW(18);
    Usage: VAR[IABLE] [ <variable> [ NUMBER | CHAR | CHAR (n [CHAR|BYTE]) |
                        VARCHAR2 (n [CHAR|BYTE]) | NCHAR | NCHAR (n) |
                        NVARCHAR2 (n) | CLOB | NCLOB | REFCURSOR |
                        BINARY_FLOAT | BINARY_DOUBLE ] ]
    SQL> variable b3  RAW(18);
    Usage: VAR[IABLE] [ <variable> [ NUMBER | CHAR | CHAR (n [CHAR|BYTE]) |
                        VARCHAR2 (n [CHAR|BYTE]) | NCHAR | NCHAR (n) |
                        NVARCHAR2 (n) | CLOB | NCLOB | REFCURSOR |
                        BINARY_FLOAT | BINARY_DOUBLE ] ]
    --now the actual query below
    SQL> SELECT * FROM TEST WHERE ID1=:B1 AND ID2 BETWEEN :B2 AND :B3;
    SP2-0552: Bind variable "B3" not declared.
    (this fails due to the errors earlier)Also this is a third party app schema so that we don't have the option of modifying the data type of the columns.
    Thanks,
    Edited by: orausern on May 10, 2011 11:30 AM

    Try anonymous PL/SQL block:
    declare
    b1 RAW(18);
    b2 RAW(18);
    b3 RAW(18);
    begin
    b1:=..;
    b2:=..;
    b3:=..;
    SELECT col1, col2, ..
    INTO ...
    FROM TEST
    WHERE ID1=:B1
    AND ID2 BETWEEN :B2 AND :B3;
    end;
    /

Maybe you are looking for

  • Custom Field in Account Assignment with search help functionality..

    Hello friends,   I have added a custom field(Profit Center) in account assignment frame which is having search help also attached..   the data for search help read from R/3.. When i click the search help in WEB , I got an error message saying that 'N

  • MacBook Air won't turn on - it only hoots !

    My MacBook Air (2009/2010) will not turn on: when I press the power button there's a tinny little hooting sound  every 5 seconds, exactly in sync with the flashing power light - that's all - no sound of fans or anything, nothing to see on the black s

  • Can't create Connection to Oracle Database

    Hi i'm trying to create a simple connection to my oracle database and my projects compiles, but at the "createConnection" statement an SQLException is thrown. Well first of all my stats: Windows XP 32 bit Visual Studio 2005 (VC++ 8) Oracle Database 1

  • Activate External Display as mirror using Fn keys only

    My Macbook display is kaput. So i connected the external TV as display, but i need to activate the mirror display function. My HDD also kaput, so when booting from the install disc, it doesnt seem to recognose F2 or F7 or Shift F2 to activate the ext

  • LBP6000 squeezes the letter/words

    Hi everyone, My Canon LBP6000 is not printing correctly it kinda compresses/squeezes the words vertically/horizontally (depending on portrait/landscape), I can't describe it correctly so I attached these photos of a (landscape orientation): I have Wi