Update statements in Query
I have one query,
Update the salary of the employees
who has finished one year service with the company by 10% and who has service
less than 1 yr with the company by only 5%.
Thesre are basically two Update
statements in your Query:
1. Update the salary of the employees
who has finished one year service with the company by 10%
Ans:
update table employee set salary
= (salary + 0.10*salary) where (to_number(to_char(sysdate,'YYYY'))
- to_number(to_char(hiredate,'YYYY')))
> 1
/
2. and who has service less than
1 yr with the company by only 5%
Ans:
Update table employee set salary
= (salary + 0.05*salary) where (to_number(to_char(sysdate,'YYYY'))
- to_number(to_char(hiredate,'YYYY')))
< 1
/
I think this is what you needed
else revert me back.
Petro.
Use Decode or Case to
solve this problem
Naren
Give this inside a loop
{
UPDATE empincrement
SET salincrement =
(
SELECT decode(doj - sysdate >=1 ,sal*.10, sal*.05)
FROM emp
);
}
end loop
This is the way I have tried to
solve this, but in the below part
doj - sysdate >=1 , its giving
an error like right paranthesis missing.
C.Ashok
Use this query in your loop.
update emp
set sal=
(SELECT case when (hiredate - sysdate)
>=1 then
sal*.10 else sal*.05 end
FROM emp)
Dhaval Lade
Have a Oracle Question
Do
you have an Oracle Question?
Oracle Books
Oracle
Certification, Database Administration, SQL, Application, Programming Reference
Books
Oracle Application
Oracle
Application Hints and Tips
Oracle Home
Oracle
Database, SQL, Application, Programming Tips
All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
All product names are trademarks of their respective
companies.
The site www.erpgreat.com is not affiliated with or endorsed
by any company listed at this site.
Every effort is made to ensure the content integrity.
Information used on this site is at your own risk.
The content on this site may not be reproduced
or redistributed without the express written permission of
www.erpgreat.com or the content authors.
|