oracle ignores invalid identifier error in subquery(oracle 忽略子查询中的无效标识符错误)
问题描述
我不明白为什么以下查询有效,尽管子查询给出了无效标识符"错误.
I do not understand why the following query works, although the subquery gives an "invalid identifier" error.
SELECT *
FROM aircraft
WHERE airc_manufact IN (SELECT airc_manufact FROM flight);
我的表格如下所示(缩写):
My tables look the following (abbreviated):
AIRCRAFT(airc_model (PK),airc_manufact)
AIRCRAFT (airc_model (PK), airc_manufact)
飞行(flt_no (PK),airc_model (FK))
如果我自己运行子查询,我会收到一个无效标识符"错误,因为 airc_manufact 不是飞行表中的列.
If I run the subquery on its own, then I receive an "invalid identifier" error like it should since the airc_manufact is not a column in the flight table.
如果我运行整个查询,则不会收到错误消息.Oracle 似乎忽略了子查询,因此给了我飞机表中的所有行.
If I run the whole query, then I do not receive an error. Oracle seems to ignore the subquery and thus give me all row in the aircraft table.
对我来说,这似乎是一个错误,因为查询中有一个明显的错误.为什么查询会运行?我的理解是,Oracle 会先运行或评估子查询,然后再运行外部查询.
To me, this seems to be a bug because there is an obvious error in the query. Why does the query run? My understanding is that Oracle would first run or evaluate the subquery, and then run the outer query.
推荐答案
你没有限定你的列名.所以,你认为你在跑步:
You have not qualified your column names. So, you think you are running:
SELECT a.*
FROM aircraft a
WHERE a.airc_manufact IN (SELECT f.airc_manufact FROM flight f);
如果 f.airc_manufact 不存在,则范围规则说要查看外部查询.所以,你真正在运行的是:
If f.airc_manufact doesn't exist, then the scoping rules say to look in the outer query. So, what you are really running is:
SELECT a.*
FROM aircraft a
WHERE a.airc_manufact IN (SELECT a.airc_manufact FROM flight f);
这作为一个过滤子句非常无用.
That is pretty useless as a filtering clause.
道德:总是限定查询中的列名,特别是当查询引用多个表时.
Moral: Always qualify column names in a query, particularly if the query refers to more than one table.
这篇关于oracle 忽略子查询中的无效标识符错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:oracle 忽略子查询中的无效标识符错误
基础教程推荐
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 无法解决整理冲突 2021-01-01
