Home » SQL & PL/SQL » SQL & PL/SQL » First time user (Merged 3)
icon5.gif  First time user (Merged 3) [message #399142] Mon, 20 April 2009 21:22 Go to next message
sagarkhushalani
Messages: 7
Registered: April 2009
Junior Member
I'm using Oracle for the first time. We have to create triggers and I tried this but its not working (error is trigger was created with compilation errors).

CREATE TRIGGER T1
AFTER INSERT ON EMPLOYEE
BEGIN
IF (NEW.JOBTYPE == 'S') THEN
INSERT INTO SECRETARY (SSN) VALUES (:NEW.SSN);
ELSE
IF (NEW.JOBTYPE == 'T') THEN
INSERT INTO TECHNICIAN (SSN) VALUES (:NEW.SSN);
ELSE
IF (NEW.JOBTYPE == 'E') THEN
INSERT INTO ENGINEER (SSN) VALUES (:NEW.SSN);
END IF;
END IF;
END IF;
END T1;
/


What am I doing wrong? Sorry if it's a stupid mistake, noob here Confused ...
Re: First time user [message #399146 is a reply to message #399142] Mon, 20 April 2009 22:01 Go to previous messageGo to next message
danish_fsd@yahoo.com
Messages: 38
Registered: February 2008
Location: Pakistan
Member
All "NEW" keyword should be with colon ":" sign.
Also place only "=" operator instead of "==" in IF condition.

Regards
Danish
Re: First time user [message #399147 is a reply to message #399142] Mon, 20 April 2009 22:04 Go to previous messageGo to next message
BlackSwan
Messages: 25036
Registered: January 2009
Location: SoCal
Senior Member
You need to help us by following the Posting Guidelines as stated below.
http://www.orafaq.com/forum/t/88153/0/
Please, please, please Read & Follow Posting Guidelines above.
Go to the section labeled "Practice" & do as directed.
Re: First time user [message #399152 is a reply to message #399146] Mon, 20 April 2009 22:53 Go to previous messageGo to next message
sagarkhushalani
Messages: 7
Registered: April 2009
Junior Member
Thank you! Worked like a charm Smile
Re: First time user (Merged 3) [message #399154 is a reply to message #399142] Mon, 20 April 2009 22:59 Go to previous messageGo to next message
BlackSwan
Messages: 25036
Registered: January 2009
Location: SoCal
Senior Member
CREATE TRIGGER t1 
  AFTER INSERT ON employee 
BEGIN 
  IF (:NEW.jobtype = 'S') THEN 
    INSERT INTO secretary 
               (ssn) 
    VALUES     (:NEW.ssn); 
  ELSE 
    IF (:NEW.jobtype = 'T') THEN 
      INSERT INTO technician 
                 (ssn) 
      VALUES     (:NEW.ssn); 
    ELSE 
      IF (:NEW.jobtype = 'E') THEN 
        INSERT INTO engineer 
                   (ssn) 
        VALUES     (:NEW.ssn); 
      END IF; 
    END IF; 
  END IF; 
END t1; 
/
Re: First time user (Merged 3) [message #399159 is a reply to message #399154] Mon, 20 April 2009 23:23 Go to previous messageGo to next message
sagarkhushalani
Messages: 7
Registered: April 2009
Junior Member
Thanks Smile and sorry about the triple posting - I'm not sure how that happened. I've read the guidelines.
Re: First time user (Merged 3) [message #399160 is a reply to message #399142] Mon, 20 April 2009 23:25 Go to previous message
BlackSwan
Messages: 25036
Registered: January 2009
Location: SoCal
Senior Member
>I'm not sure how that happened
You clicked POST multiple times without checking for results.
Previous Topic: union error
Next Topic: index in date filed
Goto Forum:
  


Current Time: Sun Dec 04 20:54:08 CST 2016

Total time taken to generate the page: 0.15671 seconds