How to bind variables to a LOV query

Hi,
I have a page with a messageLOVInput field. I have attached an external LOV with it. The query attached to the LOVregion has a bind parameter which should be replaced by the logged in Person's Business Group ID.
I have done all the required LOV Mappings etc for a normal LOV.
If I hardcode the business group ID and then run the page, its working fine. But if I want to bind the businessgroup id at runtime, I am getting an error saying "all variables not bound"
I tried the usual method of calling some initMethod in AM from the CO of the external LOV region, and then calling some initQuery in the VO to set the bind parameter, but this doesn't work.
How do I bind variables at runtime with the LOV VO ?
Thanks, in advance !!
-Debojyoty

Hi Deb,
Heres what you gotta do.
By default the query is going to be executed in the EO . In case of a query without any bind variables this works fine. This is because for LOV EO's one doenst' have to explicitly call the the executequery method. In your case, there is one bind variable that needs to be set, before any query is fired, either implicitly or explicitly else you are going to get Bind variable not set exception.
1. Define an init query method in your EOImpl.
public void initQuery(String p_param)
setWhereClause(null);
setWhereClauseParams(null);
setWhereClauseParam(0,p_param);
2. Define a method for initializing the query. In your AM IMPL for the LOV, recieve the EOIMPL and call the initquery method and pass the parameter that you would to base the query upon.
3. In the CO for the LOV, call the AMimpl Method defined in step 2.
Let me know if this works ? If you still have problems, I will post some sample code.
Rgds,
Venkatesh
Message was edited by:
Venkatesh

