The document contains code snippets that update employee salary records in a database table based on certain conditions. The snippets use SQL queries, variable declarations, IF/CASE statements, and loops to select employee data, check salary amounts, calculate bonuses, and update salaries accordingly.
5. Code
Begin
declare c anchor empPr.salary;
select salary into c from empPr where id=2;
if(c>40000) then
update empPr set salary=c+1000 where
id=2;
end if;
end
6.
7.
8.
9.
10. Code
begin
declare c anchor empPr.salary;
select salary into c from empPr where id=2 ;
if(c>40000) then
update empPr set salary=c+1000 where id=2;
else
update empPr set salary=c+500 where id=2;
end if;
end ;
11.
12.
13.
14.
15.
16.
17.
18. Code
begin
declare c anchor empPr.salary;
declare bonus int;
select salary into c from empPr where id=2 ;
case c
when 50000 then
set bonus=c+1000;
when 30000 then
set bonus=c+500;
else
set bonus=c;
end case;
update empPr set salary=bonus where id=2;
end ;
19.
20.
21.
22.
23.
24. Code
begin
declare c anchor empPr.salary;
declare bonus int;
select salary into c from empPr where id=2 ;
case
when C<=40000 then
set bonus=c+500;
when c<=50000 then
set bonus=c+1000;
else
set bonus=c+2000;
end case;
update empPr set salary=bonus where id=2;
end ;
25.
26.
27.
28.
29.
30.
31.
32.
33.
34. Code
create type emp as row anchor row of empPr;
BEGIN
declare e1 emp;
L:
for e1 as select * from empPr DO
if( e1.salary < 30000) THEN
Iterate L;
end if;
update empPr set salary=e1.salary+1000
where id=e1.id;
end for L;
END;
35.
36.
37. Code
create type e1 as row anchor row of empPr;
BEGIN
declare total_sal int;
set total_sal = 0;
ADD :
for e1 as select * from empPr DO
Set total_sal=total_sal+e1.salary;
if( total_sal >100000)
leave ADD:
end if;
end for ADD;
END;