Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2013
    Posts
    21

    Is there any difference??

    is there executional difference between the following two statements.im going to use this in before update tirgger.

    i want to preupdate employees table before update for each row..which one should i use ?? can some1 explain me in detail ..thankss

    IF NVL(new.emp_updatecount, 0 ) = NVL(old.emp_updatecount, 0 ) THEN
    :new.emp_updatecount := NVL(old.emp_updatecount, 0 ) + 1;


    IF NVL(new.emp_updatecount, -1 ) = NVL(old.emp_updatecount, -1 ) THEN
    new.emp_updatecount := NVL(old.emp_updatecount, -1 ) + 1;

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,622
    >which one should i use ??
    use neither since neither is valid syntax
    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.
    There are no stupid questions, but there are a LOT of Inquisitive Idiots.

  3. #3
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,427
    I have not Idea why you are checking the emp_updateout but the correct syntax is

    Code:
    IF NVL(:new.emp_updatecount, -1 ) = NVL(:old.emp_updatecount, -1 ) THEN
                 :new.emp_updatecount := NVL(:old.emp_updatecount, -1 ) + 1;
    end if;
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  4. #4
    Join Date
    Nov 2003
    Posts
    2,817
    This
    Code:
    :new.emp_updatecount := NVL(:old.emp_updatecount, -1 ) + 1;
    would set the column from NULL to zero.

    My guess(!) is, that this value is expected to be 1 if nothing was recorded before. So it should proably be done like this
    Code:
    :new.emp_updatecount := NVL(:old.emp_updatecount, 0 ) + 1;
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags: http://www.dbforums.com/misc.php?do=bbcode#code

    Tips for good questions:

    http://tkyte.blogspot.de/2005/06/how...questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

  5. #5
    Join Date
    Jan 2013
    Posts
    21
    Quote Originally Posted by beilstwh View Post
    I have not Idea why you are checking the emp_updateout but the correct syntax is

    Code:
    IF NVL(:new.emp_updatecount, -1 ) = NVL(:old.emp_updatecount, -1 ) THEN
                 :new.emp_updatecount := NVL(:old.emp_updatecount, -1 ) + 1;
    end if;

    i would appreciate your help.. im thinking is there any difference if i set NULL value to 0 other than -1 ?? or both the same ?

  6. #6
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,427
    If all you are counting is how many times the row is updated then simply use the assignment line. No need for the if then atatement

    Code:
     :new.emp_updatecount := NVL(:Old.emp_updatecount, 0 ) + 1;
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  7. #7
    Join Date
    Jan 2013
    Posts
    21
    Quote Originally Posted by beilstwh View Post
    If all you are counting is how many times the row is updated then simply use the assignment line. No need for the if then atatement

    Code:
     :new.emp_updatecount := NVL(:Old.emp_updatecount, 0 ) + 1;

    thank you very much for your help

Posting Permissions

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