oracle无效且未通过重新验证
代码如下:
SQL code如下:
--创建中国地图表 create table china_address
( id number not null primary key ,
address_name varchar2(30) not null ,
parent_address_id number ,
foreign key (parent_address_id) references china_address(id)
); --创建中国地图序列 create sequence china_address_sequ
minvalue 1 maxvalue 10000 start with 1
increment by 1
nocycle cache 5; --创建中国地图主键自增长触发器 create trigger china_address_increase_tr before
insert on china_address for each row
begin select china_address_sequ.nextval into :new.id from dual
end china_address_increase_tr;
|
修改如下:
CREATE
OR
REPLACE
TRIGGER
CHINA_ADDRESS_INCREASE_TR BEFORE
INSERT
ON
CHINA_ADDRESS
FOR
EACH ROW
BEGIN
SELECT
CHINA_ADDRESS_SEQU.NEXTVAL
INTO
:NEW.ID
FROM
DUAL;
END
CHINA_ADDRESS_INCREASE_TR;
主要是你从网上COPY的代码里面
SELECT CHINA_ADDRESS_SEQU.NEXTVAL INTO:NEW.ID FROM DUAL
后面少了个符号";"
PL/SQL认为语句后面带有一个;才作为一个语句的结束
SELECT CHINA_ADDRESS_SEQU.NEXTVAL INTO:NEW.ID FROM DUAL
后面少了个符号";"
PL/SQL认为语句后面带有一个;才作为一个语句的结束
此外,不建议使用触发器做这个事情,不如使用
INSERT INTO china_address VALUES(CHINA_ADDRESS_SEQU.NEXTVAL,'sd',1);
更健壮.