PLS-00103:遇到符号"文件结束" Sql Developer

时间:2015-05-20 13:57:45

标签: database triggers oracle-sqldeveloper

我想执行以下sql代码。

--1
CREATE TABLE User_Type(
User_Type_ID Integer NOT NULL PRIMARY KEY,
User_Type_Name Char(20 ) NOT NULL
);

CREATE SEQUENCE User_Type_seq;
CREATE TRIGGER User_Type_ID_trg
BEFORE INSERT ON User_Type
FOR EACH ROW
BEGIN
SELECT User_Type_seq.NEXTVAL INTO :new.User_Type_ID
FROM DUAL;
END;
/

当我手动写入sql developer时,它可以工作。但我需要这样的很多块。所以,我用notepad ++编辑了那些并再次复制/粘贴到sql developer。这次;表和序列已创建,但它给出了关于触发器代码的错误(我已经从select_user_errors中选择了这个例程)

PLS-00103:遇到符号"文件结束"当期待以下之一时:错误103                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ;

以下是完整的代码,但不起作用。创建表和序列代码是有效的,但触发代码不是。

--1
CREATE TABLE User_Type(
  User_Type_ID Integer NOT NULL PRIMARY KEY,
  User_Type_Name Char(20 ) NOT NULL
);

CREATE SEQUENCE User_Type_seq;
CREATE TRIGGER User_Type_ID_trg
BEFORE INSERT ON User_Type
FOR EACH ROW
BEGIN
SELECT User_Type_seq.NEXTVAL INTO :new.User_Type_ID
FROM DUAL;
END;
/
--2
CREATE TABLE Users(
  User_ID Integer NOT NULL PRIMARY KEY,
  User_Password Char(8 ) NOT NULL,
  User_Name Char(20 ) NOT NULL,
  User_Type_ID Integer NOT NULL
);
CREATE SEQUENCE Users_seq;
CREATE TRIGGER User_ID_trg
BEFORE INSERT ON Users
FOR EACH ROW
BEGIN
SELECT Users_seq.NEXTVAL INTO :new.User_ID
FROM DUAL;
END;
/
--3
CREATE TABLE Admin(
  Admin_ID Integer NOT NULL PRIMARY KEY,
  E_mail Char(20 ) NOT NULL,
  Phone_Number Char(20 ) NOT NULL,
  User_ID Integer NOT NULL
);
CREATE SEQUENCE Admin_seq;
CREATE TRIGGER Admin_ID_trg
BEFORE INSERT ON Admin
FOR EACH ROW
BEGIN
SELECT Admin_seq.NEXTVAL INTO :new.Admin_ID
FROM DUAL;
END;
/
--4
CREATE TABLE City(
  City_ID Integer NOT NULL PRIMARY KEY,
  City_Name Char(20 ) NOT NULL
);


CREATE SEQUENCE City_seq;
CREATE TRIGGER City_ID_trg
BEFORE INSERT ON City
FOR EACH ROW
BEGIN
SELECT City_seq.NEXTVAL INTO :new.City_ID
FROM DUAL;


/

我搜索了类似的问题,但没有回答解决我的问题。

对不起英语,谢谢...

2 个答案:

答案 0 :(得分:0)

你在最后一次触发中错过END;

CREATE TRIGGER City_ID_trg
BEFORE INSERT ON City
FOR EACH ROW
BEGIN
SELECT City_seq.NEXTVAL INTO :new.City_ID
FROM DUAL;
END;
/

其他所有内容is already created and compiled successfully

顺便说一句,从11g开始,您可以直接在PL / SQL中分配序列,而无需从双重中选择:

...
BEGIN
  :new.City_ID := City_seq.NEXTVAL;
END;
/

答案 1 :(得分:0)

它解决了。不幸的是,一个字母错误我还没有理解为什么,但是:

一定是

create trigger

而不是

CREATE TRIGGER