Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2003
    Posts
    5

    Unanswered: Need help creating a trigger

    I have a table called Enrollment which contains StdID, CourseNumber, and EnrollGrade.
    StdID CourseNumber EnrollGrade
    101 2201 A
    101 2203 B
    102 2203 C
    103 2203 B
    103 2201 C
    103 1101 B

    I need to create a trigger that will not allow a Student to enroll in CourseNumber 2205 until they have completed 2201 and 2203. I can't figure out how to go through each StdID and see if they've taken 2201 and 2203 yet.

    Here's what I have so far:
    Create or Replace Trigger Enroll_Rule
    Before Insert on Enrollment
    For Each Row
    Begin
    --i know i need a select statement here and then and If statement.

    and now i'm totally lost. does anybody have any ideas to get me started?? Thanks a lot!

  2. #2
    Join Date
    Jul 2001
    Location
    Germany
    Posts
    189

    Try this ...

    Hello,

    try this ..

    Create or Replace Trigger Enroll_Rule
    Before Insert on Enrollment
    For Each Row

    DECLARE

    nCount PLS_INTEGER := 0;
    no_course_found EXCEPTION;

    Begin

    SELECT COUNT(1) INTO nCount
    FROM Enrollment WHERE stdid = :new.stdid
    AND CourseNumber IN (2201, 2203);

    IF nCount <> 2 THEN
    RAISE no_course_found;
    END IF;

    END;

    ... Hope that helps ?

    Best regards
    Manfred Peter
    (Alligator Company GmbH)
    http://www.alligatorsql.com

  3. #3
    Join Date
    Apr 2003
    Posts
    5
    that helped me out. Thanks a lot!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •