我只在查询的LOGIN_TIME部分遇到此“ORA-01850”错误。我相信这是因为我团队中的某些人忘记在班次结束时退出,因此他们的某些数据字段的登录时间超过24小时(不应该这样)。
所以基本上我想让我的查询做的是;读取登录时间,如果超过24小时,则将时间缩短至24小时,以便可以将其转换为秒。
我认为这会纠正错误吗?但我怎么做呢?
SELECT
CALL_DATE as "Date"
, TO_NUMBER(TO_CHAR(TO_DATE(CALL_TIME,'hh24:mi:ss'),'sssss'))/86400 as "Time"
, AGENT_GROUP as "Agent Group"
, AGENT_NAME as "Agent Name"
, STATE as "State"
, REASON_CODE as "Reason Code"
, TO_NUMBER(TO_CHAR(TO_DATE(LOGIN_TIME,'hh24:mi:ss'),'sssss'))/86400 as "Login Time"
, TO_NUMBER(TO_CHAR(TO_DATE(READY_TIME,'hh24:mi:ss'),'sssss'))/86400 as "Ready Time"
, TO_NUMBER(TO_CHAR(TO_DATE(NOT_READY_TIME,'hh24:mi:ss'),'sssss'))/86400 as "Not Ready Time"
FROM DB.AGENT_DETAILS
WHERE
AGENT_GROUP in ('Sales')
and TRUNC(CALL_DATE) BETWEEN '01-January-2017' and TRUNC(SYSDATE)
答案 0 :(得分:1)
问题是您的数据存储在VARCHAR2中,并且它们使用非标准方法来存储大于一天的间隔。因此,我们需要进行一些字符串操作,以使它们成为内置Oracle函数可以使用的格式。
可以提供帮助的一个这样的Oracle函数是TO_DSINTERVAL,它可以选择接受以小时,分钟和秒表示的ISO间隔 - 但它必须看起来像with q1 as (
/*here is the source data*/
select '24:03:45' as t from dual
), q2 as (
/*parse and convert to iso interval format*/
select 'PT' || substr(t,1,2) || 'H'
|| substr(t,4,2) || 'M'
|| substr(t,7,2) || 'S'
as iso from q1
), q3 as (
/*convert to an Oracle Day-To-Second Interval*/
select to_dsinterval(iso) i from q2
)
/*convert interval to whole number of seconds*/
select trunc((i + sysdate - sysdate) * 86400) as sssss from q3;
86625
。
以下是一个例子:
{{1}}