oracle timestamp转换date及date类型相减
--timestamp转换为date(ts字段为timestamp类型) SELECT cast(ts AS DATE) from tab1 WHERE tid=1; --timestamp转换为date(ts字段为timestamp类型) SELECT cast(ts AS DATE) from tab1 WHERE tid=3; --date相减 SELECT (SELECT cast(ts AS DATE) from tab1 WHERE tid=3)-(SELECT cast(ts AS DATE) from tab1 WHERE tid=1) FROM dual; --把date转换为妙 SELECT ((SELECT cast(ts AS DATE) from tab1 WHERE tid=3)-(SELECT cast(ts AS DATE) from tab1 WHERE tid=1))*24*60*60 FROM dual;