为何要加上;作为「;在SQL语句中;从「;导致错误?
followsql语句运行良好,但在将为何要加上;作为「;在SQL语句中;从「;导致错误?,sql,oracle,Sql,Oracle,followsql语句运行良好,但在将添加为时,数据库会给出一个错误。 但是,给出的许多案例在FROM中包含AS。那么,错误陈述有什么问题吗 谢谢 -- works code select distinct id from PROJECT b where 0>= ( select max(step) from PROJECT where (status='C' and id =b.id) ); 错误消息:ORA-00933:SQL命令未正确结束 -
添加为时,数据库会给出一个错误。
但是,给出的许多案例在FROM
中包含AS
。那么,错误陈述有什么问题吗
谢谢
-- works code
select distinct id
from PROJECT b
where 0>= (
select max(step)
from PROJECT
where (status='C' and id =b.id)
);
错误消息:ORA-00933:SQL命令未正确结束
-- testing data
create table project (
id varchar(22) not null,
step int not null,
status char(1) not null,
primary key (id, step)
);
insert into project values ('P100', 0,'C');
insert into project values ('P100', 1,'W');
insert into project values ('P100', 2,'W');
insert into project values ('P201', 0,'C');
insert into project values ('P201', 1,'C');
insert into project values ('P333', 0,'W');
insert into project values ('P333', 1,'W');
insert into project values ('P333', 2,'W');
insert into project values ('P333', 3,'W');
注意:Oracle中的表别名不允许使用我的代码运行(即使用Oracle Database 19c)as
(尽管在所有(或几乎所有)其他数据库中都允许)
也就是说,这里有两种编写查询的替代方法可能更有效:
select distinct p.id
from PROJECT p
where exists (select 1
from PROJECT p2
where p2.id = p.id and p2.status = 'C' and p2.step > 0
);
或:
…因为Oracle不支持表别名的as
,而支持列别名的as
。
select distinct p.id
from PROJECT p
where exists (select 1
from PROJECT p2
where p2.id = p.id and p2.status = 'C' and p2.step > 0
);
select distinct p.id
from project p
where p.status = 'C' and p.step > 0