working with dates in oracle

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • UnixUser

    working with dates in oracle

    I need to write a query in oracle 8i that will allow me to select some
    rows of date within a date range. In MSSQL I would do something like
    "select f1,f2 from tablea where lastdate >= '01/01/2002'" . How do I
    accomplish the same type of query in Oracle.
  • Jim Kennedy

    #2
    Re: working with dates in oracle

    select f1,f2 from tablea where lastdate >=
    to_date('01/01/2002','mm/dd/yyyy')
    (assuming you mean month then day in your format.)
    Jim

    "UnixUser" <rafel.coyle@pf shouston.comwro te in message
    news:a1c0482e.0 307271821.46844 9c3@posting.goo gle.com...
    I need to write a query in oracle 8i that will allow me to select some
    rows of date within a date range. In MSSQL I would do something like
    "select f1,f2 from tablea where lastdate >= '01/01/2002'" . How do I
    accomplish the same type of query in Oracle.

    Comment

    • andrewst

      #3
      Re: working with dates in oracle


      Originally posted by Kuljeet
      rafel.coyle@pfs houston.com (UnixUser) wrote in message
      news:news:...
      I need to write a query in oracle 8i that will allow me to
      select some
      rows of date within a date range. In MSSQL I would do something
      like
      "select f1,f2 from tablea where lastdate >= '01/01/2002'" . How
      do I
      accomplish the same type of query in Oracle.
      >
      try-->
      select f1,f2 from tablea where to_char(lastdat e,'DD/MM/YYYY') >=
      '01/01/2002';
      NO! See Jim Kennedy's answer for the correct approach. The above does
      a string comparison, and will say that '02/01/1999' is greater than
      '01/01/2002'!

      --
      Posted via http://dbforums.com

      Comment

      • Walt

        #4
        Re: working with dates in oracle

        andrewst wrote:
        Originally posted by Kuljeet
        try-->
        select f1,f2 from tablea where to_char(lastdat e,'DD/MM/YYYY') >=
        '01/01/2002';
        NO! See Jim Kennedy's answer for the correct approach. The above does
        a string comparison, and will say that '02/01/1999' is greater than
        '01/01/2002'!
        And it'll be much slower since you're applying the to_char() function
        for each row in the table, instead of just applying the to_date()
        function once.

        Of course, the bigger problem is the accuracy, not the performance...

        --
        //-Walt
        //
        //

        Comment

        Working...