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

おそらく、テーブルを逆にして、null 値のみを取得することにより、左結合と結合した左結合が必要になる場合があります。

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 は発生しません。

なぜaboutページがこれをより明確に文書化していないのか、私にはわかりません...

于 2015-03-27T14:24:03.687 に答える