Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Monday, March 17, 2008

Questions and Answers 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'))) <>
/

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.


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)

No comments:

Post a Comment

Archives