0

I'm trying to use DELETE FROM with an IN clause and a subquery to delete rows given by a query on another table that is 1-to-1 with the table I am deleting from, but Oracle 11g2 barfs an utterly unhelpful ORA-00900 error at me, as in the following SQL fiddle:

http://sqlfiddle.com/#!4/93171/1

For those who can't get at SQLfiddle, the schema/initial load I'm using is (I'm using varchar instead of varchar2 for test portability, the "wild" data uses varchar2 instead):

create table obj (id integer primary key, data varchar(100));
create table meta(id integer primary key, imported char(1));

insert into obj (id, data) values (1, 'foo');
insert into obj (id, data) values (2, 'bar');
insert into obj (id, data) values (3, 'baz');
insert into obj (id, data) values (4, 'blurf');
insert into obj (id, data) values (5, 'hurf');
insert into meta (id, imported) values (1, 'T');
insert into meta (id, imported) values (2, 'F');
insert into meta (id, imported) values (3, 'T');
insert into meta (id, imported) values (4, 'F');
insert into meta (id, imported) values (5, 'F');

and the statements I'm trying to run are:

delete from obj where obj.id in (select meta.id from meta where meta.imported = 'F');
select * from obj full outer join meta on obj.id = meta.id;

(The select ... full outer join runs by itself, and the error still happens if I still comment it out, so it's not the source of the ORA-00900.)

P.S. this statement is valid SQL, too -- neither SQL Server 2014 nor PostgreSQL 9.3 have an issue with the fiddle, and it works in a local copy of SQLite 3.8.8.3 as well once the full outer join is switched for an inner join.

4

2 回答 2

0

也许您需要通过反转表并仅采用空值来将左连接与左连接结合起来

select * from obj left join meta on obj.id = meta.id 
union all
select * from meta left join obj  on obj.id = meta.id 
where obj.id is null 
于 2015-03-25T22:13:02.577 回答
0

这确实是 SQLFiddle 中的一个问题——当我对正在使用的实际数据库运行这种形式的删除语句时,不会出现 ORA-00900。

为什么关于页面没有更清楚地记录这一点,我不知道......

于 2015-03-27T14:24:03.687 回答