Where clause and Dates

I am creating a coditional query for one of my data blocks.
What I need to do is build a where clause on the fly and pass
that back to my block using the Set_BLock_Property built in. I
am able to do this but I am having problems with the fact that I
don't know how to correctly pass a date back. It seems when
specifying a date in a where clause it needs to have single
quotes around this. But when ever I try to embed the quotes in
the string I am not successful. I have even tried appending the
quotes using the chr function doing something like.
Where_Clause := 'Birthday <= '

Spencer,
I think chr(39) will give you the correct character. For example,
Where_Clause := 'Birthday <= '

Similar Messages

  • Where clause and order by to DAO classes

    Hi
    Is it ok(I mean design wise) to pass the 'where clause' conditions and order by clause as a parameter to the method of DAO class?

    Well, I would suggest you write seperate methods in your dao , one to select data without the where clause and one to select data with the where clause thrown in. If you have different 'where' clauses for selecting different kinds of data, have that many dao methods. The dao methods being specific know exactly what is the data that's coming in.
    Lets assume you have a list of purchase orders and each purchase order is indetified by a unique id called PURCHASE_ORDER_ID.
    1. The following code would populate a purchase order's details given an id.
    private statis final String QUERY_1 = "select * from PURCHASE_ORDERS where PURCHASE_ORDER_ID = ? ";
    PurchaseOrderModel getPurchaseOrderData(long poId){
         //get a prepared statement from your connection
         PreparedStatement pst = conn.prepareStatement(QUERY_1);
         //set the poId passed as params to your query
         pst.setLong(1, poId);
         ResultSet rs = pst.executeQuery();
         if(rs.next()){
              //populate data into a model          
         finally{
              //clean up resources
         return model;    
    }2. The following code would return a list of PurchaseOrderModel's whose shipping date falls between a set of dates selected by the user.
    private statis final String QUERY_2 = "select * from PURCHASE_ORDERS where SHIPPING_DATE between ? and ? ";
    PurchaseOrderModel getPurchaseOrdersBetweenDates(list bindValues){
         //get a prepared statement from your connection
         PreparedStatement pst = conn.prepareStatement(QUERY_1);
         //set the dates passed as params to your query
         //we know that the List ought to contain only 2 dates
         pst.setDate(1, (Date)bindValues.get(0));
         pst.setDate(2, (Date)bindValues.get(1));
         ResultSet rs = pst.executeQuery();
         if(rs.next()){
              //iterate and populate data into a model          
              //add model to a list
         finally{
              //clean up resources
         return list;    
         3. This is more interesting - the dao method searches a list of Purchase Orders starting with a set of specific words. The words themselves may be one or many. This means that the number of '?' in your prepared statement may be dynamic. Each element of the list is a String that contains the start substring of a purcahse order name. For example - the list may contain elements like ["a", "ab", "c", "gh"] and the dao method returns all purchase order starting with these names.
    private statis final String QUERY_3 = "select * from PURCHASE_ORDERS where ";
    PurchaseOrderModel getPurchaseOrderNameMatches(list bindValues){
         //construct the query dynamically
         StringBuffer query = new StringBuffer(QUERY_3);
         int count = 0;
         for(Iterator itr = bindValues.iterator(); itr.hasNext();;){
              String value = (String)itr.next();
              query.append ("name like 'value%' ");
              if (count != 0 and (count+1 != bindValues.length)){
                   query.append(" or ");
              count ++;          
         //get a prepared statement from your connection
         PreparedStatement pst = conn.prepareStatement(query.toString());     
         ResultSet rs = pst.executeQuery();
         if(rs.next()){
              //iterate and populate data into a model          
              //add model to a list
         finally{
              //clean up resources
         return list;    
    To sum up,
    1. You need as many methods as you have different kinds of searches (one method for each kind of 'where' clause).
    2. The ejb/business layer would examine the data and decide on which method to call.
    3. Increases coding effort, but makes the code clean and readable. Each layer does it's job. Thus we dont have ejbs forming 'where' clauses and so on.
    Having said that, it really is your decision - you should take into consideration the following factors -
    1. How big is the project ? If its a huge codebase developed by many people, then segregate the responsibilities clearly in each layer as I have outlined. For a small scale project, you could go with your approach.
    2. Whats the take on maintenance and future add-ons ? Do you see the codebase growing with time ?
    3. Is your project a commercial one - is it a product that needs to be maintained or is it a one-off development - develop once and you are done with it.
    4. What are the design considerations ? Is somebody going to audit code for quality ? Or is it a academic one ?
    You should take into account all these before deciding to go one way or the other.
    A general thumb rule should be that you should be convinced that your code readable (maintainable), scalable and efficient. Anything that you do towards these ends is good code/design despite what people/books/patterns say, IMO.
    cheers,
    ram.

  • Mutilple Filter Objects - Changing where clause and or

    Is it possible to have a query as below using filter commands.
    (obj1 = 'value11' and obj2 = 'value21')
    or
    (obj1 = 'value12' and obj2 = 'value22')
    or
    The objective is to manipulate the where clause and , or .
    Thanks in Advance
    Bhanu Mohanty

    Hi Bhanu,
    to reach what you want it's necessary to build a virtual characteristic.
    The new characteristic will be populated via coding during runtime of your query. Another possibility (as mentioned before in this forum by Siegfried Szameitat) is to create a new characteristic in your cube that contains field1 and field2 concatenated. With the first scenario, you don’t need a reloading of your cube, with second one this is necessary.
    Hope this helps.
    Bye,
    Roberto

  • Where clause and using dates

    Hi all,
    How to use the where clause to select records based on condition,,,,, and this condition is based on a date,, for example:
    select items from inventory_items
    where purchasing_date in :from_date and :to_date;
    Thank you very much
    Tasneem

    Tasneem wrote:
    Hi all,
    How to use the where clause to select records based on condition,,,,, and this condition is based on a date,, for example:
    select items from inventory_items
    where purchasing_date in :from_date and :to_date;
    Thank you very much
    Tasneemtry this..
    select items from inventory_items
    where purchasing_date between :from_date and :to_date;
    If someone's response is helpful or correct, please mark helpful or correct.

  • LTS content WHERE clause and fitlers screwing up returned data

    Hi all,
    I'm connecting against Essbase 9.3.1 cubes with 10.1.3.4 and just stumbled upon an error. In some of the dimensions coming from Essbase there are undesired members, which I wanted to filter out the usual way. I.e. by adding where clauses to the LTS:
    "Cube#1"."SALES".."SALES"."Gen4,Market" <> 'Dummy'
    Now before doing this, everything runs fine with one report yielding this:
    Gen3,Product Range
    A 6.4
    B 4
    C 7.2
    After adding:
    Gen3,Product Range
    A 35
    B 110
    C 42
    These numbers don't make any sense. Funny thing is, that the request doesn't even display the Market dimension.
    So I thought "well let's put it on the reports then". So I created saved filters (since there's also one on products)...Same result.
    It actually appends this to the MDX
    *set [Market4] as 'Filter(Generate({[Market3]}, Descendants([Market].currentmember, [Market].Generations(4),SELF), ALL), ( NOT ([Market].currentmember.MEMBER_ALIAS = "Corporate Sub-Region" OR [Market].currentmember.MEMBER_Name = "Corporate Sub-Region")) AND ( NOT ([Market].currentmember.MEMBER_ALIAS = "European Region SRgn" OR [Market].currentmember.MEMBER_Name = "European Region SRgn")))'*
    The thing is: if I only use market dimension levels and filtering there I'm fine. Likewise, if I only use product dimension levels and filter on products there's no issue.
    Any idea how I can filter this without getting errors?
    Here's the two full statements
    WORKS:
    With
    set [Data Type2] as 'Filter([Data Type].Generations(2).members, ([Data Type].currentmember.MEMBER_ALIAS = "Units" OR [Data Type].currentmember.MEMBER_Name = "Units"))'
    set [Market3] as 'Filter([Market].Generations(3).members, ([Market].currentmember.MEMBER_ALIAS = "Europe" OR [Market].currentmember.MEMBER_Name = "Europe"))'
    set [Product2] as 'Filter([Product].Generations(2).members, ([Product].currentmember.MEMBER_ALIAS = "SMU" OR [Product].currentmember.MEMBER_Name = "SMU"))'
    set [Product3] as 'Generate([Product2], Descendants([Product].currentmember, [Product].Generations(3), leaves))'
    set [Time Period2] as 'Filter([Time Period].Generations(2).members, ([Time Period].currentmember.MEMBER_ALIAS = "FY-09" OR [Time Period].currentmember.MEMBER_Name = "FY-09"))'
    set [Time Period3] as 'Generate({[Time Period2]}, Descendants([Time Period].currentmember, [Time Period].Generations(3),SELF), ALL)'
    set [View Type2] as 'Filter([View Type].Generations(2).members, ([View Type].currentmember.MEMBER_ALIAS = "Default" OR [View Type].currentmember.MEMBER_Name = "Default"))'
    member [Account].[MS1] as 'AGGREGATE(crossjoin ({[Data Type2]},crossjoin ({[Market3]},{[View Type2]})),Account.[WoH Last 13Wks])', SOLVE_ORDER = 100
    member [Account].[MS2] as 'AGGREGATE(crossjoin ({[Data Type2]},crossjoin ({[Market3]},{[View Type2]})),Account.[WoH Last 4Wks])', SOLVE_ORDER = 100
    select
    { [Account].[MS1],
    [Account].[MS2]
    } on columns,
    NON EMPTY {crossjoin ({[Product3]},{[Time Period3]})} properties ANCESTOR_NAMES, GEN_NUMBER on rows
    from [SALES.SALES]
    DOESNT WORK:
    With
    set [Data Type2] as 'Filter([Data Type].Generations(2).members, ([Data Type].currentmember.MEMBER_ALIAS = "Units" OR [Data Type].currentmember.MEMBER_Name = "Units"))'
    set [Market3] as 'Filter([Market].Generations(3).members, ([Market].currentmember.MEMBER_ALIAS = "Europe" OR [Market].currentmember.MEMBER_Name = "Europe"))'
    set [Market4] as 'Filter(Generate({[Market3]}, Descendants([Market].currentmember, [Market].Generations(4),SELF), ALL), ( NOT ([Market].currentmember.MEMBER_ALIAS = "Corporate Sub-Region" OR [Market].currentmember.MEMBER_Name = "Corporate Sub-Region")) AND ( NOT ([Market].currentmember.MEMBER_ALIAS = "European Region SRgn" OR [Market].currentmember.MEMBER_Name = "European Region SRgn")))'
    set [Product2] as 'Filter([Product].Generations(2).members, ([Product].currentmember.MEMBER_ALIAS = "SMU" OR [Product].currentmember.MEMBER_Name = "SMU"))'
    set [Product3] as 'Generate([Product2], Descendants([Product].currentmember, [Product].Generations(3), leaves))'
    set [Time Period2] as 'Filter([Time Period].Generations(2).members, ([Time Period].currentmember.MEMBER_ALIAS = "FY-09" OR [Time Period].currentmember.MEMBER_Name = "FY-09"))'
    set [Time Period3] as 'Generate({[Time Period2]}, Descendants([Time Period].currentmember, [Time Period].Generations(3),SELF), ALL)'
    set [View Type2] as 'Filter([View Type].Generations(2).members, ([View Type].currentmember.MEMBER_ALIAS = "Default" OR [View Type].currentmember.MEMBER_Name = "Default"))'
    member [Account].[MS1] as 'AGGREGATE(crossjoin ({[Data Type2]},crossjoin ({[Market4]},{[View Type2]})),Account.[WoH Last 13Wks])', SOLVE_ORDER = 100
    member [Account].[MS2] as 'AGGREGATE(crossjoin ({[Data Type2]},crossjoin ({[Market4]},{[View Type2]})),Account.[WoH Last 4Wks])', SOLVE_ORDER = 100
    select
    { [Account].[MS1],
    [Account].[MS2]
    } on columns,
    NON EMPTY {crossjoin ({[Product3]},{[Time Period3]})} properties ANCESTOR_NAMES, GEN_NUMBER on rows
    from [SALES.SALES]

    NLS is UTF8 btw.

  • How to use a lexical variable in a WHERE clause and as a function argument.

    Hello,
    My report has a lexical variable which has values like 'and id in (1,3,4)'. I want to use this variable in two separate queries. In the first, it is used in the WHERE clause, something like:
    .. where date is not null &var;
    In the second query, the variable is used in a function call, something like:
    select * from table (my_function(&var));
    The trouble is that the first query works when the value of the variable is unquoted, but for the second query the value should be quoted.
    Does anyone have an idea how I could solve this problem?
    Thanks in advance,
    Frans
    Message was edited by:
    fransie

    http://tkyte.blogspot.com/2006/06/varying-in-lists.html
    Presents many options.

  • Where clause in Data Block

    I'm running Forms 6i client/server.
    I have defined a where clause in the Property Palette for a Data Block.
    What I like to do is to extend the where clause with a subquery, but
    how can this be done? I mean, should I put the code in a trigger, which trigger?
    Regards
    Roar

    simple where clause with sub_query
    My block has name is dc_gmod. In the where pallete I put the text (and the all is work good!!!):
    exists
    select 1 from ttt.xxxxx_table v
    where (dc_gmod.cd_gmod = v.cd_gmod)
    and
    (instr(:fst.tmp_nm,cd_place,1) > 0
    or
    cd_place IN
    (select U_UNIT from ttt.xxxxxxxxx_tabe
    where RG_U = :QA.RG_UNIT_RUN
    AND SID = :QA.SID
    AND SERIAL# = :QA.SERIAL
    1.The dc_gmod.cd_gmod - is full name my block_name and item_name.
    2. The ttt.xxxxx_table is full name of my table what is source for block dc_gmod
    3. The cd_place is ITEM of BLOCK dc_gmod

  • ADF/UIX where clause and VO on different pages

    Hi,
    i have a VO called Periods which contains Periods and their statuses. On one page for entering data i use the periods VO in LOV mode with a where clause limiting the user to selecting periods with open status.
    I have another page which is for maintaining the period statuses. The problem is that when i move between entry and setup pages the where clause takes affect in both pages ie. the maintain periods page only shows periods with status Open!!
    To get around this on the maintain periods prepare model i tried doing this:
    actionContext.getBindingContainer().getApplicationModule().findViewObject("PeriodsView1").setWhereClause(null);
    actionContext.getBindingContainer().getApplicationModule().findViewObject("PeriodsView1").executeQuery();this works, however it causes bizarre behaviour on some records when i change values in the UIX editable table. The UIX editable table works fine if i remove the above code snippet (and dont go to the page that sets the where clause on the view object). The behaviour is that i cant select some rows in the UIX table properly and the updated values arent effected.
    can someone advise pn the proper way of doing this?

    Brenden, instead of setting the where clause to null, try setting it to an empty string (eg. "") or something dumb like "1=1".
    In turn place JDeveloper into debug mode by selecting your project properties, profiles, development, runner, and changing the java options to: -Djbo.debugoutput=console
    With this option turned on, you'll see your actual SQL going to the database with your where clause. You should be able to see the where clause of your underlying query that you just set, and if you use something dumb like 1=1 you'll note the setWhereClause module is working.
    Hope this helps.
    Cheers,
    CM.

  • Correct way to do "where " clause on date type column

    Hi,
    I am using a following query in Oracle 10.2.0.3 express edition database to retrieve the rows greater than a certain date.
    select from FLOWS_020100.WWV_FLOW_ACTIVITY_LOG1$ where TIME_STAMP > to_date('31-OCT-12');*
    This query returns all the rows including the rows with TIME_STAMP == '31-OCT-12'.
    This TIME_STAMP column is defined as below in this table:
    COLUMN_NAME     DATA_TYPE     DATA_LENGTH     NULLABLE     CONSTRAINT_TYPE      INDEX_TYPE
    TIME_STAMP     DATE      7     N     C     NORMAL
    Table has 420 rows with '31-OCT-12' being the smallest date and '16-NOV-12' being the biggest.
    Is there anything wrong in my above query?
    Why is ">" returning the rows that include primary key where-clause value also?
    Can you please guide what is the correct syntax for this date comparison?
    Thanks for your time and help.
    Best Regards.

    907882 wrote:
    Hi,
    I am using a following query in Oracle 10.2.0.3 express edition database to retrieve the rows greater than a certain date.
    select from FLOWS_020100.WWV_FLOW_ACTIVITY_LOG1$ where TIME_STAMP > to_date('31-OCT-12');*
    This query returns all the rows including the rows with TIME_STAMP == '31-OCT-12'.
    This TIME_STAMP column is defined as below in this table:
    COLUMN_NAME     DATA_TYPE     DATA_LENGTH     NULLABLE     CONSTRAINT_TYPE      INDEX_TYPE
    TIME_STAMP     DATE      7     N     C     NORMAL
    Table has 420 rows with '31-OCT-12' being the smallest date and '16-NOV-12' being the biggest.
    Is there anything wrong in my above query?
    Why is ">" returning the rows that include primary key where-clause value also?
    Can you please guide what is the correct syntax for this date comparison?
    Thanks for your time and help.
    Best Regards.Remember that a date column also contains a time part. Therefore your query would pick up
    rows with a time_stamp of 31-Oct-12 13:40:09, for example. Now that is greater than 31-Oct-12
    (which is really 31-Oct-12 00:00:00), so it is picked up.
    You probably want >= to_date('1-Nov-2012', 'dd-mon-yyyy')
    Note: always use a format mask in a to_date, otherwise if the default format mask changes, your code will break.
    BTW: please mark your threads as answered, if they have been:
    >
    Handle:      907882
    Status Level:      Newbie
    Registered:      Jan 13, 2012
    Total Posts:      9
    Total Questions:      6 (5 unresolved)
    >
    Edited by: Paul Horth on Nov 27, 2012 9:30 AM

  • ADF Struts UIX - how write where clause whith date in ViewObject

    Hello
    I need to write a search form with two date fields and then query a where clause between to_date('date 1') and to_date('date 2').
    the query may be writed in ViewCriteria class or using Application module method like this
    AssureViewImpl assureView=getAssureView1();
    assureView.applyViewCriteria(null);
    assureView.setWhereClause("NUM_ASSU = :1");
    assureView.setWhereClauseParam(0,numAss);
    thanks a lot for your help

    Does the user always specify both start and end dates?

  • 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;

  • Where-clause for date-string

    Hi specialist's,
    i have a simple question about a select, but I think I do not see the forrest becaus of too many trees ...
    I have a table where timestamps are stored in seconds-since-epoch.
    I select a human readble format with this statement:
    select to_char(DATE '1970-01-01' + TRXTIMESTAMP / (24*3600*1000), 'DD-MM-YYYY HH24:MI:SS')  as timestamp from txlog;
    TIMESTAMP
    19-10-2013 09:31:27
    19-10-2013 09:31:27
    19-10-2013 09:31:27
    Now I want to filter i.e. for dates of 19-01.... 
    My first try was this:
    select to_char(DATE '1970-01-01' + TRXTIMESTAMP / (24*3600*1000), 'DD-MM-YYYY HH24:MI:SS')  as timestamp from txlog
      where timestamp like '19-%'
    Result:
    ORA-00904: "TIMESTAMP": invalid identifier
    My next try was this:
    select to_char(DATE '1970-01-01' + TRXTIMESTAMP / (24*3600*1000), 'DD-MM-YYYY HH24:MI:SS')  as timestamp from txlog
    where 1 like '19%'
    Result: 0 rows!
    If I change this to
    ... where 1 like '%'
    I get all rows.
    What is wrong with my selects ???

    Felix_GG wrote:
    Hi specialist's,
    i have a simple question about a select, but I think I do not see the forrest becaus of too many trees ...
    I have a table where timestamps are stored in seconds-since-epoch.
    I select a human readble format with this statement:
    select to_char(DATE '1970-01-01' + TRXTIMESTAMP / (24*3600*1000), 'DD-MM-YYYY HH24:MI:SS')  as timestamp from txlog;
    TIMESTAMP
    19-10-2013 09:31:27
    19-10-2013 09:31:27
    19-10-2013 09:31:27
    Now I want to filter i.e. for dates of 19-01....
    My first try was this:
    select to_char(DATE '1970-01-01' + TRXTIMESTAMP / (24*3600*1000), 'DD-MM-YYYY HH24:MI:SS')  as timestamp from txlog
      where timestamp like '19-%'
    Result:
    ORA-00904: "TIMESTAMP": invalid identifier
    My next try was this:
    select to_char(DATE '1970-01-01' + TRXTIMESTAMP / (24*3600*1000), 'DD-MM-YYYY HH24:MI:SS')  as timestamp from txlog
    where 1 like '19%'
    Result: 0 rows!
    If I change this to
    ... where 1 like '%'
    I get all rows.
    What is wrong with my selects ???
    Firstly, why not store timestamps as timestamps?
    Anyway, Your first select refers to the alias 'timestamp' which is only accessible in an outer query, not from within the where clause.
    Try
    Select * from (
    select to_char(DATE '1970-01-01' + TRXTIMESTAMP / (24*3600*1000), 'DD-MM-YYYY HH24:MI:SS')  as timestamp from txlog
    where timestamp like '19-%';
    But timestamp is not a good choice for an alias, as it is a keyword.
    Your second select is obvious - the number 1 will never be like '19%', but it will work
    in the third select: as 1 is indeed like '%' (anything).

  • Where clause and joins

    HI all,
    If i Have a select statement that needs two different tables
    and a where clause with only 1 join and the rest of conditions dependent on only 1 table such as:
    select .... from table a, table b
    where a.col1 = b.col1
    and b.col2 some condition
    and b.col3 some condition;
    is it better/optima for performancel for me to have the join right at the beginning of the where clause or after table b has been filtered out such as:
    select ... from table a, table b
    where b.col2 some condition
    and b.col3 some condition
    and a.col1 = b.col1

    Hi,
    The order of conditions in a WHERE clause doesn't effect performance; the Cost-Based Optimizer will decide how to perform them.
    The order can make a difference on how easy it is to understand and maintain the code. I find ANSI join syntax far better for this:
    select      ...
    from      table      a
    join     table      b     on     a.col1     = b.col1
    where      b.col2  <some condition>
    and      b.col3  <some condition>
    ;

  • Decode in where claus with date comparasion

    hi
    i m using this query can we compare date in decode function in where claue if yes how
    SELECT PPA.START_DATE,
    PPA.END_DATE
    FROM pa_project_assignments PPA,
    PA_CONTROL_ITEMS PCI
    WHERE DECODE(PPA.START_DATE < PCI.ATTRIBUTE1,PCI.ATTRIBUTE1,PPA.START_DATE) BETWEEN (PCI.ATTRIBUTE1) AND (PCI.DATE_REQUIRED)
    AND PPA.END_DATE BETWEEN (PCI.ATTRIBUTE1) AND( PCI.DATE_REQUIRED)
    AND PPA.PROJECT_ID=PCI.PROJECT_ID

    This works.
    SELECT * FROM emp
    WHERE
    CASE WHEN hiredate < SYSDATE THEN
    hiredate
    ELSE SYSDATE
    END BETWEEN SYSDATE-10000 AND SYSDATEIn your CASE
    SELECT PPA.START_DATE,
    PPA.END_DATE
    FROM pa_project_assignments PPA,
    PA_CONTROL_ITEMS PCI
    WHERE
    case when PPA.START_DATE < PCI.ATTRIBUTE1 then
    PCI.ATTRIBUTE1
    else
    PPA.START_DATE
    end  BETWEEN PCI.ATTRIBUTE1 AND PCI.DATE_REQUIRED
    AND PPA.END_DATE BETWEEN  PCI.ATTRIBUTE1 AND PCI.DATE_REQUIRED
    AND PPA.PROJECT_ID=PCI.PROJECT_IDCheers!!!
    Bhushan

  • WHERE clauses and Merge Join Cartesian?

    For some reason, Siebel is generating queries like this:
                        AND CONCAT (CONCAT (t41828.lvl8anc_postn, '-'),
                                    t41828.lvl8_emp_full_name
                                   ) = 'GEO-SMITH, BILL'
                        AND CONCAT (CONCAT (t41828.lvl6anc_postn, '-'),
                                    t41828.lvl6_emp_full_name
                                   ) = 'GROUP1-DOE, JOHN'and this ends up with 3 merge join cartesian in autotrace and this query takes several hours.
    However, by rewriting just those 2 clauses to:
                        AND (t41828.lvl8anc_postn = 'GEO' and
                                    t41828.lvl8_emp_full_name = 'SMITH, BILL')
                        AND (t41828.lvl6anc_postn = 'GROUP1' and
                                    t41828.lvl6_emp_full_name = 'DOE, JOHN')the merge join cartesians go away, and it runs in 7 seconds.
    However, since Siebel is generating the query, and we are having issues, we decided to add columns for testing that is equivalent to the concatenation of the two columns above. After doing this, and creating indexes on the new columns, it is now back to the merge join cartesian and I cannot get rid of it.
    So:
    1. How can rewriting the WHERE (not adding or deleting anything here, just rewriting it in a different way) clause eliminate the merge join cartesian?
    I'm guessing by understanding that single question, I will be able to come up with a better solution to this.

    Note we made two additional columns:
    CONCAT (CONCAT (t41828.lvl8anc_postn, '-'), t41828.lvl8_emp_full_name) => col1 CONCAT (CONCAT (t41828.lvl6anc_postn, '-'), t41828.lvl6_emp_full_name) => col2
    When I created indexes on col1 and col2 and used them in the query, the cartesians returned, and I cannot figure out why. So, I'm still confused why:
    In the original query:
    1. Using CONCAT, and thus no indexes => cartesian
    2. No CONCAT, and indexes => no cartesian
    With the new columns, col1 and col2:
    1. No CONCAT needed, full table scan or indexes => cartesian

Maybe you are looking for

  • Inbound Delivery Idoc not update PIC and PGI with split batch.

    Dear Experts, Delivery outbound with split batch send to third party Warehouse to PIC and PGI from SAP, then receive the delivery inbound IDOC to update the PIC and PGI in SAP from third party. Basic Idoc DELIVERY03 it's works fine with out split bat

  • Foreign Trade LC sales Doc Credit Block.

    Dear Brothers, We have implemented Foreign Trade in Exports here in our company and some times there are issues of Credit block ,My question is if there is an LC document attached to a particular sales order and the LC is worth 3 million ,The balance

  • Table of Contents Order Question

    I have a table of contents set up in my document with a Section Header and underneath that the page number followed by the page title. Example: ELEPHANT 3  PEANUTS The problem is that on right handed pages it puts the Section Header BELOW the page nu

  • InDesign CS6-HELP in Menu

    At the top of the InDesign screen there is a HELP drop down menu.  When I click on "InDesign Help" or Support Centre I get nothing but a browser screen that says the server cannot be accessed.  I called the help desk and they told me to wait as the s

  • LABVIEW 2009 and lvanlys.dll

    Hi, I'm relatively new to LABVIEW and I'm building an application with LABVIEW 2009.  The application works well on my PC.  However, the application is intended to be ran on another machine.  I then tried two approaches.  First, I copied the executab