我正在使用下面的DB2查询来获取特定字符长度 来自CLASSICICATION Coulmn的条件,条件是“ \”之前的条件0,但出现错误。
select SERVICE_REQUEST,
(case when
(SUBSTR(CLASSIFICATION,LOCATE('\',CLASSIFICATION)-2,1))='0' then
RIGHT(CLASSIFICATION,LENGTH(CLASSIFICATION)-LOCATE('\',CLASSIFICATION))
ELSE CLASSIFICATION
end)
as CLASSIFICATION2
from REPORTDB3.MAXIMO_INDIA_SR_MONTHLY_REPORT where length(SERVICE_REQUEST)=7
错误:
An error occurred while processing the results. -
The statement was not executed because a numeric argument of a scalar function is out of range.. SQLCODE=-138, SQLSTATE=22011, DRIVER=4.19.56
您能帮我吗?
关于, Sambit
已经不再需要Stackoverflow了
答案 0 :(得分:0)
我相信您应该关注CLASSIFICATION
列数据存在以下问题的情况:
-完全没有\
个字符
-第1个第2个位置中的\
字符
在这种情况下,您的查询会将负的第二个参数传递给SUBSTR
函数,这是不允许的。
with REPORTDB3_MAXIMO_INDIA_SR_MONTHLY_REPORT(CLASSIFICATION, SERVICE_REQUEST) as (
values
('ab0c|def', '1234567')
, ('\def', '1234567')
, ('a\def', '1234567')
, ('ab0c\def', '1234567')
)
select SERVICE_REQUEST, CLASSIFICATION,
case SUBSTR(CLASSIFICATION, case when pos>2 then pos end -2, 1)
when '0' then SUBSTR(CLASSIFICATION, pos+1)
else CLASSIFICATION
end as CLASSIFICATION2
from (
select SERVICE_REQUEST, CLASSIFICATION, LOCATE('\', CLASSIFICATION) as pos
from REPORTDB3_MAXIMO_INDIA_SR_MONTHLY_REPORT
where length(SERVICE_REQUEST)=7
)