-
Website
http://awads.net/wp/ -
Original page
http://awads.net/wp/2005/12/28/cool-sql-function-extract/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
jgarry
3 comments · 1 points
-
Andy C
22 comments · 47 points
-
dahowlett
1 comment · 2 points
-
Don Seiler
9 comments · 1 points
-
davidhaimes
4 comments · 3 points
-
-
Popular Threads
For an unknown reason you cannot extract Hour, minute or second from a date. It works only on Timestamp.
Francois
interesting is extracting nanoseconds from timestamp :
SQL> create table t as select timestamp '2000-01-01 00:00:42.123456789' t from dual;
Table created.
SQL> select mod(extract(second from t),1)*1000000000 ns from t;
NS
123456789
You can also get this information with the To_Char() function.
SELECT to_char(SYSTIMESTAMP,'FF') FROM dual
you cannot extract Hour, minute or second from a date
Yes, the documentation says: The field you are extracting must be a field of the datetime_value_expr or interval_value_expr. For example, you can extract only YEAR, MONTH, and DAY from a DATE value.
I'm not sure exactly why you cannot get to the hour/minute/second from a DATE using EXTRACT, since a DATE datatype contains a time portion as well (but not fractional seconds).
It'll be interesting to know what the reason behind this limitation is.
Yes, I just used this the other day. I wrapped it in a DECODE to get a text representation of the month.
Well, this isn't so useful if you want the name of the day instead of a number. Say, "MON" instead of 2. Back to TO_CHAR!
<pre>
select
extract(hour from cast(sysdate as timestamp)) hh,
extract(minute from cast(sysdate as timestamp)) mi,
extract(second from cast(sysdate as timestamp))ss
from dual
</pre>
Thanks.