Oracle Database 提取日期的年,月,日,小时,分钟或秒部分
示例
DATE数据类型的年,月或日组成部分可以使用EXTRACT( [ YEAR | MONTH | DAY ] FROM datevalue )
SELECT EXTRACT (YEAR FROM DATE '2016-07-25') AS YEAR,EXTRACT (MONTH FROM DATE '2016-07-25') AS MONTH,
EXTRACT (DAY FROM DATE '2016-07-25') AS DAY
FROM DUAL;
输出:
YEAR MONTH DAY---- ----- ---
2016 7 25
时间(小时,分钟或秒)部分可以通过以下任一方式找到:
使用CAST( datevalue AS TIMESTAMP )将转换DATE为a TIMESTAMP,然后使用EXTRACT( [ HOUR | MINUTE | SECOND ] FROM timestampvalue ); 要么
使用TO_CHAR( datevalue, format_model )来获取值作为一个字符串。
例如:
SELECT EXTRACT( HOUR FROM CAST( datetime AS TIMESTAMP ) ) AS Hours,EXTRACT( MINUTE FROM CAST( datetime AS TIMESTAMP ) ) AS Minutes,
EXTRACT( SECOND FROM CAST( datetime AS TIMESTAMP ) ) AS Seconds
FROM (
SELECT TO_DATE( '2016-01-01 09:42:01', 'YYYY-MM-DD HH24:MI:SS' ) AS datetime FROM DUAL
);
输出:
HOURS MINUTES SECONDS----- ------- -------
9 42 1
以上是 Oracle Database 提取日期的年,月,日,小时,分钟或秒部分 的全部内容, 来源链接: utcz.com/z/326293.html