Oracle SQL ORA-00907:CASE语句中缺少右括号错误

时间:2014-06-03 18:33:25

标签: sql oracle case-statement

我正在select子句中使用以下CASE语句执行查询:

select (case instr(listagg(D.first_name, ',') 
    within group (order by D.first_name), ',')
when 0 
then substr(listagg(D.first_name, ',') 
    within group (order by D.first_name), 1)
else substr(listagg(D.first_name, ',') 
    within group (order by D.first_name), 1, instr(listagg(D.first_name, ',') 
    within group (order by D.first_name), ',') - 1) end) Advisor1FName
from ....

SQL Developer抛出一个ORA-00907错过右侧的paranthesis错误。

出了什么问题?任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

通过将整个listagg函数括在括号中来解决。奇怪的是,他们是必需的,但这就解决了这个问题。

所以,

substr(listagg(D.first_name, ',') 
    within group (order by D.first_name), 1)

变为

substr((listagg(D.first_name, ',') 
    within group (order by D.first_name)), 1)