Using Date in where clause

Hello all,
I am new to Oracle, currently using 10G + aspvbscript.
I've been trying to query data using date in where clause but nothing seems to work.
The column is in date format.
It gets printed out like this: 5/1/2010 11:21:19 AM
I tried using this query:
SELECT * from table where TRUNC(user_date) > to_date('FEB-01-2010:00:00:00','mm-dd-yyyy:HH24:MI:SS') order by user_date asc.
It does return an output but it returns everything in table and does not take WHERE clause into consideration however, it does sort the date in ascending order.
I've tried getting rid of TRUNC tried to format date in a different way but no such luck.
Please point me to the right direction.
Thanks.

Welcome to the forums!
In cases like this it is helpful if you can provide the following information:
1. Oracle version (SELECT * FROM V$VERSION)
2. Sample data in the form of CREATE / INSERT statements.
3. Expected output
4. Explanation of expected output (A.K.A. "business logic")
5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.
I'll try and take a stab at your request based on the data given. What your query says is that it will return all rows that have a date greater then 2/1/2010 (MM/DD/YYYY). If your query is returning all rows then maybe the possibility exists that all the dates in the table are greater then 2/1/2010. Have you checked all dates to see if this is the case?
Also, one note about your TO_DATE() function.to_date('FEB-01-2010:00:00:00','mm-dd-yyyy:HH24:MI:SS')The date format does not match the string you are using with respect to month. Your string has 'FEB' but the format is 'MM' which is the numeric representation of the month. Although Oracle was able to convert it to the proper date on my system you should try and maintain consistency between the string and the date format used.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Error while using REMAP_TABLE and WHERE clause  together in IMPDP

    I am trying to move some records from a very large table to another small table.
    I am facing trouble while using REMAP_TABLE and WHERE clause together in IMPDP.
    Problem is data filter is not getting applied and all records are getting imported.
    here is how I have simulated this. please advice.
    CREATE TABLE TSHARRHB.TMP1
      A  NUMBER,
      B  NUMBER
    begin
    Insert into TSHARRHB.TMP1
       (A, B)
    Values
       (1, 1);
    Insert into TSHARRHB.TMP1
       (A, B)
    Values
       (2, 2);
    COMMIT;
    end;
    expdp system/password TABLES=tsharrhb.TMP1 DIRECTORY=GRDP_EXP_DIR DUMPFILE=TMP1.dmp REUSE_DUMPFILES=YES LOGFILE=EXP.log PARALLEL=8
    impdp system/password DIRECTORY=GRDP_EXP_DIR DUMPFILE=TMP1.dmp LOGFILE=imp.log PARALLEL=8 QUERY='TSHARRHB.TMP1:"WHERE TMP1.A = 2"'  REMAP_TABLE=TSHARRHB.TMP1:TMP3 CONTENT=DATA_ONLY
    Import: Release 11.2.0.1.0 - Production on Fri Dec 13 05:13:30 2013
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, Automatic Storage Management, OLAP, Data Mining
    and Real Application Testing options
    Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
    Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/********@GRD6.RBSG DIRECTORY=GRDP_EXP_DIR DUMPFILE=TMP1.dmp LOGFILE=SSD_93_TABLES_FULL_EXP.log PARALLEL=8 QUERY=TSHARRHB.TMP1:"WHERE TMP1.A = 2" REMAP_TABLE=TSHARRHB.TMP1:TMP3 CONTENT=DATA_ONLY
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    . . imported "TSHARRHB"."TMP3"                           5.421 KB       2 rows
    Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at 05:13:33
    here I am expecting only 1 record to get imported but both the records are getting imported. please advice.

    The strange thing compared to your output is that I get an error when I have table prefix in the query block:
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
    Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** DUMPFILE=TMP1.dmp LOGFILE=imp.log PARALLEL=8 QUERY=SYSADM.TMP1:"WHERE TMP1.A = 2" REMAP_TABLE=SYSADM.TMP1:TMP3 CONTENT=DATA_ONLY
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    ORA-31693: Table data object "SYSADM"."TMP3" failed to load/unload and is being skipped due to error:
    ORA-38500: Unsupported operation: Oracle XML DB not present
    Job "SYSTEM"."SYS_IMPORT_FULL_01" completed with 1 error(s) at Fri Dec 13 10:39:11 2013 elapsed 0 00:00:03
    And if I remove it, it works:
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
    Starting "SYSTEM"."SYS_IMPORT_FULL_01":  system/******** DUMPFILE=TMP1.dmp LOGFILE=imp.log PARALLEL=8 QUERY=SYSADM.TMP1:"WHERE A = 2" REMAP_TABLE=SYSADM.TMP1:TMP3 CONTENT=DATA_ONLY
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    . . imported "SYSADM"."TMP3"                             5.406 KB       1 out of 2 rows
    Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at Fri Dec 13 10:36:50 2013 elapsed 0 00:00:01
    Nicolas.
    PS: as you can see, I'm on 11.2.0.4, I do not have 11.2.0.1 that you seem to use.

  • Using distinct in where clause

    Greedings,
    I am trying to execute some kind of distinct using rowid in where clause but for some reason im not getting the appropriate result. Any guidance is welcome
    SELECT acnt_code,cat,cat_desc,buc FROM so_budgets_cat where
    Trim(buc)='S03'
    and
    NOT exists (SELECT  1
                       from   so_budgets_cat tab2
                       where  (  tab2.cat     =  so_budgets_cat.cat )
                       and    tab2.ROWID  > so_budgets_cat.ROWID
    ORDER BY cat,so_budgets_cat.rowidThanks in advance

    Additionally to the fact that we don't have an idea on the expected output, I can't understand the comparison of ROWIDs in your query. These are the logical addresses where the data reside in the disks, comparing them doesn't make sense to me; Oracle DB defines where to store, based on space availability in the disk allocation to the database occupation - and NOT in a logical sequence.
    Maybe the existing row is stored in an address that is not a higher number than other, and so it is not being retrieved in your sub-query - hence your test for distinction is failing.

  • Using function in where clause

    I have created a function as follows
    create or replace FUNCTION get_codes RETURN varchar2 IS
    scodes varchar2(50) := 'A1,A2';
    BEGIN
    scodes := '('''||REPLACE(scodes,',',''',''')||''')';
    return scodes;
    END;
    this function returns ('A1','A2')
    now i want to use this in where clause, both below statements fetches no rows
    select * from tablea where code in (select get_codes from dual);
    select * from tablea where code in get_codes;
    but the following will fetch rows
    select * from tablea where code in ('A1','A2')
    how to use function in where clause
    Thanks

    Hi,
    The code that works:
    where code in ('A1','A2')is testing whther code is either of two 2-character strings, A1 or A2.
    The ones that don't work, such as:
    where code in get_codes;are comparing code to one 9-character string: 'A1','A2', where characters 1, 4, 6 and 9 are single-quotes. (The function can only return one value.)
    You can use dynamic SQL to embed that 9-character string in part of your query, where it will be interpreted as two 2-character strrings.
    [Oracle Base|http://www.oracle-base.com/articles/misc/DynamicInLists.php] and AskTom have good pages on the subject of dynamic IN-lists.
    Of you can use INSTR or LIKE:
    where INSTR ( get_codes
                , '''' || code || ''''
                ) > 0

  • Can i use Decode in Where clause

    Hi,
    Can i use Decode in Where clause Please Do the need full on the same.
    Thanks,
    Sanjeev.

    set serveroutput on
    DECLARE
    posn  PLS_INTEGER := 0;
    empid PLS_INTEGER := 178;
    x     NUMBER;
    BEGIN
      SELECT NVL(SUM(ah.quantity * ah.saleprice * ap.payoutpct), 0)
      INTO x
      FROM accessoryhistory ah, payoutpercentage ap,
      sku s, store st
      WHERE empid = DECODE(posn,
                              0, st.areadir,
                              1, st.areamgr,
                              2, NVL(st.storemgr1, st.storemgr2),
                              3, NVL(st.asstmgr1, NVL(st.asstmgr2,
                           st.asstmgr3)))
      AND ah.statustype IN ('ACT', 'DEA')
      AND ah.store = st.store
      AND s.dbid = ah.dbid
      AND s.sku = ah.sku
      AND ap.productgroup = s.productgroup
      AND ap.position = posn;
      dbms_output.put_line(x);
    END;
    /http://psoug.org/reference/decode_case.html

  • Can both in-row and off-row LOBs be used in a where clause?

    We are preparing to upgrade ASE from version 15.5 to 16.0.  One of the features that is very appealing has to do with the changes made concerning the handling of LOBs.  In particular, the ability to use a LOB column in search arguments (where clause) is something our developers have longed for since the retirement of the full-text search option.  So, in version 16.0, can any column with a datatype of text be used as a search argument? Are there any restrictions.
    Thanks in advance.

    Hi Kevin,
    The in-row LOB feature is mainly designed to save space when a text column has many short values, which is a particularly bad problem when the server uses a large page size (like 16K) as ASE would use a full 16K to store even a single bye "Y".  I don't think the feature made any change in how text can be used in search arguments.  i.e. you can still use LIKE and IS [NOT] NULL, but not others.
    Example:
    1> create table t (x text in row (8))
    2> go
    1> insert t values ("abc")
    2> insert t values ("abcdefghijkl")
    3> go
    (2 rows affected)
    1> select * from t where x like "%c%"
    2> go
    x                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
    abc                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
    abcdefghijkl                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
    (2 rows affected)
    1> select * from t where x !> "c"
    2> go
    Msg 257, Level 16, State 1:
    Server 'redhead', Line 1:
    Implicit conversion from datatype 'TEXT' to 'VARCHAR' is not allowed.  Use the
    CONVERT function to run this query.
    Msg 306, Level 16, State 5:
    Server 'redhead', Line 1:
    TEXT, IMAGE and UNITEXT datatypes may not be used in a WHERE clause, except with
    the LIKE expression and IS [NOT] NULL predicate on columns.

  • Using a dummy where-clause to force the use of an index

    I notice that an index only gets used when I use the index key in the where clause. Should I use a dummy where clause to force the index to be used?
    SQL> create table emp (
    2 empno NUMBER(5),
    3 empname VARCHAR2(15) );
    Table created.
    SQL> create index idx_emp_no on emp (empno);
    Index created.
    SQL> insert into emp (empno, empname) values (1, 'Peter');
    1 row created.
    SQL> set autotrace traceonly;
    SQL> select empno from emp;
    Execution Plan
    Plan hash value: 3956160932
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 13 | 3 (0)| 00:00:01 |
    | 1 | TABLE ACCESS FULL| EMP | 1 | 13 | 3 (0)| 00:00:01 |
    SQL> select empno from emp where empno > 0;
    Execution Plan
    Plan hash value: 434430053
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 13 | 1 (0)| 00:00:01 |
    |* 1 | INDEX RANGE SCAN| IDX_EMP_NO | 1 | 13 | 1 (0)| 00:00:01 |
    As you can see, using a dummy where clause (empno > 0), I manage to reduce the cost from 3 to 1.

    Again. Be careful with comparisons. But I like the discussion. It is usefull to carefully look at what happens "behind the scenes" and find a sensible explaination for that.
    Your new scenario now is different. By selecting one specific row instead of selection all you already made an assumption. That only one or few of the rows are returned. Andre's statement still is correct. Now the CBO will prefere the index scan.
    The CBO now has to decide between two options.
    Option a) use the index.
    This means =>
    Step 1: Access the index to find the value
    Step 2: Access the table using the rowid that was found in the index leaf entry.
    Option b) scan the full table
    This means =>
    Step 1: Iterate over all rows of the table
    Step 2: Apply a filter condition (empno = :x)
    We can see this execution plan by adding a hint to the query.
    select /*+ FULL(emp) */ * from emp where empno = 1;This hint will force the CBO to access the table emp using a full table scan.
    The cost in my environment for option B is 3.
    Option A has a cost with 2. Therefore the CBO prefers Option A.
    However this can easily change.
    Consider the following
    begin
      for i in 1..1000 loop
        insert into emp (empno, empname) values (1, 'Employee');
      end loop;
    end;
    commit;
    execute dbms_stats.gather_table_stats(user,'EMP');The run the select again.
    SQL> set autotrace traceonly
    SQL> select * from emp where empno = 1;
    1001 Zeilen ausgewõhlt.
    Ausf³hrungsplan
    Plan hash value: 3956160932
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |  1001 | 12012 |     3   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| EMP  |  1001 | 12012 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("EMPNO"=1)
    Statistiken
              1  recursive calls
              0  db block gets
             74  consistent gets
              0  physical reads
              0  redo size
          18356  bytes sent via SQL*Net to client
           1250  bytes received via SQL*Net from client
             68  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
           1001  rows processedThe CBO now prefers the full table scan and not the index access.
    If we force it to use an index then the cost increases.
    SQL> set linesize 100
    SQL> select /*+INDEX(emp) */ * from emp where empno = 1
    1001 Zeilen ausgewõhlt.
    Ausf³hrungsplan
    Plan hash value: 2426388914
    | Id  | Operation                   | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |           |  1001 | 12012 |     5   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| EMP       |  1001 | 12012 |     5   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | IDX_EMPNO |  1001 |       |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("EMPNO"=1)
    Statistiken
              0  recursive calls
              0  db block gets
            139  consistent gets
              0  physical reads
              0  redo size
          30550  bytes sent via SQL*Net to client
           1250  bytes received via SQL*Net from client
             67  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
           1001  rows processed
    SQL>The cost using the index range scan is now 5. WHile the FTS is still 3. Therefore the CBO prefers to use the FTS.

  • Using multiple dates in WHERE clause

    I have a multiple select box in a form. I am trying to select
    records in SQL using the list that this form field produces. They
    are dateTime values. How do I use this list in the WHERE clause of
    my select statement?

    Man, I really hate posting anywhere near Dan - I've been
    watching his mastery for years. (Talk about the big leagues) But
    here goes anyway...
    I've gotten my little behind kicked by more than a view date
    issues, and I have basically gotten away from exact matches (unless
    you really need them).
    I'd probably do something like this:
    SELECT field1,field2...
    WHERE datetime_column_in_db > (OR LTE,OR GT/LT)
    '#datetimeformatyoulike(form.datetimevalue1)#
    Basically, finding records in RELATION to the form's datetime
    value has always been much easier for me.
    And God (and Dan) have mercy on my soul...

  • Using collections in WHERE clause

    Hi friends,
    Please help me to use an associate array in SQL query (WHERE clause). The requirement is similar to the following example:
    ===============================================
    declare
    type rec_emp is record(emp_id integer, emp_name varchar2(100));
    type ty_emp is table of rec_emp index by pls_integer;
    tb_emp ty_emp;
    type ty_emp_history is table of emp_history%rowtype index by pls_integer;
    tb_emp_history ty_emp_history;
    begin
    select emp_id, emp_name
    bulk collect into tb_emp
    from emp
    where dept_id = 10;
    --Now I want to fetch records from emp_history based on the values in tb_emp. So I want a query something like the following.
    --(I know that join can be used to achive this. But it is just an example. I need to achive this in collections.)
    select *
    bulk collect into tb_emp_history
    from emp_history
    where emp_id = tb_emp.emp_id
    and emp_name = tb_emp.emp_name;
    end;
    ===============================================
    Thanks in advance.
    Edited by: Iniyavan on Oct 26, 2012 11:50 AM

    >
    Please help me to use an associate array in SQL query (WHERE clause).
    select *
    bulk collect into some_array
    >
    there is no variable 'some_array' in what you posted.
    If you want help with your code you have to post the code you are really using, not some hacked-up version of it that has errors.
    Here is sample code that shows how to treat a collection as a table using the TABLE operator
    -- type to match emp record
    create or replace type emp_scalar_type as object
      (EMPNO NUMBER(4) ,
       ENAME VARCHAR2(10),
       JOB VARCHAR2(9),
       MGR NUMBER(4),
       HIREDATE DATE,
       SAL NUMBER(7, 2),
       COMM NUMBER(7, 2),
       DEPTNO NUMBER(2)
    -- table of emp records
    create or replace type emp_table_type as table of emp_scalar_type
    declare
    tb emp_table_type;
    deptnoList sys.OdciNumberList;
    BEGIN
    select emp_scalar_type(empno, ename, job, mgr, hiredate, sal, comm, deptno)
    bulk collect into tb from emp;
    SELECT deptno bulk collect
    INTO deptnoList
    FROM dept where deptno not in (select deptno from table(tb));
    for i in 1..deptnoList.count loop
    dbms_output.put_Line(deptnoList(i));
    end loop;
    END;Note that tb is a collection and is useds in the subquery 'select deptno from table(tb)'.

  • Using Filter and where clause in GoldenGate

    Hi,
    I need to use where clause in extract process.
    The condition i need to use is :- where (CODE LIKE '10%' OR CODE LIKE '0%')
    how to use LIKE operation along with OR in extract.
    I have multiple where conditions these are straight i.e = and <> which are working fine. But LIKE is not working.
    Please do assist for the same.
    Thanks.

    GoldenGate uses FILTER and SQLPREDICATE (and COMPUTE is a variation that can work, depending on how you are trying to manipulate the data).
    To filter data, you can use:
    ● A FILTER or WHERE clause in a TABLE statement (Extract) or in a MAP statement (Replicat).
    ● A SQL query or procedure
    ● User exits
    FILTER comparison operators include:
    Comparison operators:
    > (greater than)
    >= (greater than or equal)
    < (less than)
    <= (less than or equal)
    = (equal)
    <> (not equal)
    WHERE clause permissible operators:
    Column names PRODUCT_AMT
    Numeric values -123, 5500.123
    Literal strings "AUTO", "Ca"
    Built-in column tests @NULL, @PRESENT, @ABSENT (column is null, present or absent in the row). These tests are built into Oracle GoldenGate. See “Considerations for selecting rows with FILTER and WHERE” on page 155.
    Comparison operators =, <>, >, <, >=, <=
    Conjunctive operators AND, OR
    Grouping parentheses Use open and close parentheses ( ) for logical grouping of multiple elements.
    You could try using a GoldenGate string function. You know what the leading one or two characters (0 and 10) are.
    Use the @STREXT function to extract a portion of a string and do a comparison there. Or take care of it using SQLEXEC on replicat (call a function to be able to use LIKE).

  • Regd. using functions in where clause

    Hi All,
    I need to apply a set of functions in sysdate and use that in a where clause to compare. My question is, will these functions on sysdate be executed for every record in the tables that I use? Will this have performance impact when i have millions of records returned by the select?
    Below is the scenario:
    Select * from table A inner join table B on A.c1 = B.c1 where
    TO_NUMBER(TO_CHAR(TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE, -1))),'YYYYMMDD')) BETWEEN Date1 and Date2
    Regards,
    Raj.D

    1005330 wrote:
    I need to apply a set of functions in sysdate and use that in a where clause to compare. My question is, will these functions on sysdate be executed for every record in the tables that I use? Will this have performance impact when i have millions of records returned by the select?
    Below is the scenario:
    Select * from table A inner join table B on A.c1 = B.c1 where
    TO_NUMBER(TO_CHAR(TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE, -1))),'YYYYMMDD')) BETWEEN Date1 and Date2
    Test it on a small data set - run a query and check the execution plan to see what the predicate section tells you.
    Oracle OUGHT to be smart enough to recognise that you've got a constant that it need only calculate once. If not, then change the usage to read:
        (select TO_NUMBER(TO_CHAR(TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE, -1))),'YYYYMMDD')) from dual) BETWEEN Date1 and Date2Note, by the way, that 'constant between col1 and col2' is generally a tough one as far as efficiency is concerned; it translates to:
        col1 <= constant
    and col2 >= constantIn many cases this means oracle has to access a large volume of data (for one of the predicates) and then filter that data (with the other predicate). A typical damage limitation strategy is to create an index on the two columns, arrangin the column order to minimise the range scan on the first column.
    Depending on your data patterns and the nature of the predicate there are alternative optimiisation strategies.
    Regards
    Jonathan Lewis

  • Compare Date in where clause

    Hi,
    I have query which i used to display the new status that happend. Here in the where clause i am checking the dates for comparisiion but the query say no data found
    But data found in the table Please suggest how to put a join condition on dates. or is there any other way to write this query
    select distinct SDM from PROJECT_START_UP
    where project_name = :p1_projects and
    check_id = 44 and
    CREATION_DATE like (select max(CREATION_DATE) from project_start_up where check_id = 44)
    Thanks
    Sudhir

    Why you're using LIKE operator instead of '='??
    Please try whether you have data
    select distinct SDM from PROJECT_START_UP
    where project_name = :p1_projects and
    check_id = 44 If above query returned data, then run
    select distinct SDM from PROJECT_START_UP
    where project_name = :p1_projects and
    check_id = 44 and CREATION_DATE = (select max(CREATION_DATE) from project_start_up where check_id = 44)- - - - - - - - - - - - - - - - - - - - -
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com

  • Date in where clause without Trunc

    Hi,
    How handle a date comparision in where clause without trunc. Rightnow I am using it with 'trunc', it is very slow..
    Select ColumnA,  ColumnB
    From Sample
    Where trunc(created_date,'DD-MON-YY') = '15-NOV-2011';
    CREATE TABLE SAMPLE
         ColumnA NUMBER(9,0)           NOT NULL,
         ColumnB VARCHAR2(255)      NOT NULL,
         created_date                DATE
       );

    Hi,
    Here's one way:
    SELECT  ColumnA,  ColumnB
    FROM      Sample
    WHERE      created_date     >= TO_DATE ('15-NOV-2011', 'DD-MON-YYYY')
    AND     created_date     <  TO_DATE ('15-NOV-2011', 'DD-MON-YYYY') + 1
    ;If you have an index on created_date. then this query will be able to use that index, because created_date is alone on one side of the operator.
    Another reason why this will be faster is that it only has to call TO_DATE twice, regardless of how many rows are in the table. The original query had to call TRUNC for every row.
    Don't compare a DATE (such as the results of TRUNC) to a string (such as '15-NOV-2011'). You're liable to get a run-time error, or, if youre not so lucky, unexpected results.
    Edited by: Frank Kulash on Nov 15, 2011 5:22 PM

  • Clarification on using function in where clause of oracle sql query

    I have an issue in regarding function using where clause of sql query..
    We are facing performance issue while executing query, so in what ways to improve the performance of the query which i have posted below.
    select col ,case when my_function(parameter)
    from tab1 a ,tab2 b,tabl3 c
    where a.column1=b.column2
    and b.column3 =c.column6
    and my_function(parameter)>0
    Regards
    Dinesh
    Edited by: wild fire on May 18, 2012 4:15 PM

    Dinesh,
    remind that when you use a function in the where clause it normally will get started for each record in the table.
    So your answer is two-fold:
    1. make the function only start when needed by adding a function based index on the table (this will make inserts and updates slower)
    2. make the function faster by adding the DETERMINISTIC clause if possible. this will make Oracle "cache" the result of the function.
    Regards,
    Richard
    blog: http://blog.warp11.nl
    twitter: @rhjmartens
    If this question is answered, please mark the thread as closed and assign points where earned..

  • Using decode in where clause

    Hi all
    We can use decode function in the Select columns as well as Group by Columns as well as Having Clause
    Can we use decode function in the where clause also. If yes can u give small sample
    Suresh Bansal

    ""DECODE in the WHERE clause"
    http://psoug.org/reference/decode_case.html
      WHERE empid = DECODE(posn,
                              0, st.areadir,
                              1, st.areamgr,
                              2, NVL(st.storemgr1, st.storemgr2),
                              3, NVL(st.asstmgr1, NVL(st.asstmgr2,
                           st.asstmgr3)))

Maybe you are looking for

  • IN :P_List

    We have a report which needs to print values from multiple rows. The key values for the rows in question are being passed in from a form as a parameter list. However, using the IN with the parameter list doesn't seem to work - as in Select column1, c

  • How to get the list of top 10 tables grown last week or last few days

    Hi All, Please let me know, how to get the list of top 10 tables grown last week or last few days Thanks

  • Question about smc fancontrol after installing Leopard... please help

    hi,, i recently had my macbook pro a clean install leopard,.. everything is going fine afterwards until i installed smc fancontrol, smc fancontrol is working fine, but my problem is, i forgot to set the default fan speed on the smc fancontrol which i

  • After Mountain Lion install,  Mail does not import

    I installed Mountain Lion over a clean installation of Lion. All went well. Entered my AppleID and password, which work fine on my iPhone and MacBookAir. Mail 6.0 (iCloud server) does not import my old mail. iCal and Contacts imported fine. Your help

  • Tiny crack in Macbook Pro 13 inch screen?

    There's this tiny v-shaped crack in my macbook pro 13 inch screen. Inside the v shaped crack it's cloudy and i can't see the screen clearly through the v shape. The crack itself is rainbow colored and at first I thought it was water or something. But