当我在 Oracle 10g 中运行它时,我收到错误“ORA-01427:单行子查询返回多于一行”,正如我所料:
WITH a as (select 1 somenumber from dual),
b as ( select 'foo' foo from dual
union all select 'goo' from dual)
SELECT (select 0.5 from b)
FROM a
但是,当我运行以下语句时,我没有收到错误,而是返回“2.5”。
WITH a as (select 1 somenumber from dual),
b as ( select 'foo' foo from dual
union all select 'goo' from dual)
SELECT (select sum(a.somenumber) + 0.5 from b)
FROM a
这个标准是对子查询求和然后添加 0.5 就好像它是在运行子查询后完成的一样?或者这是一些 Oracle 特性/错误?
编辑:对于那些好奇的人,实际代码看起来更像这样:
WITH a as (select 1 somenumber from dual),
b as ( select 'foo' foo from dual
union all select 'goo' from dual)
SELECT (select sum(a.somenumber) + customfunction(a.somenumber) from b)
FROM a