oracle 在 COALESCE 中使用 SELECT
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25311854/
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
Using SELECT inside COALESCE
提问by user3808188
How do I correct the following SQL code, specifically the COALESCE part?
如何更正以下 SQL 代码,特别是 COALESCE 部分?
insert into Stmt G (ID,blah,foo)
select
coalesce(SELECT ID FROM Stmt G WHERE G.CLAIMNO=C.CLNUMBER, select StmtSeq.nextval from dual),
c.blah,
d.foo
from claim c
left join d on ...;
I'm taking the ID from the Stmt table itself if the ClaimNo matches, otherwise creating a new one. Is this not allowed in SQL? How else can I write this statement?
如果 ClaimNo 匹配,我将从 Stmt 表本身获取 ID,否则创建一个新的。这在 SQL 中是不允许的吗?我还能怎么写这个声明?
I'm getting a "Missing Expression" error on the coalesce part right now.
我现在在合并部分收到“缺少表达式”错误。
回答by Patrick Hofman
You should place parenthesis around the select
s:
您应该在select
s周围放置括号:
coalesce( (SELECT ID FROM Stmt G WHERE G.CLAIMNO=C.CLNUMBER)
, (select StmtSeq.nextval from dual)
)