JSP, Data Web Bean, BC4J: Setting the where clause of a View Object at run time

Hi,
I am trying to develop a data web bean in which the where clause of a View Object will be set at run time and the results of the query then displayed.
My BC4J components are located in one project while the coding for the data web bean is in another project. I used the following code bu t it does not work. Could you please let me know what I am doing wrong?
public void populateOSTable(int P_EmpId)
String m_whereString = "EmpView.EMP_ID = " + P_EmpId;
String m_OrderBy = "EmpView.EMP_NAME";
oracle.jbo.ApplicationModule appModule = null;
ViewObject vo = appModule.findApplicationModule("EMPBC.EMPAppModule").findViewObject("EMPBC.EMPView");
vo.setWhereClause(m_whereString);
vo.setOrderByClause(m_OrderBy);
vo.executeQuery();
vo.next();
String empName numAttrs = vo.getAttribute(EmpName);
System.out.println(empName);
Thanks.

<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by JDev Team (Laura):
Here is how I have usually done mine:
1. In the JSP, use a RowsetNavigator bean to set the where clause and execute the query.
2. Use a custom web bean to process the results of the query (print to HTML).
for example:
<jsp:useBean class="oracle.jbo.html.databeans.RowsetNavigator" id="rsn" scope="request" >
<%
// get the parameter from the find form
String p = request.getParameter("p");
String s = request.getParameter("s");
// store the information for reference later
session.putValue("p", p);
session.putValue("s", s);
// initialize the app module and view object
rsn.initialize(application,session, request,response,out,"wt_bc_WT_bcModule.wtjoinView");
// set the where clause string
String theclause = "presname = '" + p + "' AND slideno=" + s;
// set the where clause for the VO
rsn.getRowSet().getViewObject().setWhereClause(theclause);
rsn.getRowSet().getViewObject().executeQuery();
rsn.getRowSet().first();
%>
</jsp:useBean>
<jsp:useBean class="wt_bc.walkthruBean" id="wtb" scope="request" >
<%
// initialize the app module and VO
wtb.initialize(application,session, request,response,out,"wt_bc_WT_bcModule.wtjoinView");
wtb.render();
%>
In this case, the render method of my custom web bean mostly gets some session variables, and prints various content depending on the session variable values.
Hope this helps.
</jsp:useBean><HR></BLOCKQUOTE>
Laura can you give the code of your walkthru bean? i wna't to initialize a viewobject, set the where clause and give that viewobject back to initialize my navigatorbar.
Nathalie
null

