我有疑问SELECT A.ID, B.ID FROM A, B
这工作正常。
一旦我添加 FETCH FIRST n ROWS ONLY
对它来说,查询失败并显示错误消息
SQL Error [918] [42000]: ORA-00918: column ambiguously defined
据我了解,该错误指的是一个模棱两可的
SELECT
条款,不应由 FETCH FIRST n ROWS ONLY
引起.我是否错过了证明这种行为合理的东西?或者这是一个错误?
我知道在指定显式列别名时可以省略此行为。我想知道,为什么
SELECT A.ID, B.ID FROM A, B
有效,而 SELECT A.ID, B.ID FROM A, B FETCH FIRST 10 ROWS ONLY
没有。Oracle 版本为 12.1.0.2.0
最佳答案
这记录在 oracle documents 中:
Restrictions on the row_limiting_clause
If the select list contains columns with identical names and you specify the row_limiting_clause, then an ORA-00918 error occurs. This error occurs whether the identically named columns are in the same table or in different tables. You can work around this issue by specifying unique column aliases for the identically named columns.
即使
SELECT
使用 FETCH FIRST|NEXT
后,查询有效, 如果两个列名称相同,则会抛出错误。您应该为
SELECT
中的所有列指定不同的别名。条款。
关于sql - Oracle SQL "column ambiguously defined"和 `FETCH FIRST n ROWS ONLY`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57787579/