Home » SQL & PL/SQL » SQL & PL/SQL » Using decode
Using decode [message #1606] Wed, 15 May 2002 20:27 Go to next message
Dave
Messages: 92
Registered: August 1999
Member
I need help with something. I am just trying to figure out how to give a 10%raise to employees who have been with a company for one year or more.
This is what I have, what am I missing?
select ename "Name",sal "Salary",
DECODE(months_betweensysdate,hiredate),'',sal*1.10, sal)
New_Salary
from emp
Re: Using decode [message #1608 is a reply to message #1606] Wed, 15 May 2002 21:51 Go to previous messageGo to next message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
Your select should read:

The sign function determines whether there are more months between sysdate and hiredate than 120. If so, the decode will replace the salary by salary * 1.1SELECT ename "Name"
, sal "Salary"
, DECODE(sign(months_between(sysdate, hiredate)-120), +1,sal*1.1,sal) New_Salary
FROM emp

But, you're only performing a select, you're not doing an actual update. I believe that, to give a raise, you should do an update.

HTH,
MHE
Re: Using decode [message #1617 is a reply to message #1606] Thu, 16 May 2002 02:37 Go to previous message
Dave
Messages: 92
Registered: August 1999
Member
Thank you! That helped a great deal!
Previous Topic: substring and host variable
Next Topic: IN and OUT parameters
Goto Forum:
  


Current Time: Tue Apr 23 00:29:33 CDT 2024