Oracle SQL ORA-00907:CASE 语句中缺少右括号错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24022437/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle SQL ORA-00907: missing right parenthesis error in CASE statement
提问by Moon_Watcher
I'm executing a query with the following CASE statement in the select clause:
我在 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 throws an ORA-00907 missing right paranthesis error.
SQL Developer 抛出 ORA-00907 缺少右括号错误。
What is going wrong? Any help would be appreciated.
出了什么问题?任何帮助,将不胜感激。
回答by Moon_Watcher
Solved by enclosing the entire listagg function in brackets. It's strange that they were required, but that's what solved the problem.
通过将整个 listagg 函数括在括号中来解决。奇怪的是它们是必需的,但这就是解决问题的方法。
So,
所以,
substr(listagg(D.first_name, ',')
within group (order by D.first_name), 1)
becomes
变成
substr((listagg(D.first_name, ',')
within group (order by D.first_name)), 1)