auhtor:skate
time:2010/03/03
oracle抽取函数
今天朋友问个问题,如何抽取时间的“小时”
oracle的抽取函数是 extrac()语法:
SELECT EXTRACT(YEAR from SYSDATE) from DUAL; return Current Year
SELECT EXTRACT(MONTH from SYSDATE) from DUAL; return Current Month
SELECT EXTRACT(DAY from SYSDATE) from DUAL; return Current Day
SELECT EXTRACT(HOUR from TIMESTAMP '2010-10-10 10:10:10') from DUAL;
SELECT EXTRACT(MINUTE from TIMESTAMP '2010-10-10 10:10:10') from DUAL;
例子如下:
SQL> SELECT EXTRACT(YEAR from SYSDATE) from DUAL
2 ;
EXTRACT(YEARfromSYSDATE)
------------------------
2010
SQL> SELECT EXTRACT(month from SYSDATE) from DUAL
2 ;
EXTRACT(MONTHfromSYSDATE)
-------------------------
3
SQL> SELECT EXTRACT(day from SYSDATE) from DUAL;
EXTRACT(DAYfromSYSDATE)
-----------------------
3
SQL> SELECT EXTRACT(hour from SYSDATE) from DUAL;
SELECT EXTRACT(hour from SYSDATE) from DUAL
ORA-30076: 对析出来源无效的析出字段
SQL> SELECT EXTRACT(minute from SYSDATE) from DUAL;
SELECT EXTRACT(minute from SYSDATE) from DUAL
ORA-30076: 对析出来源无效的析出字段
SQL> SELECT EXTRACT(HOUR from TIMESTAMP '2010-10-10 10:10:10') from DUAL;
EXTRACT(HOURfromTIMESTAMP'2010
------------------------------
10
SQL> SELECT EXTRACT(minute from TIMESTAMP '2010-10-10 10:10:10') from DUAL;
EXTRACT(MINUTEfromTIMESTAMP'20
------------------------------