oracle我刚刚接触不久,麻烦各位看看:
select caller_nbr,called_nbr,start_time,end_time,
(to_date(end_time,'yyyy-mm-dd hh24:mi:ss') - to_date(start_time,'yyyy-mm-dd hh24:mi:ss'))
from tab_pub_calllog where called_nbr='18' order by start_time desc查询此语句时候报错,start_time,end_time的格式是:2009-03-01 19:28:16
select caller_nbr,called_nbr,start_time,end_time,
(to_date(end_time,'yyyy-mm-dd hh24:mi:ss') - to_date(start_time,'yyyy-mm-dd hh24:mi:ss'))
from tab_pub_calllog where called_nbr='18' order by start_time desc查询此语句时候报错,start_time,end_time的格式是:2009-03-01 19:28:16
比如
SQL> select to_date('2009-03-01 19:28:16','yyyy-mm-dd hh24:mi:ss')-to_date('2009
-02-01 19:28:16','yyyy-mm-dd hh24:mi:ss') rtn from dual; RTN
----------
28SQL> select to_date('2009-01-01 19:28:16','yyyy-mm-dd hh24:mi:ss')-to_date('2009
-02-01 19:48:16','yyyy-mm-dd hh24:mi:ss') rtn from dual; RTN
----------
-31.013889你这里报什么错,你的start_time, end_time是什么类型的字段。
end_time - start_time
from tab_pub_calllog where called_nbr='18' order by start_time desc
直接相减就可以了。
end_time - start_time
from tab_pub_calllog where called_nbr='18' order by start_time desc
那不需要用to_date了,直接相减。SQL> select to_date('2009-03-01 19:28:16','yyyy-mm-dd hh24:mi:ss')-to_date('2009
-02-01 19:28:16','yyyy-mm-dd hh24:mi:ss') rtn from dual; 注意我用的这里都是字符串的。to_date('2009-03-01 19:28:16','yyyy-mm-dd hh24:mi:ss')