oracle中的“Select Extract Minute”失败

时间:2013-10-03 03:47:49

标签: oracle plsql

请帮我解决这个问题。

我需要从表格中提取分钟(“JAM”栏)。

我试过这个查询:

WITH recordabsen AS
     (SELECT userid,
          TO_CHAR(checktime,'MM/DD/YYYY')   AS tanggal ,
          MIN(TO_CHAR(checktime,'hh24:mi')) AS JAM
     FROM checkinout
     WHERE USERID = '688'
      AND (checktime BETWEEN to_date('04/01/2013','MM/DD/YYYY') AND to_date('05/01/2013','MM/DD/YYYY'))
      AND checktype = 'I'
     GROUP BY userid,
          TO_CHAR(checktime,'MM/DD/YYYY')
     )
SELECT EXTRACT (MINUTE FROM JAM) AS minute
FROM recordabsen
WHERE to_date(JAM,'hh24:mi') > TRUNC(to_date(JAM,'hh24:mi')) + 8/24

但返回错误:

无效的提取字段

2 个答案:

答案 0 :(得分:0)

一旦你完成了:

to_char(checktime,'hh24:mi')

你有一个字符串而不是日期,所以也许最好使用字符串函数而不是日期函数,即:

substr("JAM", 4)

Here is a sqlfiddle demo

答案 1 :(得分:0)

为什么不直接从WITH子句查询传递checktime?然后,如果checktime是一个日期,你可以把它投射到TIMESTAMP,这将允许你使用EXTRACT MINUTE:

SELECT EXTRACT (MINUTE FROM CAST(SYSDATE AS TIMESTAMP)) FROM dual;

检查SQLFiddle:http://www.sqlfiddle.com/#!4/d41d8/18054