删除语句 - 子查询应该抛出错误

Ora*_*ush 8 sql oracle subquery delete-row

我创建了两个表,T1和T2,每个表分别有一列,abc和xyz.我在每个表中插入了2行(数值1和2).

当我运行该命令时"select abc from t2",它会抛出一个错误,表示表T2中不存在列abc.但是,当我运行该命令时"delete from t1 where abc in (SELECT abc from t2);",将删除2行.

不应该删除失败,因为我使用了在子查询中失败的相同语句?

create table t1(abc number); - 表创建

create table t2(xyz number); - 表创建

插入t1值(1); - 插入一行

插入t1值(2); - 插入一行

插入t2值(1); - 插入一行

插入t2值(2); - 插入一行

从t2中选择abc; --ORA-00904 - >因为t2中不存在列abc

从t1删除abc in(SELECT abc from t2); - 删除了2行

Yog*_*ngh 11

如果使用表名作为别名来确保选择了表t2列,则会出现错误,即

 delete from t1 where abc in (SELECT t2.abc from t2); --ORA-00904 
Run Code Online (Sandbox Code Playgroud)

您的原始查询没有失败,因为它使用abc表的列,t1 因为表t1在子查询中可见.