If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Is there any difference??

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
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;
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 7,597
>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.
Don't say, show. Don't promise, prove.
Reply With Quote
  #3 (permalink)  
Old
Lead Application Develope
 
Join Date: Jun 2004
Location: Liverpool, NY USA
Posts: 2,415
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.
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Nov 2003
Posts: 2,806
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
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
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 ?
Reply With Quote
  #6 (permalink)  
Old
Lead Application Develope
 
Join Date: Jun 2004
Location: Liverpool, NY USA
Posts: 2,415
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.
Reply With Quote
  #7 (permalink)  
Old
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On