This content has been marked as final. Show 7 replies
you are missing select from dual
here is the example you can replcae with your table name and seq name;
SQL> CREATE OR REPLACE TRIGGER tr_subjectnot sure why are you creating trigger, you can use SQ_SUBJECT.nextval in insert statement also.
2 BEFORE INSERT
3 ON emp
4 FOR EACH ROW
6 SELECT SEQ_THREAD.NEXTVAL
7 INTO :NEW.empno
8 FROM DUAL;
looks ok, but I would try this version
create or replace trigger trg_bri_studentsAre you sure that you use the correct table and ids? It is strange that a table "students" has a primary key "subject_id".
before insert on students
for each row
if :new.SUBJECT_ID is null then
select SQ_SUBJECT.nextval into :new.SUBJECT_ID from dual;
what is the prominence of '/' ???
in the pl/sql
Below is the exact SQL , i hv noticed later that I haven't given '/' ,
so would like to know its importance in a sql statement.
create or replace trigger tr_subject
2 BEFORE insert on SUBJECT
3 for each row
5 select SQ_SUBJECT.nextval into :new.SUBJECT_ID from dual;
/ indicates Oracle that the statements are over and now it should execute them. For an un-named code block you have to tell Oracle when it should start the execution. '/' is meant for exactly the same purpose.
Hope it helps.
/ indicates Oracle that the statements are over andThat's not strictly true - the / is a SQL*Plus command, not an Oracle command. When you're keying in pl/sql code into SQL*Plus, it leaves you in the editor until you give either a . (quit the editor without running the code) or / (quit the editor and run the code)
now it should execute them. For an un-named code
block you have to tell Oracle when it should start
the execution. '/' is meant for exactly the same
Hope it helps.
If you're not using SQL*Plus to run your code, then it may be that the / is unnecessary - for example, I know that Toad does not require an additional /.
However, the bulk of scripts will still be run through SQL*Plus, so it's good practice to make them SQL*Plus ready. If you don't, be prepared to spend a while working out why your release script that ran so fine on Toad is now stuck on a line number in SQL*Plus...
To my knowledge, most other Oracle client tools will accept the extra / without complaining.
thank you gurus!!