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;

 

posted on 2013-06-21 17:26  Ruthless  阅读(20704)  评论(0编辑  收藏  举报