views:

152

answers:

3

Can anyone please tell me what is wrong with this query?

create trigger Test_trigger 
   before insert on Test for each row 
   begin select TestSequence.nextval into :new.id from dual; 
end;/

When I run this query, I get the following error:

ERROR at line 1: PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:

;
The symbol ";" was substituted for "end-of-file" to continue.

I am using Oracle 10g Express Edition.

A: 

It should work if you remove the "/" at the end.

Liao
I've tried removing "/". Still it doesn't work.
Ivey
Strange, because I tested your exact code (minus the "/") in Oracle 10g XE and it worked just fine.. (ofcourse, I created a dummy table and a sequence too). Maybe you are using this as part of a script and the error is elsewhere in the script?
Liao
Please look at the script I've included above.
Ivey
A: 

Here is the script I'm trying to execute:

drop index TestTableIdx1;
drop index TestIdx1;
drop index TestIdx2;
drop table Test;
drop sequence TestSequence;
drop table TestTable; 

create table TestTable (
  objId      number        NOT NULL,
  type       varchar(16)   NOT NULL,
  title      varchar(192)          ,
  url        varchar(192)          ,
  primary key(objId, type)
);

create table Test (
  id         number        NOT NULL,
  objId      number        NOT NULL,
  type       varchar(16)   NOT NULL, 
  timeslot   timestamp     NOT NULL,
  contextId  number        ,
  pubId      number        NOT NULL,
  category   varchar(24),
  meta       varchar(32),
  pageviews  number        NOT NULL,
  aggrLevel  number        NOT NULL,
  primary key(id)
);

create table Dummy (
  id int NOT NULL,
  primary key(id)
);

create sequence TestSequence 
start with 1 
increment by 1 
nomaxvalue;

create trigger Test_trigger
before insert on Test
for each row
begin
select TestSequence.nextval into :new.id from dual;
end;
/

create index TestTableIdx1 on TestTable (
  objId desc, type asc
);

create index TestIdx1 on Test (
  timeslot desc, objId desc, type asc
);

create index TestIdx2 on Test (
  timeslot desc
);

create index TestIdx3 on Test (
  objId desc, type asc
);

create index TestIdx4 on Test (
  contextId desc
);
Ivey
your script is working fine.... i tested your code exactly as above using sqldeveloper.
poh
Yeah, script runs just fine. Although I doubt it in this case, it could be some odd oracle problem? Presuming you're using SqlDeveloper, try restarting it?
Liao
Thanks. I tried running it twice. I'll try again. I'm running the script through the web interface.Don't know what I am doing wrong!:(
Ivey
Why have you got "desc" and "asc" in your index definitions? Oracle indexes are bidirectional.
Jeffrey Kemp
I tried executing the script again; this time it is running properly! I still don't know what I've done wrong before. But I'm just happy it works.:DThanks Liao and poh for your help.
Ivey
A: 

The trailing "/" is SQL*Plus syntax. You're probably using the SQL tool in Oracle Apex - in which case, omit the "/".

Jeffrey Kemp
Thanks. I wasn't aware of that. Will remember that later on using sql commands in Apex.
Ivey