Results 1 to 11 of 11

Thread: Triggers

  1. #1
    Join Date
    Apr 2010
    Posts
    11

    Question Unanswered: Triggers

    HI I HAVE THIS TABLES

    CREATE TABLE "CRU"
    (
    "CRUID" NUMBER(10),
    "NAME" VARCHAR2(20),
    "DURATION" NUMBER(2)

    );
    CREATE TABLE voy
    (
    voyage_id NUMBER(10) ,
    startdate DATE NOT NULL,
    cruise_id NUMBER(10) NOT NULL CONSTRAINT fk_cruise_id REFERENCES cru(cruId),
    );


    THEY HAVE THIS DATA
    INSERT INTO CRU VALUES(1,'TESTING CRUISE',5);
    INSERT INTO CRU VALUES(2,'TESTIN 2',3);

    THE VOY TABLE DOES NOT HAVE VALUES YET

    I WANT TO CREATE SOME TRIGGERS SO IF SOMEONE
    TRYS TO INSERT INTO TABLE VOY
    AND THE DURATION OF THE CRU IS 5 DAYS AND THE START DATE IS IN NOVEMBER TO THROW ERROR AND SAY 'YOU CANNOT RUN A CRU IN NOVEMBER'

    IF SOMEONE CAN PLEASE HELP ME

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >IF SOMEONE CAN PLEASE HELP ME

    When are you going to start doing your own homework assignments?
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Apr 2010
    Posts
    11
    i am doing my own assessment
    i just need help

    is it bad to ask for help if you try and cannot do it?

  4. #4
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >i am doing my own assessment

    I have not see any evidence above is true

    >i just need help
    Perhaps you should drop this course if are incapable of completing assignments

    >is it bad to ask for help if you try and cannot do it?
    use sqlplus along with CUT & PASTE.

    show us your code.
    Post only 100% correct syntax code

    If you can not produce correct syntax using the Fine Manual, you'll never get a working solution.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  5. #5
    Join Date
    Apr 2010
    Posts
    11
    i dont know why you attack me, and you are not polite
    if you dont want to help
    i will kindly ask you to to mind your own business
    if you were at my place i was going to help you
    and you dont have the right to call me incapable you dont know who i am
    and what are my condition

    the only sytax mistake i did is at the , at the end of the creation of the second table

  6. #6
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >I WANT TO CREATE SOME TRIGGERS

    show us your code.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  7. #7
    Join Date
    Apr 2010
    Posts
    11
    CREATE OR REPLACE TRIGGER restriction BEFORE INSERT OR UPDATE ON voy FOR EACH ROW BEGIN IF (TO_CHAR(:NEW.startdate, 'MONTH') ='NOVEMBER') THEN RAISE_APPLICATION_ERROR('cannot run 5 days in november'); END IF; END;

    i dont know how to check if the duration is 5 days and this code is not working because it allows inserts and updates

  8. #8
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Code:
    CREATE OR replace TRIGGER restriction
      before INSERT OR UPDATE ON voy
      FOR each ROW
    BEGIN
        IF ( To_char(:NEW.startdate, 'MONTH') = 'NOVEMBER' ) THEN
          Raise_application_error('cannot run 5 days in november');
        END IF;
    END;
    >i dont know how to check if the duration is 5 days
    SELECT DURATION FROM CRU ......
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  9. #9
    Join Date
    Apr 2010
    Posts
    11
    i try this code but when i try to insert
    like insert into voy values (1,'12-nov-2010',1); it allows me insert it
    but it supose to throw the error
    from the book im studing it shows the code is the same like i have here but it does not work

  10. #10
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    SQL> select To_char(to_date('12-NOV-2010','DD-MON-YYYY'), 'MONTH') from dual;

    TO_CHAR(T
    ---------
    NOVEMBER
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  11. #11
    Join Date
    Mar 2007
    Posts
    623
    Quote Originally Posted by cystavros View Post
    i try this code but when i try to insert
    like insert into voy values (1,'12-nov-2010',1); it allows me insert it
    but it supose to throw the error
    from the book im studing it shows the code is the same like i have here but it does not work
    Maybe you should read about DATE format models in SQL Reference book, available with other Oracle documentation e.g. online on http://tahiti.oracle.com/:
    MONTH
    Name of month, padded with blanks to display width of the widest name of month in the date language used for this element.
    Code:
    SQL> select '>'||to_char(to_date('12-NOV-2010','DD-MON-YYYY'), 'MONTH')||'<' month1,
      2         '>'||to_char(to_date('12-NOV-2010','DD-MON-YYYY'), 'fmMONTH')||'<' month2
      3  from dual;
    
    MONTH1      MONTH2
    ----------- ----------
    >NOVEMBER < >NOVEMBER<

Posting Permissions

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