Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个具有以下结构的表DEMOTABLE(COL_ID INT,COL_DATE DATE). 为什么以下查询给我一个错误
DEMOTABLE(COL_ID INT,COL_DATE DATE).
错误代码 936,SQL 状态 42000:ORA-00936:缺少表达式
SELECT MAX( SELECT TO_CHAR(COL_DATE,'YYYY-MM-DD HH24:MI:SS') FROM DEMOTABLE WHERE COL_ID IN(1,2,3)) FROM DUAL
听起来你想要
SELECT to_char( max( col_date ), 'yyyy-mm-dd hh24:mi:ss' ) FROM demotable WHERE col_id IN (1,2,3)
通常,您需要先执行MAX然后才将最大日期转换为字符串。这既是因为您想使用日期比较语义,又因为进行比较更便宜,并且只对您感兴趣的一行进行数据类型转换。您还想SELECT从您感兴趣的表中,而不是来自DUAL。
MAX
SELECT
DUAL