使用 select * 的递归查询引发 ORA-01789
recursive query with select * raises ORA-01789
这是复杂递归查询的最小化版本。当显式列出递归 CTE 的 递归成员(union all
的第二部分)中的列时,查询有效:
with t (c,p) as (
select 2,1 from dual
), rec (c,p) as (
select c,p from t
union all
select t.c,t.p from rec join t on rec.c = t.p
)
select * from rec
我不明白为什么在指定 t.*
时会出现错误 ORA-01789: query block has incorrect number of result columns
。
with t (c,p) as (
select 2,1 from dual
), rec (c,p) as (
select c,p from t
union all
select t.* from rec join t on rec.c = t.p
)
select * from rec
为什么这里的t.*
不等同于t.c,t.p
?您能否为我指出任何推理的文档?
更新:可在 11g 和 18 (dbfiddle) 上重现。
对我来说似乎可能存在某种错误。我稍微修改了查询以测试各种情况,现在能够在我的 Oracle 19.6.0.0.0 数据库中重现 ORA-00600
错误! 运行 apex.oracle.com 或 livesql.oracle.com(即 运行 19.8.0.0.0)上的问题查询也会导致错误。立即向 Oracle 报告!
我终于asked on AskTom forum and according to response from Oracle expert Connor McDonald, this behavior is in compliance with documentation, namely the sentence The number of column aliases following WITH query_name and the number of columns in the SELECT lists of the anchor and recursive query blocks must be the same which can be found in this paragraph.
重点是,star表达式的扩展是在检查列数是否相同后进行的。因此必须明确列出列,不能缩短为星号。
这是复杂递归查询的最小化版本。当显式列出递归 CTE 的 递归成员(union all
的第二部分)中的列时,查询有效:
with t (c,p) as (
select 2,1 from dual
), rec (c,p) as (
select c,p from t
union all
select t.c,t.p from rec join t on rec.c = t.p
)
select * from rec
我不明白为什么在指定 t.*
时会出现错误 ORA-01789: query block has incorrect number of result columns
。
with t (c,p) as (
select 2,1 from dual
), rec (c,p) as (
select c,p from t
union all
select t.* from rec join t on rec.c = t.p
)
select * from rec
为什么这里的t.*
不等同于t.c,t.p
?您能否为我指出任何推理的文档?
更新:可在 11g 和 18 (dbfiddle) 上重现。
对我来说似乎可能存在某种错误。我稍微修改了查询以测试各种情况,现在能够在我的 Oracle 19.6.0.0.0 数据库中重现 ORA-00600
错误! 运行 apex.oracle.com 或 livesql.oracle.com(即 运行 19.8.0.0.0)上的问题查询也会导致错误。立即向 Oracle 报告!
我终于asked on AskTom forum and according to response from Oracle expert Connor McDonald, this behavior is in compliance with documentation, namely the sentence The number of column aliases following WITH query_name and the number of columns in the SELECT lists of the anchor and recursive query blocks must be the same which can be found in this paragraph.
重点是,star表达式的扩展是在检查列数是否相同后进行的。因此必须明确列出列,不能缩短为星号。