ORA-00933:SQL命令没有正确结束?输入绑定变量?

时间:2016-01-04 12:47:31

标签: sql oracle

我试图在我的Oracle Apex 5的SQL命令中写出来,我不明白为什么我会收到错误。此外,当我向'Enter Bind Variables'提交询问“:NEW'时,会出现一个弹出窗口吗?是不是已经宣布了?

drop table tmpcapacityguide cascade constraints;
drop table tmpcaravanpark cascade constraints;

create table tmpcaravanpark as select * from Caravan_park;
create table tmpcapacityguide 
(mincap   number(3),
 maxcap   number(3));

insert into tmpcapacityguide values(30, 150);

CREATE OR REPLACE TRIGGER "PARK_CAPACITY_CHECK" 
before insert or update of capacity
on Caravan_park
for each row
when (:new.capacity < 30) DECLARE
mincapacity integer;
maxcapacity integer;

begin
select mincap, maxcap
into mincapacity, maxcapacity
from tmpcapacityguide
where capacity = :new.capacity;
if (new.capacity < mincapacity)
then raise_application_error(-20601, 'Capacity must be between 30 and 150');
end if;
end;

2 个答案:

答案 0 :(得分:0)

尝试使用斜杠和最后一个结束后的触发器名称,并且您也不需要&#34;:&#34;在IF语句中的新变量之前签名:

drop table tmpcapacityguide cascade constraints;
drop table tmpcaravanpark cascade constraints;

create table tmpcaravanpark as select * from Caravan_park;
create table tmpcapacityguide  (mincap   number(3), maxcap   number(3));
/
insert into tmpcapacityguide values(30, 150);
/
CREATE OR REPLACE TRIGGER PARK_CAPACITY_CHECK 
    before insert or update of capacity on caravan_park
    for each row
    when (new.capacity < 30) 
declare
    mincapacity integer;
    maxcapacity integer;
begin
    select mincap, maxcap
    into mincapacity, maxcapacity
    from tmpcapacityguide
    where capacity = :new.capacity;

    if (new.capacity < mincapacity)
    then 
        raise_application_error(-20601, 'Capacity must be between 30 and 150');
    end if;
end PARK_CAPACITY_CHECK;
/

此外,您应该将其作为脚本执行,而不是在SQL Developer中执行。这可以通过按F9而不是F5作为sstated here来完成。

修改

至于您的ORA-00904错误,您的tmpcapacityguide表中仍然没有容量列。你试着在这里使用它:

select mincap, maxcap
into mincapacity, maxcapacity
from tmpcapacityguide
where capacity = :new.capacity;

答案 1 :(得分:0)

输入

:new.capacity并且必须声明。有关详细信息,请参阅此处:http://www.akadia.com/services/ora_bind_variables.html