0

I want to get details from data base in which date is of format 08-MAR-14 03.52.17.000000000 PM .I know its possible to get date

SELECT * FROM Table WHERE somecol >= '2011-01-01' AND somecol <= '2011-01-30' 

in this data i am having time also and how is it possible to get only date and I am using java to connect with oracle and html5+java script+j query.

6
  • Use the DATE() function to extract the year-month-day part. E.g. DATE(somecol) > '2011-01-01' Commented Jun 20, 2014 at 13:34
  • ResultSet.getDate() will only not include the time portion of the data. docs.oracle.com/javase/7/docs/api/java/sql/… Commented Jun 20, 2014 at 13:41
  • 1
    What is the datatype of 'somecol'? Commented Jun 20, 2014 at 13:52
  • It sounds like you are applying conditions on this date as well. You could use trunc(col_date) for your conditions and to_char(col_date, 'YYYY-MM-DD') for how the column values are presented in the select statement. Commented Jun 20, 2014 at 14:00
  • possible duplicate of Oracle: Similar to sysdate but returning only time and only date Commented Jun 20, 2014 at 17:24

2 Answers 2

1

use to_char function.

Refer this link

Sign up to request clarification or add additional context in comments.

Comments

0

I'm assuming somecol contains the date field that is actually stored as a VARCHAR2 text string of the format:

08-MAR-14 03.52.17.000000000 PM

If this is the case, here's your query:

select * from table 
  where to_date(substr(somecol, 0, 9)) >= '01-JAN-11'
    and to_date(substr(somecol, 0, 9)) <= '30-JAN-11';

The problem with this is that Oracle needs to execute the substr and to_date on every row in order to know which ones to bring back. If you need to run this frequently on a table with a large number of rows, it would impact your performance. You could create function-based indexes on 'to_date(substr(somecol, 0, 9))' in order to lessen this impact.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.