Similar Messages

  • BUG ? :  ADF creating extra VO instance using bind variables in a LOV query

    ADF 11.1.1.1.0
    After "playing around" with bind variables Setting bind variables in view objects for LOV I've come across something strange that I've reproduce using the HR schema and tables Employees and Departments. Its a bit long but here goes :
    Using the HR schema tables departments and employeesI'm trying to create a LOV (selectOneChoice) for the
    employee department, the LOV having a bind variable that limits the values returned in this case returning only DepartmentId = 50
    I've create a VO lovDepartment (not based on an EO) with the following query :
    SELECT Departments.DEPARTMENT_ID,
           Departments.DEPARTMENT_NAME,
           Departments.MANAGER_ID,
           Departments.LOCATION_ID
    FROM DEPARTMENTS Departments
    where DEPARTMENT_ID  = :pDeptIdA LOV has been defined on the DepartmentId attribute of the EmployeesView.
    The lovDepartmentImpl overrides the executeQueryForCollection to set the bind variable value.
        @Override
        protected void executeQueryForCollection(Object object, Object[] object2,
                                                 int i) {
            setNamedWhereClauseParam("pDeptId", "50");       
            super.executeQueryForCollection(object, object2, i);
        }When using an ADF form to create a new employee the DepartmentId lov is empty.
    Enabling SQL tracing shows the following :
    [370] _LOCAL_VIEW_USAGE_model_EmployeesView_lovDepartment1_0 ViewRowSetImpl.doSetWhereClause(-1, pDeptId, null)
    [371] _LOCAL_VIEW_USAGE_model_EmployeesView_lovDepartment1_0 ViewRowSetImpl.execute caused params to be "un"changed
    [372] Column count: 4
    [373] _LOCAL_VIEW_USAGE_model_EmployeesView_lovDepartment1_0 ViewRowSetImpl.doSetWhereClause(-1, pDeptId, null)
    [374] _LOCAL_VIEW_USAGE_model_EmployeesView_lovDepartment1 ViewRowSetImpl.setNamedWhereClauseParam(pDeptId, 50)
    [375] ViewObject: _LOCAL_VIEW_USAGE_model_EmployeesView_lovDepartment1 Created new QUERY statement
    [376] _LOCAL_VIEW_USAGE_model_EmployeesView_lovDepartment1>#q computed SQLStmtBufLen: 235, actual=195, storing=225
    [377] SELECT Departments.DEPARTMENT_ID,
           Departments.DEPARTMENT_NAME,
           Departments.MANAGER_ID,
           Departments.LOCATION_ID
    FROM DEPARTMENTS Departments
    where DEPARTMENT_ID  = :pDeptId
    [378] Bind params for ViewObject: _LOCAL_VIEW_USAGE_model_EmployeesView_lovDepartment1
    [379] For RowSet : _LOCAL_VIEW_USAGE_model_EmployeesView_lovDepartment1_0
    [380] Binding null of type 12 for "pDeptId"
    [381] No Resource Bundle found but null value id:LOV_DepartmentId_LOVUIHints_NullValueId is defined in an ListBinding Definition.It would seem that 2 lovDepartment instances are used one at line 370 LOCALVIEW_USAGE_model_EmployeesView_lovDepartment1_0
    and one at line 374 LOCALVIEW_USAGE_model_EmployeesView_lovDepartment1
    The one at line 374 LOCALVIEW_USAGE_model_EmployeesView_lovDepartment1 gets the variable bound at line 374
    however LOCALVIEW_USAGE_model_EmployeesView_lovDepartment1_0 gets a null value and would explain the empty LOV
    Can anybody explain what is happening here ? (and how to use bind variables in LOV queries)
    Regards
    Paul
    (bump)
    Edited by: Paul (MITsa) on Jul 14, 2009 10:46 AM
    I've now tried all types of LOV from ChoiceList to Radio groupe by testing the application module - none of them work.....
    Edited by: Paul (MITsa) on 14-Jul-2009 22:52

    when you rinvoke executeQueryForCollection the bind variables are allready set and they exist in Object[] object2 method parameters.
    in order to change them you need something like:
    private void changeGenericBindVariable(Object[] params, String paramName, Object paramValue) {
    for (int i = 0; i < params.length; i++) {
    if (paramName.equals(((Object[])params)[0].toString()))
    ((Object[])params[i])[1] = paramValue;
    * executeQueryForCollection - overridden for custom java data source support.
    protected void executeQueryForCollection(Object qc, Object[] params,
    int noUserParams) {
    changeGenericBindVariable(params, "pDeptId", "50")
    super.executeQueryForCollection(object, object2, i);
    But its better to set bind variables before you executeQueryForCollection. like when you invoke LOV.
    For cascading LOVs and the problems i have check:
    [http://adfbugs.blogspot.com/2009/07/jdeveloper-11-r1-cascading-lov-bugs.html]

  • Extract the "bind" variables for a given query running in 10g.

    how can we extract the "bind" variables for a given query running in 10g? The performance of a query may vary based on the parameters supplied to it. For example, a query like the following
    SELECT * FROM CUSTOMER_ORDERS WHERE CUSTOMER = :CUST_ID
    .might run differently when the :CUST_ID is "123" who may have very few orders versus "456" who may have tens of thousands of orders.
    So, if we see a spike in the system due to a query, we need visibility into what the exact query syntax and values are for any database session. We're aware of an Oracle view called V$SQL_BIND_CAPTURE, but what we're finding with this view is that it's only a snapshot of variables that are refreshed on an interval. That view does not give us a live view into what values are being used in the various sessions in realtime.
    If someone ould provide us with some SQL (or other means) to do get a realtime view into the SQL and variables currently running in the database, it would be greatly appreciated.

    In addition to what's been said in the other thread, you could add a layer of logging either in the database or out.
    v$sql_bind_capture and the associated ash view dba_hist_sqlbind contain sample data.
    You could up the sample rate but it's not advisable - it's still just a sample.
    If you're on 11g, this is where adaptive cursor sharing might help.
    Not help in finding the values of your binds, but help in using different plans where there is such a skew for different bind values and the plan is perhaps wrong for customer 456.
    The problem when you're got such a skew and you're using bind variables is that the two don't really go together.
    When the query is next parsed and you've got bind variable peeking enabled, you might get the 123 plan is that is the bind value at parse time and then run into problems for 456 or even vice versa.
    See http://jonathanlewis.wordpress.com/2009/05/06/philosophy-1/ for a discussion on binds and histograms which reflects the reasons for using either.

  • How use integer variable as object in query

    sir how use integer variable as object in query
    see my code
    Integer currentssgg = new Integer(tt.getValue().toString()); no error
    //yy.setValue(currentss); no error
    //yy.setValue(new Integer(tt.getValue().toString())); no eror
    getSessionBean1().getTripRowSet().setObject(1,currentssgg); giv error
    tripDataProvider.refresh();
    and how use string variable same as method
    please give me idea how use integer variable as object in query
    thank's
    aamir

    >> var mnu = 'menu1';
    this[mnu].onRollOver = function(){
    <<
    Close, but it needs to be like this:
    var mnu = 1;
    this["menu" + mnu].onRollOver = function(){
    Dave -
    www.offroadfire.com
    Head Developer
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/

  • How to set a bind variable into a vo query from the current vo ?

    I would like to exclude from my list of values defined in a view object the already referenced items in the current view object content.
    Let's say i have dept and emp with a many to many relationships, I would like that the already existing dept for emp not listed (excluded) in the list of values for emp.
    Do i need to define a bind parameters and set it during search or is it possible to use an expression that will refer the current row attribute representing the dept ?
    I didn't find an example or explanation how to set bind parameters defined in a view object query from seach pages or list of values ui components. May be somebody know how to find the info.
    Thank you

    I think that bind variable accessors in the VO class is what you need. You can override the getter method of the bind variable "LocaleCode2" in order to return the first 2 chars from the bind variable "LocaleCode". Have a look at this blog post for details:
    http://jdeveloperandadf.blogspot.com/2011/03/custom-java-bind-variable-in-where.html
    Dimitar

  • Binding a variable to an LOV query, not working... Urgent!

    Hi,
    Based on a column value(which gets populated at runtime), in a table, the LOV query for another column in the same table, should be restricted with this value.
    1. My LOV is based on a VO.
    Lov query is
    SELECT ped.full_name as employee_name,
    ped.employee_number as employee_number
    FROM p_employee_details ped
    WHERE ped.value = 'Y' and ped.work in (:1, 'Both')
    2. For binding the variable, I have a method in VOImpl of the LOV.
    public void initQuery(String p_param)
    setWhereClauseParams(null);
    setWhereClauseParam(0,p_param);
    3. This method is called in the LOVAMImpl
    public void initializeVO(String p_param)
    LovVOImpl lovVO = (LovVOImpl)getLovVO1();
    lovVO.initQuery(p_param);
    4. In the CO for the LOV RN, the LOVAMimpl Method defined in step 3 is called.
    public void processRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processRequest(pageContext, webBean);
    OAApplicationModule lov_am = (OAApplicationModule) pageContext.getApplicationModule(webBean);
    Dictionary lov_dict = pageContext.getLovCriteriaItems();
    String lov_criteria = (String) lov_dict.get("work");
    Serializable lov_params[] = {lov_criteria};
    lov_am.invokeMethod("initializeVO",lov_params);
    Here "work" is the column in the table whose value is needed for binding the lov query
    But i am still getting an error saying not all variables bound.:
    Developer Mode Exception : Lov Input should by default be the queryable criteria and Result.
    I don't know what else to do.
    Thanks in advance

    HI,
    Here the code giving on starting of the thread will work,only problem is lov mapping over here which was same as mine , u have to create one more lov mapping which will have criterial item same as the field on which lov is based.
    Thanks

  • Setting bind variables in dependant LoV's : How?

    Hi
    I'm trying to create an LoV dependant upon the value selected in a previous Lov.
    I have created an LoV with a bind variable which executes correctly when run independantly of a form
    When I attach the loV to a form I get prompted to :-
    "Set the binding(s) for the bind variable(s) defined in the lov"
    How do I do this ?
    All replies gratefully recieved, thanks in advance
    Andy

    Examples of using a bind variable LOV are located in the "Building Portals" manual. On technet, click the Documentation tab, then open the "Building Portals" PDF.
    null

  • How to use bind variables in the following query

    CREATE OR REPLACE PROCEDURE MMDB.test IS
    sel_qtn VARCHAR2 (10);
    CURSOR PT_QUANTITY IS select * from mmdb.product_tree WHERE QUANTITY_CHECK ='E'
    AND run_id = 100
    a PT_QUANTITY%ROWTYPE;
    BEGIN
    FOR i IN PT_QUANTITY
    loop
    sel_qtn := i.quanttity-1;
    While sel_qtn>=1
    loop
    insert into mmdb.product_tree (BILLING_ACCOUNT_NO ,S_CODE) values (i.BILLING_ACCOUNT_NO ,i.S_CODE||'E');
    sel_qtn :=sel_qtn -1;
    End loop;
    commit;
    end;

    Don't duplicate threads: How to use bind variables in the following query

  • How to put variable selection and the query result the same screen

    Dear all,
       how can I put the variable selection and the query result in the same screen? Please advise. Thanks.
    Jin Ming

    Not sure if you are saying you want the prompts on the same page as the results... however in 7.0 with BEx Analyzer, you can insert a text object from the design toolbar and assign it to the variable.... this way, lets say you run query for period 6, then the text object will display "6" on the same area where the query results are.

  • How to include variable on block's query

    I have a block where I fetch data using Query with sub-querry on Query data source name. The problem is that I need to put a variable in a sub-query, but it returned error: ORA-01008 not all variables bound. I'm retrieving multiple records here.
    SELECT DISTINCT --fields
    FROM table1 a, table2 b, table3 c, table4 d
    WHERE a.line_cd = b.line_cd
    AND a.line_cd = 21
    --other conditions
    AND a.clm_seq_no = 7100003
    AND d.eff_dt = (SELECT MAX(eff_dt)
              FROM table4
              WHERE 1=1
              AND srvc_code = a.srvc_code
              AND line_cd = a.line_cd
              AND sched_no = a.sched_no
              AND cover_code = a.cover_code
              AND eff_dt <= :global.variable --problem
    )

    Thanks for your replies.
    Query Data source typy = Table, I also tried using package that serves as handler of global variable (variables.eff_dt) but it gives me error (cannot perform query).
    ( SELECT * FROM (SELECT DISTINCT a.claimant_seq, a.expense_title title,
    NVL(c.max_chrg, 0) max_chrg, NVL(c.min_chrg, 0) min_chrg, DECODE(tran_type, 2,
    a.amount * -1, a.amount) amnt, a.line_cd, a.subline_cd, a.iss_cd, a.clm_yy,
    a.clm_seq_no, a.item_no, a.peril_cd, a.sched_no, a.cover_code, a.srvc_code,
    a.srvc_dtl_code, NVL(a.days, 0) no_days, c.no_days days, NVL(d.min_chrg, 0) MIN,
    NVL(d.max_chrg, 0) MAX, a.dtls_seq, a.limit_amt, a.ctpl_amt, a.excess_amt
    FROM VTPLBI_DTLS a, POL_COVERAGE b, POL_SRVC_DTLS c, pol_services d
    WHERE a.line_cd = b.line_cd
    AND a.sched_no = b.sched_no
    AND a.cover_code = b.cover_code
    AND b.line_cd = d.line_cd
    AND b.sched_no = d.sched_no
    AND b.cover_code = d.cover_code
    AND a.srvc_code = d.srvc_code
    AND a.srvc_code = c.srvc_code(+)
    AND a.line_cd = c.line_cd(+)
    AND a.sched_no = c.sched_no(+)
    AND a.cover_code = c.cover_code(+)
    AND a.srvc_dtl_code = c.srvc_dtl_code(+)
    AND d.eff_dt = (SELECT MAX(eff_dt) --wency05082007
              FROM POL_SERVICES
              WHERE 1=1
              AND srvc_code = a.srvc_code
              AND line_cd = a.line_cd
              AND sched_no = a.sched_no
              AND cover_code = a.cover_code
              AND eff_dt <= variables.v_eff_dt --here is the problem
    UNION SELECT DISTINCT a.claimant_seq, a.expense_title, 0, 0, DECODE(tran_type,
    2, a.amount * -1, a.amount) amnt, a.line_cd, a.subline_cd, a.iss_cd, a.clm_yy,
    a.clm_seq_no, a.item_no, a.peril_cd, a.sched_no, a.cover_code, a.srvc_code,
    a.srvc_dtl_code, NVL(a.days, 0) no_days, 0, 0, 0, a.dtls_seq, a.limit_amt,
    a.ctpl_amt, a.excess_amt
    FROM VTPLBI_DTLS a
    WHERE (a.sched_no = 2 or a.sched_no is null) )
    ORDER BY dtls_seq ) comp_dtl
    Message was edited by:
    Wency

  • How to pass variable to jump to query !

    hello Experts !
    i have a query with variable "Month". so when i run that , user enters the Month/year and it gives the results for "Employee ID" for that month/year.
    i have also creted another query on dso, in order to get detail line item information abt " Employee ID" and join this query with the main one thru RRI.
    in RRI , i have selected "Employee ID" as single value field for both the query. the problem is when i do GOTO from the first query , it does work and gives me the result, but it gives records corresponds to that "Employee id"for all the months and year.
    How do i also pass "Month" - variable value along with that "Employee id" so that the second query only shows line item for that employee id for that selected month.
    thanx

    Hi,
    The use of jump query is to get the detailed level information, for the key figure values which appears in main query.
    This mainly happen when in your cube design you do not details information.
    For example:
    In your main query output you have :
    division , company code , variable amount
    Rec1)10, 1012,4000
    Rec2)20,1001,5000
    Now you want to know what are the document numbers involved to get the variable amount:
    So now , you jump query output will be for record no 1.
    Document number , variable amount
    100001,500
    100002,1000
    100003,2000
    100004,500
    So now you can see that jump query is giving you the documents numbers which are total of 4000.
    Once you have variable in main query , the jump will give details of those keyfigur values only.
    In case of jump query you need not to have any variable , it will automatically take from parant query.
    Though you can define varaible for jump also.
    I hope it clear your doubt
    Thanks
    Mayank

  • How to transfer variable value from one query to another query?

    I create two queries which contain the same variable "Year" and "Month".
    In the wad,Query1 is used to be a table and Query2 is used to show the chart in the condition with the same variable value of Query1
    So I want to transfer the variable  value from query1 to query2.
    Can anyone help me ?

    Let me explain the issue in detail.
    In Query Designer, both the year and  month variables are defined by user exit function to read current year and month and can be modified  during the query runtime.
    In WAD, Query1 is  used  to be a table with a table interface to hyperlink a chart which is defined by Query2 with the same variable value of Query1.
    During the runtime of template, if I change the variable value of Query1 , I want the variable of Query2 to be changed automatically with the same new value.
    So in the table interface of Query1 , I write the ABAP code in "SE24" and related source code to the variable is following:
    concatenate
    'function fire_urlJGSP_Col(filter) {'
    Cl_rsr_www_renderer=>c_lf
    'chart_url="' url '" + "&CMD=LDOC'
    '&TEMPLATE_ID=GCCHART_9' "WEB ID of the work book
    '&PAGEID=Graphics'       "Name of the view
    '&CMD=PROCESS_VARIABLES&SUBCMD=VAR_SUBMIT&VAR_NAME=Z2MYEAR&VAR_VALUE_EXT=" + filter'
    Cl_rsr_www_renderer=>c_lf
    'openWindow(chart_url,"chart_window","dependent=yes","600",'
    '"450","true")'
    Cl_rsr_www_renderer=>c_lf
    into l_coding.
    In this way , I can only transfer the year variable value from Query1 to Query2 and not two variables .
    So , how  shall I do to transer the two variable value in the same?

  • How to pass a value to a bind variable in a query report in oracle apex

    Hi Guys,
    I have requirement to send weekly reports via email to some users. The users should receive their own records in the report. The user details is stored in a table. What I am planning to do is to create a report query in oracle apex to generate the report and then run a function/procedure via a scheduler to email the report to respective users. Now my query is ............. is it possible to pass a value (user name) to the report query to pull records of only that user? I know we can have bind variables in the report query but I have no idea how to pass a value for bind variables from a function/procedure.
    Can anyone help me on this issue or suggest a better approach?
    Thanks,
    San

    You need to use dynamic sql
    But please keep in mind that since you're using Oracle you may be better off posting this in some Oracle forums
    This forum is specifically for SQL Server
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Need help in Bind variable in AF Query LOV

    Hi,
    i have one problem with bind variable, if i use bind variable in the LOV VO Query then my result is not coming, if there is not bind variable it's working fine and if i use the bind variable in the LOV search option then it's working fine but if i hide the bind variable and set the value in AM prepareSesstion method the LOV is not returning any value. I try to return the values also all values are also coming but those values are not setting to AF Query Attribute.
    Query is:
    select substr(d.description,0,40) description
    from cm_system_users a,
    cm_user_responsibilities b,
    cm_responsibility_processes c,
    cm_processes d
    where a.nt_login =:B_NT_LOGIN
    and a.user_id = b.user_id
    and trunc(sysdate) between b.eff_date and nvl(b.exp_date,sysdate + 1)
    and b.RESPONSIBILITY_ID = c.RESPONSIBILITY_ID
    and c.process_type = d.process_type
    and d.enabled_flag = 'Y' order by d.arguments_flag
    AM Method:
    CmProcessViewImpl vo = getCmProcessView();
    String nt_login = getUserPrincipalName();
    vo.setNamedWhereClauseParam("B_NT_LOGIN", nt_login.toUpperCase());
    vo.executeQuery();
    Can any one help me in this. it's urgent for me.

    This is a little underdescribed. IIUC, the view object in question is being used as a target for a view accessor, correct? (Otherwise you'll have to be more explicit about what you mean by "Query LOV".
    If I'm right, there are two possibilities:
    1) You are using a VO instance in a shared application module instance. If so, make sure your code is in the prepareSession() for that application module class if it's session dependent (as it seems to be below), you need to make sure the application module instance is shared at session scope.
    2) You've based the view accessor directly on the VO definition. This basically creates an anonymous VO instance; I don't think there's any way to use prepareSession() to set a bind variable on such an instance (which won't be created until the accessor is first used). You might be able to get by with putting similar code into the view object class' create() method, but I haven't tested this.
    If your code is in your primary application module class (as opposed to the class for a shared AM instance), the problem here is that getCmProcessView() returns the VO instance from that application module instance's design-time data model, which is never used by view accessors.
    By the way, why do you need to do this in prepareSession() instead of at the view accessor level? I believe you can get the logged in user name (for the view accessor) in with the groovy expression
    viewObject.DBTransaction.session.userPrincipalName
    or possibly just
    DBTransaction.session.userPrincipalName
    (despite this involving DBTransaction, it returns the web app user name, not the DB username).
    That's a 100% declarative solution, if you don't count the Groovy expression as non-declarative.
    If you're afraid of a user executing the LOV (somehow) before the bind variable value gets set, just ensure that the bind variable is marked "required".

  • Query don't use the right index when using bind variables

    Hi people !
    I need some help because I have an issue with a query that don t use the right Indexes as it should
    First of all, I have mainly three tables :
    ORDER : Table that contains description for each Order (approximately 1 000 000 Records)
    ORDER_MVTS : Table that contains the tasks made (called movements) to set up each Orders
    with quantity of packages prepared for each product (approximately 10 000 000 Records)
    PRODUCT : Tables that contains the products (approximately 50 000 Records)
    When I launch the query with hard coded values, it brings back response very fast
    because it uses the right index (ORDER_DHR_VALID) which represent the date and hour of the order
    (with format 'DD/MM/YYYY HH24:MI:SS'). The selectivity for this index is good.
    NB 1: I have to use the trick " >= Trunc(date) and < trunc(date) +1 " to filter on a simple date because
    the index contains hour and minutes (I know it wasn't probably a bright idea at conception time).
    NB 2: The index on ORDER_MVTS.PRODUCT_CODE is'nt discriminating enough because there is'nt enough different products.
    It's the same for index on CUSTOMER_CODE and on MVT_TYPE so only the index on ORDER.DHR_VALID is good.
    Here is the correct explain plan when I execute the query with hard coded values :
    SELECT SUM(ORDER_MVTS.NB_PACKAGE)
    FROM ORDER_MVTS, PRODUCT, ORDER
    WHERE ORDER.DHR_VALID >= TRUNC(to_date('14/11/2008 10:04:56','DD/MM/YYYY HH24:MI:SS'))
    AND ORDER.DHR_VALID < TRUNC(to_date('14/11/2008 10:04:56','DD/MM/YYYY HH24:MI:SS')) + 1
    AND ORDER_MVTS.MVT_TYPE = 'DELIVERY'
    AND PRODUCT.CODE = ORDER_MVTS.PRODUCT_CODE
    AND ORDER_MVTS.ORDER_CODE = ORDER.CODE
    AND ORDER.CUSTOMER_CODE = 'ADIDAS'
    AND PRODUCT.CODE = 1234
    Rows Row Source Operation
    1 SORT AGGREGATE
    2 NESTED LOOPS
    4 NESTED LOOPS
    2 INDEX UNIQUE SCAN (object id 378548) --> PRODUCT_PK
    4 TABLE ACCESS BY INDEX ROWID ORDER
    777 INDEX RANGE SCAN (object id 378119) --> ORDER_DHR_VALID
    2 TABLE ACCESS BY INDEX ROWID ORDER_MVTS
    30 INDEX RANGE SCAN (object id 377784) --> ORDER_MVTS_ORDER_FK
    Now the problem is when the query is used in a Cursor with bind variables.
    It seems like Oracle don't use index on ORDER.DHR_VALID because he can't figure out that he have
    to actually filter on a short period of time (only one day).
    So Oracle uses the index on ORDER_MVTS.PRODUCT_CODE which is'nt a bright idea (it takes 10 secondes instead of just one)
    Here is the bad explain plan :
    Rows Row Source Operation
    1 SORT AGGREGATE
    2 NESTED LOOPS
    722 NESTED LOOPS
    2 INDEX UNIQUE SCAN (object id 378548) --> PRODUCT_PK
    722 TABLE ACCESS BY INDEX ROWID ORDER_MVTS
    1790 INDEX RANGE SCAN (object id 377777) --> ORDER_MVTS_PRODUCT_FK
    2 TABLE ACCESS BY INDEX ROWID ORDER
    1442 INDEX UNIQUE SCAN (object id 378439) --> ORDER_PK
    Now I have found two solutions to this problem :
    1) using a Hint to force the use of index on ORDER.DHR_VALID (with /*+ INDEX(ORDER ORDER_DHR_VALID) */ )
    2) Using Dynamic SQL and keeping the date hard coded (but not the other values except mvt_type)
    For example :
    QUERY :=
    'SELECT SUM(ORDER_MVTS.NB_PACKAGE)
    FROM ORDER_MVTS, PRODUCT, ORDER
    WHERE ORDER.DHR_VALID >= TRUNC(TO_DATE('''||To_char(P_DTE_VAL,'DD/MM/YYYY')||''',''DD/MM/YYYY'')) '||
    AND ORDER.DHR_VALID < TRUNC(TO_DATE('''||To_char(P_DTE_VAL,'DD/MM/YYYY')||''',''DD/MM/YYYY'')) + 1 '||
    AND ORDER_MVTS.MVT_TYPE = 'DELIVERY'
    AND PRODUCT.CODE = ORDER_MVTS.PRODUCT_CODE
    AND ORDER_MVTS.ORDER_CODE = ORDER.CODE
    AND ORDER.CUSTOMER_CODE = :CUSTOMER
    AND PRODUCT.CODE = :CODE ';
    These two solutions work but Number 1 is bad in theory because it uses a Hint
    and Number 2 may be difficult to code.
    So my question is : Does someone knows another solution to force the use of index ORDER_DHR_VALID that can be simple and reliable.
    Thank you very much for support
    Edited by: remaï on Apr 1, 2009 4:08 PM

    What version of oracle you have? CBO work is different in 9i and 10g.
    Usually cost based optimizer do not want to use index for >< condition with binding variables because optimizer can not use statistic to determine selectivity, and by default selectivity of <> operators is low.
    (As I remember '>' selectivity by default is 5%, you have two conditions > and <, therefore resulting selectivity will be 0.05*0.05=0.0025 as two independent events, but selectivity of other conditions
    ORDER_MVTS.MVT_TYPE = 'DELIVERY' or ORDER.CUSTOMER_CODE = 'ADIDAS' looks much better for CBO)
    The best solution I see is do not use binding variables. Actually your query looks as searching query, which executes not so often, therefore you will not have perfomance win along of skipping execution plan creation.
    Edited by: JustasVred on Apr 1, 2009 10:10 AM

Maybe you are looking for

  • Lightroom 5.4. Edit options are greyed out. I tried reset warnings already.

    Hi, I just added a bigger harddrive and reinstalled Lightroom 5.4. Now,  2 of 3 edit options are greyed out. No access to plug-ins or external editors for original files.(NEF's) I tried reset warnings already.

  • Using PB as a video monitor

    This is a bit of a long shot, but I thought I would try asking anyway! I make films with a small Sony HVR A1E camera. I know that with the special attachment you can attach the PB to a TV screen thus making 2 screens. I would like to use the PB as a

  • Veescope Live on Macbook Pro via Matrox IO?

    Hope you've all been doing well Question: Green Screen and live keying and viewing Camera: Sony A65 Viewing Devices: 2011 Macbook Pro 15 inch (System Unit), Sony Bravia (HDTV) About to do my first green screen movie and wondering what devices would b

  • Free space in UNDO tablespace

    Hi, in DB version 9.2.0, after all transactions are committed, the occupied blocks in UNDO tablespace will be free or not ? The same just after startup, before any transaction the free space in UNDO tablespace would be at max ? Many thanks.

  • Wireless connectivity problems using IOS 6.0.2?

    After installing IOS 6.0.2 on my iPhone 5 I can no longer connect to known wireless sites.  I've been through troubleshooting with both Apple and my ISP and no luck.  I'm thinking there's wireless connectivity problems with this latest update (my iPa