Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

before insert trigger 1

Status
Not open for further replies.

mufka

ISP
Dec 18, 2000
587
US
I'm experimenting with sequences and triggers. I've created a sequence called AUTONUM, a table named EMP (columns EMP_ID, EMP_NAME, EMP_DEPT) and the following trigger.

Code:
CREATE OR REPLACE TRIGGER  "BI_EMP" 
  before insert on "EMP"               
  for each row  
begin   
    select "AUTONUM".nextval into :NEW.EMP_ID from dual; 
end;

My impression would be that this would mean that I could use an insert like:
Code:
INSERT INTO EMP VALUES ('John', 'Sales');

But it is looking for the EMP_ID field to be filed. Isn't that what the trigger does?
 
Mufka,

If you do not tell Oracle otherwise, it expects to populate all columns of your table with the VALUES clause of your INSERT statement.

To instruct Oracle to not to look for the EMP_ID in the list of expressions in your VALUES clause, you can say:
Code:
INSERT INTO EMP [B][I](EMP_NAME, EMP_DEPT)[/I][/B] VALUES ('John', 'Sales');
...then your code should work.

Please let us know the outcome.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”
 
Of course. Whenever I try something new, the basics escape me for some reason.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top