-
How to get the date?
In sql server,I can do this
"select * from table1 where year(ltime) = year(getDate()) and month(ltime) = month(getDate()) and day(ltime) = day(getDate())
the ltime column is datetime type.
but in oracle,I can do this
"select * from table1 where year(ltime) = year(sysdate) and month(ltime) = month(sysdate) and day(ltime) = day(sysdate)
but can not find year(),month,day() function ,How can I do?
please help,thanks
ocean
-
There are a couple of ways that you can do something similar, but in your case you would want ...
select * from table1
where TRUNC(ltime,'D') = TRUNC(sysdate,'D');
(see the TRUNC function in the Oracle SQL Reference)
In fact, since truncation defaults to 'Day' you could also ...
select * from table1
where TRUNC(ltime) = TRUNC(sysdate);
... although that is not quite so clear.
One problem with this is that it could limit the use of indexes on the ltime column. Possible solutions would be to either create a function based index ...
create index my_index on table1 (TRUNC(ltime));
... or turn your query into ...
select * from table1
where ltime >= TRUNC(sysdate) and ltime < Trunc(sysdate)+1;
-
thank you very much
ocean
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|