Similar Messages

  • JSP, DataWebBean: How to dynamically set the where clause of query and display record

    Hi,
    I am reposting this question as per suggestions made by Mr. Dwight.
    I have used ViewCurrentRecord web bean to display records from EMP table. I have to use the Dept_Id_FK from the current
    record of the EMP table to display corresponding records of Dept table. I have a view object called DeptView in my Business
    Components which selects all the records from the Dept table.
    How do I get the value of Dept_Id_FK and use it to display the required records of the Dept table?
    I tried to declare a variable and get the value of Dept_Id_FK but it did not work. My code is as follows:
    <%! String m_DeptId = null; %>
    <jsp:useBean id="RowViewer" class="oracle.jbo.html.databeans.ViewCurrentRecord" scope="request">
    <%
    RowViewer.initialize(pageContext, "EMPApp_EMP_EMPAppModule.EMPView1");
    RowViewer.setReleaseApplicationResources(false);
    RowViewer.getRowSet().next();
    m_DeptId = (String)RowViewer.getRowSet().getCurrentRow().getAttribute("DeptIdFk");
    %>
    </jsp:useBean>
    Thanks.
    null

    First of all, Thank you very much for making use of the new topic format. It is very much appreciated.
    As for your question, I think there are several different ways to accomplish what I think you want to do.
    1. Create a view object that includes both Emp and Dept entities and join them there. In this case, your query would look something like this:
    Select e.empno,e.name,...,d.dname,d.loc from emp e, dept d
    where e.deptno = d.deptno
    You should be able to create a JSP off of this view object that contains both the employee and department information. In this case, BC4J takes care of the foreign key to primary key coordination.
    2. In order to set a dynamic where clause for a view, you need to do the following in your usebean tag:
    rsn.initialize(application,session, request,response,out,"DeptView");
    rsn.getRowSet().getViewObject().setWhereClause("deptno=" &#0124; &#0124; m_DeptId);
    rsn.getRowSet().getViewObject().executeQuery();
    rsn.getRowSet().first();
    You will need to do this in a separate usebean tag from the EmpView, since the usebean can only initialize one view object.
    In other words, you would have your ViewCurrentRecord bean tag for the EmpView, then a separate one for the DeptView where you use the above code to set the where clause to display just the information for the department you want.
    Another option, but one I'm not sure would work as well, is to create a master-detail JSP to do this for you. Usually a master-detail is a one-to-many (one department to many employees). Your request appears to be the reverse, but might still be doable using the same mechanism.
    You set up relationships between views in your BC4J project using View Links. If you used the BC4J project wizard and created default views, some of these links may have been created for you. They are created when BC4J detects a foreign key to primary key relationship in the database.
    You can create your own View Links using the View Link wizard. Select your BC4J project node and choose Create View Link... from the context menu. You will be asked to select a source view (Emp), and a target view (Dept), then select the attribute in each view that related the two of them (deptno).
    Next, you need to reflect this new relationship setting in your application module. Select your app module and choose Edit from the context menu. On the data model page, select the EmpView node in the Selected list. Now select the DeptView node in the available list and shuttle it over. You should see DeptView1 via yourlink appear indented under the EmpView node. Save and rebuild your BC4J project to reflect the changes.
    In your JSP project, you can now have the wizard create a master-detail form for you based on DeptView1.
    Let me know if the above answers your question, or if I have misunderstood what it is you wanted to do.
    null

  • Not able to set the where clause params

    Hi,
    My version of apps is 12.1.3.
    I created a page with a searchRN and resultRN (LinesVO). (Not a query/view link) . I am passing the id from header to the VO to restrict the linesVO
    The controller correctly passes the id from searchRN to AM, but in AM, the where clause is not set and I am not getting the desired result:
    My AM Code:
        public void InvokeGo(String Hdrval)
                    LineVOImpl LineVO1 = getLineVO1();
                    LineVO1.setWhereClauseParams(null); // Always reset
                     System.out.println("AMIMPL:Hdrval = "+ Hdrval);
                    <prints the header_Value which is passed from CO>
                       if (Hdrval           == null        
                                            System.out.println("Inside Null If");  
                                            String message = "Please provide atleast one input to any of these search field";
                                            throw new OAException(message, OAException.ERROR);
                                    else   
                                        System.out.println("Not All Parameters are Null.Building Where Clause");
                                         < prints the line above>
                                        LineVO1.setWhereClause
                                        ("Header_name = :1");
                        System.out.println("Paremeter Set are: Header_name:"+Hdrval);
                        <prints the above line like :   Paremeter Set are: Header_name:Hdr_Name_1
                        LineVO1.setWhereClauseParam(0,Hdrval);
                        System.out.println("Inside MainAM invokeGO Method:"+LineVO1.getQuery());
                        < prints:Inside MainAM invokeGO Method:SELECT * FROM (select LINE_ID,hdr.HEADER_ID,LINE_NUMBER,LINE_NAME,Attach,hdr.header_name from xxtr_hdr hdr, xxtr_line line
    where hdr.header_id=line.header_id) QRSLT  WHERE (Header_name = :1)>
                        LineVO1.executeQuery();
    The issue is in the SQL build. I guess after setting the where clause, it should appear like :
    QRSLT  WHERE (Header_name = "Hdr_Name_1"
    Thanks

    Hu Sumit,
    I am doing that:
    LineVO1.setWhereClauseParam(0,Hdrval);
    before executequery. I even hard coded
    LineVO1.setWhereClauseParam(0,"XXXX");
    but still it din't work. I guess I am missing something small. because I have done this thing a lot of times earlier and it had worked.

  • Using a Custom Method to Set the Bind Parameters in a View Object

    Hi all:
    i tried to follow the tutorial in oracle jdeveloper 10.1.2 documentation about creating a simple search page but i'm receiving this error when i tried to test the application module after i added a where clause to my view object(i.e where dept_id= :1) and define a custom method to bind variables in the appmodule class
    i keep getting this error
    JBO-27122: SQL error during statement preparation. Statement: SELECT Employees.EMPLOYEE_ID, Employees.FIRST_NAME, Employees.LAST_NAME, Employees.SALARY, Employees.DEPARTMENT_ID Employees.DEPARTMENT_ID = :1
    ????? IN ?? OUT ????? ?? ??????:: 1
    when i used the setwhere metohd it works
    i'll apprciate ur answer
    regards

    I have the same problem:
    Just like in Toystore Demo I am calling the following method in my VO:
       * Find an account by username and password, leaving the account
       * as the current row in the rowset if found. BUT EVEN IF WE FIND ACCOUNT BY
       * USERNAME AND PASSWORD, IT WILL RETURN FALSE IF THE ACCOUNT IS DISABLED!!!!
       * @param username the username
       * @param password the user's password
       * @return whether the user account exists or not
      public boolean findAccountByUsernamePassword(String username, String password) {
         * We're expecting either zero or 1 row here, so indicate that
         * by setting the max fetch size to 1.
        setMaxFetchSize(1);
        setWhereClause("staff_id = :0 and passw = :1");
        setWhereClauseParam(0, username);
        setWhereClauseParam(1, password);
        executeQuery();
        RowSet rs = this.getRowSet();
        String userEnabled = new String("N");  // Default setting
        if (rs != null){
          int currentSlot = rs.getCurrentRowSlot();
          Row r = rs.getCurrentRow();
          if (r == null){
             r=rs.first();
             currentSlot = rs.getCurrentRowSlot();
          //check if we found the user
          if (currentSlot == SLOT_VALID){
            Object[] av = r.getAttributeValues();
            LoginUtils.userLoggedIn    = av[0].toString();  // '0' is username
            LoginUtils.userFirstName   = av[1].toString();  // '1' is user first name
            LoginUtils.userAccessLevel = av[6].toString();  // '6' is user level
            LoginUtils.userEnabled     = av[7].toString();  // '7' is user level
            userEnabled = av[7].toString();
        boolean found = (first() != null) & userEnabled.equals("Y");
        setWhereClause(null);
        setWhereClauseParams(null);
        setMaxFetchSize(0);
        return found;
      }It gives the same exception...
    JBO-27122: SQL error during statement preparation. Statement: SELECT Staff.STAFF_ID, Staff.FIRST_NAME, Staff.MIDDLE_NAME, Staff.LAST_NAME, Staff.POSITION, Staff.PASSW, Staff.USER_LEVEL, Staff.ENABLED, Staff.PHONE, Staff.EMAIL FROM STAFF Staff WHERE (Staff.STAFF_ID = :0 and Staff.PASSW = :1)
    This worked in 10.0.1.2 but now it does not work in 10.0.1.3!!!

  • How to set the where clause of a value set on the basis of a form field

    I am using a DFF(Descriptive FlexField), which needs to display the value of a certain column(say columnA) on the basis of the value of another column(say columnB).
    So i have created a value set which points to the table which has both these columns, and the DFF uses this value set. However, the problem is that I have not put any where clause in the value set, because of which i cannot handle the exact fetch returns more than one rows error.
    The query has to be as follows:
    select ColumnA from tbl where ColumnB = [ a form value ];
    What I want to know is how can i get the value of a certain field of a certain block of the form in the above query.
    Edited by: 981615 on Jan 14, 2013 12:48 AM
    Edited by: 981615 on Jan 14, 2013 12:48 AM

    Just have a look over these two statements if it solves your problem
    one time where clause
    Set_Block_Property('BLOCK_NAME',ONETIME_WHERE,your form item);
    dynamic where clause
    set_block_property('BLOCK_NAME'default_where, your form itme)
    you can where clause at run time from any procedure or some triggers

  • How do you set the size / bounds of a waveform chart at run time?

    I have a plot area that I would like to fill with as many waveform charts as the user specifies (at run time). The "bounds" property is read only and I haven't noticed an additional "size" property for a waveform chart as there is for a button. Is there a way to set the size of a waveform chart at run time, and if not, why not? (Labview 6.1)

    Look at it a little more carefully, I suspect that your assumption is only half wrong. The property does only resize the plot area--LV resizes the frame to fit the resized plot on it's own.
    You'll need to bear this in mind when you're figuring-out what size to set the property to.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Cursor did not return data if using variables in the where clause

    ENV: report builder 9.0.4.3.0, DB 10g, OS XP
    table and data ctvctyp:
    ctvctyp_code    ctvctyp_code_pred
       CO               Z1
       FE                   Z1
    FUNCTION get_case_type(case_type VARCHAR2) RETURN VARCHAR2 IS
      cursor  type_cur is
        select ctvctyp_code
        from ctvctyp
        where ctvctyp_code_pred = :P_case_type; -- if use 'Z1', it will return 'CO','FE'
                                                -- but if 'Z1' is passed in as case_type, it returns null.
      temp_type     VARCHAR2(4);
      return_type   VARCHAR2(200);
      counter       NUMBER;
    BEGIN
         return_type := '';
         counter := 0;
         srw.message(20,'in case_type is '||case_type);
         open type_cur;
         LOOP
              FETCH type_cur INTO temp_type;
              EXIT WHEN type_cur%NOTFOUND;
              counter := counter+1;
              if temp_type is NULL then
                   srw.message(20,'temp type is null');
              else
                srw.message(20,temp_type);
              end if;
              if counter = 1 then
                   return_type := ''''||temp_type||'''';
              else
                   return_type := return_type||','''||temp_type||'''';
              end if;     
         END LOOP;
         return return_type;
    END;
    In my p_casetype validation trigger:
    function P_CaseTypeValidTrigger return boolean is
         tempCaseType   VARCHAR2(200);
         return_type    VARCHAR2(200);
    begin
        :P_CASETYPE := 'Z1'
        return_type := get_case_type;   --- I got null returned.
      return (TRUE);
    end;
    But in sqlplus:
    declare a bind variable :P_casetype := 'Z1';
    select get_case_type from dual;
    returns:   'FE','MI'

    cursor type_cur is
    select ctvctyp_code
    from ctvctyp
    where ctvctyp_code_pred = _{color:#0000ff}*:P_case_type;*_{color}Shouldn't be this :p_casetype instead of :p_case_type?

  • Dynamically set ViewObject where clause dynamically from Java bean

    I have a requirement to display all of the records from a table when the JSP is first brought up, so my View Object looks like this:
    "select emp_name from emp"
    Then the users wants to ability to pass paramters to that View Object to refine the list so from by Java class I tried to do this:
    ViewObject vo = cpd.findViewObject("EmpViewObject");
    vo.setWhereClause("empName = :1");
    vo.setWhereClauseParam(1,varEmpName);
    vo.executeQuery();
    But I am getting JBO errors and I'm not sure what I'm doing wrong. Can anyone offer a hint as to how I can do this?

    this is exactly how the code is done -
    1. emp_name in the View Object
    2. emp_name in the where clause
    The two are identical. I have tried many variations of this - any time I set the where clause from my bean I get an error.
    When I take the SQL stmnt and run it in TOAD it returns expected rows when I run it in the SQL worksheet in JDev it gives an invalid Identifier - but if I hard code the where clause in the View Object it returns the same results as TOAD.

  • How to set dynamic where clause in ADF?

    Hi,
    I have a View object called BillInfoVO. This has
    all the information about who created the request, the time , status etc.,
    I need to display this VO in a jsp. But before I display, i need to fileter this
    VO results with different where clauses according to the role of the user.
    For example, if the role is admin, then
    where clause should be 'status = 'Completed, and created by = 'Current user'
    If the role is requestor, then
    the where clause should be
    sales manager id = 'Current user' and
    Status != Complete etc.,
    Could any one please let me know how I can
    dynamically set the where clause to filter the appropirate
    result row set in the jsp?
    Your help will be greatly appreciated.
    Thanks,
    venki

    You'll create a service method in your AM that will use the setWhereClause method of a viewobject.
    Then you'll expose it as a client method.
    Then you'll drag it from your data-control onto a button in your JSF page that will call your page for the query.
    More about service methods here:
    http://download.oracle.com/docs/html/B25947_01/bcservices003.htm#sm0206
    http://download.oracle.com/docs/html/B25947_01/bcquerying008.htm#sthref286

  • How to set dynamic WHERE clause to VO from backingBean?

    Hi,
    Can any one let me know the best way to add the dynamic WHERE clause in to VO query.
    I have created AM (with AMImpl.java) & VO (with VOImpl.java & VORowImpl.java) in my model project. I suppose to set the WHERE condition at runtime while the user click the search button. I am handling the user button click at UI layer backingBean. From the backing bean I could able to get the objct of the VO and set the where clause by below code.
            ValueExpression valueExp = elFactory.createValueExpression(elContext, "#{bindings.UserSearchVO1Iterator}", Object.class);
            DCIteratorBinding dcIter = (DCIteratorBinding)valueExp.getValue(elContext);
            ViewObject userSearchVO = dcIter.getViewObject();
            userSearchVO.setWhereClause("lower(usr_login) LIKE ':1' and usr_udf_suid like ':2' ");
            userSearchVO.executeQuery();But as I fear this is not the right way to do it. So I am creating the cutom method inside the VOImpl.java and triggring that method by creating one more cutom method in AMImpl.java. But I dont know how to invoke this AM method from backingBean.
    AMImpl method
    public void initDetails()
            UserSearchVOImpl vo = getUserSearchVO1();
            vo.initQuery();
    VOImpl method
        public void initQuery()
            setWhereClause("lower(usr_login) LIKE 'a%' and usr_udf_suid like '%1144%'");
            executeQuery();
        }Can any one guide me which is the best way to set the where clause to VO? How to call the AM method from backingBean?
    Thanks
    kln

    i am new to oracle 11g i writing a stored procedure in which i have made use of case in where clause to pass my parameter value v_toStoreID
    i have googled a lot regarding that i found that to use case in where clause it should be like this
    where
    case  column_value
    when 0
    then value1
    else
    value2
    end
    this my query
    SELECT ITMID as ItemId,
    NVL(OrderDtl.PackageID, 0) PackageId,
    OrderDtl.OrdDtlID,
    (CASE NVL(OrderDtl.PackageID, 0)
    WHEN 0
    THEN 1
    ELSE 0
    END) as PackageFlag,
    ivitem.Code ItemCode,
    ivitem.ITMNAME AS itemName,
    IvPatientIssueMst.IssueNo Issue_No,
    to_char(Issuedate, 'DD/MM/YYYY') IssueDate,
    OrderDtl.OrdQty,
    NVL(OrderDtl.AllocationID, 0) Package,
    OrderDtl.ServiceAmount MRP
    FROM IvPatientIssueMst
    JOIN OrderMst
    ON IvPatientIssueMst.OrderId = OrderMst.OrdId
    JOIN OrderDtl
    ON OrderDtl.OrdID = OrderMst.OrdId
    JOIN ivitem
    ON ivitem.ITMID = OrderDtl.DrugId
    LEFT JOIN IVPatientIndentMst
    ON IVPatientIndentMst.IndentID = IvPatientIssueMst.IndentId
    WHERE OrderMst.OrdVisitID = 395899
    AND
    *(CASE IvPatientIssueMst.StoreId*
    when NVL(IvPatientIssueMst.StoreId, 0)=0
    THEN v_toStoreID
    ELSE  IVPatientIndentMst.ToStoreID
    END)
    ORDER BY ivitem.ITMNAME;
    it is not working please someone help

  • Bc4j-deployment When Deploying data web bean

    When I m deploying bc4j components which are using data web bean
    it is giving error in the function webbean.doStartTag()
    all other jsp files are running fine which are not using any
    data web bean.
    I 'll apreciate any answer to this query.
    regards
    anant

    Hi Anant,
    dostartBean can encounter a variety of underlying problems ...
    what specific errors messages do you get (e.g., JBO_xxxx), or
    error-behavior ?

  • Using a view-object as a data web bean?

    Hi,
    When writing JSP pages, I'd like to have a web bean that allows basic data manipulation such as:
    - set up a row set - e.g. by specifying a view object and an (optional) where clause;
    - navigate this row set (first, next, etc.);
    - get or set the values of the attributes of the current row;
    - insert, update or delete a row;
    - commit or rollback the modifications;
    - etc.
    This bean should be "silent" - i.e. it would not have to be able to "render" anything - instead, I would use it in <%= bean.method() %> tags, or in <% ...java code... %> sections, in conjunction with other (custom) beans.
    I guess I could use a view object - but:
    1) How would I have to use it in a JSP context?
    2) Or, are there more appropriate objects to do this job?
    3) What methods could I use (i.e. where are they documented)?
    4) What pitfalls should I be aware of (most notably related to housekeeping after bean use)?
    Any information greatly appreciated!
    Thanks in advance,
    Serge

    Hi,
    When writing JSP pages, I'd like to have a web bean that allows basic data manipulation such as:
    - set up a row set - e.g. by specifying a view object and an (optional) where clause;
    - navigate this row set (first, next, etc.);
    - get or set the values of the attributes of the current row;
    - insert, update or delete a row;
    - commit or rollback the modifications;
    - etc.
    This bean should be "silent" - i.e. it would not have to be able to "render" anything - instead, I would use it in <%= bean.method() %> tags, or in <% ...java code... %> sections, in conjunction with other (custom) beans.
    I guess I could use a view object - but:
    1) How would I have to use it in a JSP context?
    2) Or, are there more appropriate objects to do this job?
    3) What methods could I use (i.e. where are they documented)?
    4) What pitfalls should I be aware of (most notably related to housekeeping after bean use)?
    Any information greatly appreciated!
    Thanks in advance,
    Serge

  • Data web bean (chart) using a dynamic view object

    Please I want a quick help. I read all forums concerning this subject but I still couldn't do it.
    - I create a view object which takes a proameter using the ? style parameter.
    - I passed the parameter from an html page and execute the query
    of the view as follows:
    <%
    String deptno = request.getParameter("deptno");
    if(deptno != null) {
    oracle.jbo.html.jsp.JSPApplicationRegistry.registerApplicationFromPropertyFile(session , "MyProject21_package3_Package3Module");
    oracle.jbo.ViewObject v = oracle.jbo.html.jsp.JSPApplicationRegistry.getInstance()
    .getAppModuleInstance("MyProject21_package3_Package3Module",request,session)
    .findViewObject("View1");
    v.setWhereClauseParam(0,deptno);
    v.executeQuery();
    %>
    - And then I used the data web bean chart as follows:
    <jsp:useBean class="oracle.jbo.html.databeans.ChartRenderer" id="ch" scope="request" >
    <%
    ch.setReleaseApplicationResources(false);
    ch.initialize(application,session, request,response,out,"MyProject21_package3_Package3Module.View1");
    ch.setCommonScriptName("/webapp/jsp/chart_common.jsp");
    ch.getChart().setGraphType(ch.PIE);
    ch.setSeriesLabelColumnName("DeptNo");
    ch.setDisplayAttributes("CountEmplNo");
    ch.getChart().setPieFeelerTextDisplay(0);
    ch.getChart().setPieTilt(10);
    ch.getChart().setPieRotate(0);
    ch.getChart().setLegendDisplay(true);
    ch.getChart().setLegendMarkerPosition(0);
    ch.getChart().setTitleString("Title");
    ch.getChart().setSubtitleString("Subtitle");
    ch.getChart().setFootnoteString("Footnote");
    ch.setImageWidth(400);
    ch.setImageHeight(400);
    ch.render();
    %>
    - I tried to use the View1 as a view name, and the v as a view name
    but both of them get the same result
    SQL Statement error and the sql statement is displayed with the ? in it which means that he didn't replace it by the parameter.
    Please I need quick help.
    Thanks.
    </jsp:useBean>
    Remark : please send me the reply at "[email protected]"

    Hi Rishab,
    I'm running into the exact same problem, in the same situation. Did you solve this problem and can you tell me how?
    Thanks in advance,
    Paskal

  • Performance with dates in the where clause

    Performance with dates in the where clause
    CREATE TABLE TEST_DATA
    FNUMBER NUMBER,
    FSTRING VARCHAR2(4000 BYTE),
    FDATE DATE
    create index t_indx on test_data(fdata);
    query 1: select count(*) from TEST_DATA where trunc(fdate) = trunc(sysdate);
    query 2: select count(*) from TEST_DATA where fdate between trunc(sysdate) and trunc(SYSDATE) + .99999;
    query 3: select count(*) from TEST_DATA where fdate between to_date('21-APR-10', 'dd-MON-yy') and to_date('21-APR-10 23:59:59', 'DD-MON-YY hh24:mi:ss');
    My questions:
    1) Why isn't the index t_indx used in Execution plan 1?
    2) From the execution plan, I see that query 2 & 3 is better than query 1. I do not see any difference between execution plan 2 & 3. Which one is better?
    3) I read somewhere - "Always check the Access Predicates and Filter Predicates of Explain Plan carefully to determine which columns are contributing to a Range Scan and which columns are merely filtering the returned rows. Be sceptical if the same clause is shown in both."
    Is that true for Execution plan 2 & 3?
    3) Could some one explain what the filter & access predicate mean here?
    Thanks in advance.
    Execution Plan 1:
    SQL> select count(*) from TEST_DATA where trunc(fdate) = trunc(sysdate);
    COUNT(*)
    283
    Execution Plan
    Plan hash value: 1486387033
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 9 | 517 (20)| 00:00:07 |
    | 1 | SORT AGGREGATE | | 1 | 9 | | |
    |* 2 | TABLE ACCESS FULL| TEST_DATA | 341 | 3069 | 517 (20)| 00:00:07 |
    Predicate Information (identified by operation id):
    2 - filter(TRUNC(INTERNAL_FUNCTION("FDATE"))=TRUNC(SYSDATE@!))
    Note
    - dynamic sampling used for this statement
    Statistics
    4 recursive calls
    0 db block gets
    1610 consistent gets
    0 physical reads
    0 redo size
    412 bytes sent via SQL*Net to client
    380 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed
    Execution Plan 2:
    SQL> select count(*) from TEST_DATA where fdate between trunc(sysdate) and trunc(SYSDATE) + .99999;
    COUNT(*)
    283
    Execution Plan
    Plan hash value: 1687886199
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 9 | 3 (0)| 00:00:01 |
    | 1 | SORT AGGREGATE | | 1 | 9 | | |
    |* 2 | FILTER | | | | | |
    |* 3 | INDEX RANGE SCAN| T_INDX | 283 | 2547 | 3 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - filter(TRUNC(SYSDATE@!)<=TRUNC(SYSDATE@!)+.9999884259259259259259
    259259259259259259)
    3 - access("FDATE">=TRUNC(SYSDATE@!) AND
    "FDATE"<=TRUNC(SYSDATE@!)+.999988425925925925925925925925925925925
    9)
    Note
    - dynamic sampling used for this statement
    Statistics
    7 recursive calls
    0 db block gets
    76 consistent gets
    0 physical reads
    0 redo size
    412 bytes sent via SQL*Net to client
    380 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows
    Execution Plan 3:
    SQL> select count(*) from TEST_DATA where fdate between to_date('21-APR-10', 'dd-MON-yy') and to_dat
    e('21-APR-10 23:59:59', 'DD-MON-YY hh24:mi:ss');
    COUNT(*)
    283
    Execution Plan
    Plan hash value: 1687886199
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 9 | 3 (0)| 00:00:01 |
    | 1 | SORT AGGREGATE | | 1 | 9 | | |
    |* 2 | FILTER | | | | | |
    |* 3 | INDEX RANGE SCAN| T_INDX | 283 | 2547 | 3 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - filter(TO_DATE('21-APR-10','dd-MON-yy')<=TO_DATE('21-APR-10
    23:59:59','DD-MON-YY hh24:mi:ss'))
    3 - access("FDATE">=TO_DATE('21-APR-10','dd-MON-yy') AND
    "FDATE"<=TO_DATE('21-APR-10 23:59:59','DD-MON-YY hh24:mi:ss'))
    Note
    - dynamic sampling used for this statement
    Statistics
    7 recursive calls
    0 db block gets
    76 consistent gets
    0 physical reads
    0 redo size
    412 bytes sent via SQL*Net to client
    380 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed

    Hi,
    user10541890 wrote:
    Performance with dates in the where clause
    CREATE TABLE TEST_DATA
    FNUMBER NUMBER,
    FSTRING VARCHAR2(4000 BYTE),
    FDATE DATE
    create index t_indx on test_data(fdata);Did you mean fdat<b>e</b> (ending in e)?
    Be careful; post the code you're actually running.
    query 1: select count(*) from TEST_DATA where trunc(fdate) = trunc(sysdate);
    query 2: select count(*) from TEST_DATA where fdate between trunc(sysdate) and trunc(SYSDATE) + .99999;
    query 3: select count(*) from TEST_DATA where fdate between to_date('21-APR-10', 'dd-MON-yy') and to_date('21-APR-10 23:59:59', 'DD-MON-YY hh24:mi:ss');
    My questions:
    1) Why isn't the index t_indx used in Execution plan 1?To use an index, the indexed column must stand alone as one of the operands. If you had a function-based index on TRUNC (fdate), then it might be used in Query 1, because the left operand of = is TRUNC (fdate).
    2) From the execution plan, I see that query 2 & 3 is better than query 1. I do not see any difference between execution plan 2 & 3. Which one is better?That depends on what you mean by "better".
    If "better" means faster, you've already shown that one is about as good as the other.
    Queries 2 and 3 are doing different things. Assuming the table stays the same, Query 2 may give different results every day, but the results of Query 3 will never change.
    For clarity, I prefer:
    WHERE     fdate >= TRUNC (SYSDATE)
    AND     fdate <  TRUNC (SYSDATE) + 1(or replace SYSDATE with a TO_DATE expression, depending on the requirements).
    3) I read somewhere - "Always check the Access Predicates and Filter Predicates of Explain Plan carefully to determine which columns are contributing to a Range Scan and which columns are merely filtering the returned rows. Be sceptical if the same clause is shown in both."
    Is that true for Execution plan 2 & 3?
    3) Could some one explain what the filter & access predicate mean here?Sorry, I can't.

  • Can I use SYSDATE in the WHERE clause to limit the date range of a query

    Hi,
    Basicaly the subject title(Can I use SYSDATE in the WHERE clause to limit the date range of a query) is my question.
    Is this possible and if it is how can I use it. Do I need to join the table to DUAL?
    Thanks in advance.
    Stelios

    As previous poster said, no data is null value, no value. If you want something, you have nvl function to replace null value by an other more significative value in your query.<br>
    <br>
    Nicolas.

Maybe you are looking for

  • Error while running a job in Data services

    We are using Data services BO XI R3 tool. We have created datastore for Oracle database  8i using Microsoft ODBC DSN. This is the source datastore. When job is to pull the data from source to 10g target, we get the below error in log file: 25219     

  • Setting up your system

    Hey guys, Been using Premiere Pro CS5 since it came out but I've run into a problem.  I purchased a Sony HVR-A1U and I'm trying to capture footage by connecting DV/HDV to 9-pin firewire and I also have a G-RAID Drive that has 9 to 9-pin firewire runn

  • I need to delete an account that i accidently created... how can i do so?

    I need to delete an account that i accidently created... how can i do so?

  • Latest updates delete System/Library/StartupItems folder

    One of the following updates delete the System/Library/StartupItems folder: Migration Assistant Update for Mac OS X Snow LEopard 1.0 Remote Desktop Client Update 3.5.1 Safari 5.1 Thunderbolt Firmware Update 1.0 iTunes 10.4 iWork Update 6 9.1 This is

  • Linux 6.4 fails to install "Oracle Linux NTFS how-to"

    HI a total linux newbie here. I am running the latest x86_64 oracle linux Red Hat Enterprise Linux Server release 6.4 (Santiago) I have followed the instructions at : Oracle Linux NTFS how-to I manage to do : wget http://pkgs.repoforge.org/rpmforge-r