Posts Oracle plsql Part 4
Post
Cancel

Oracle plsql Part 4

  • control statement if ,elsif, else, end if
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

declare
	mrec rahul_emp%rowtype;
	mempno rahul_emp.EMPNO%type;
	service_years number;
begin
	 mempno:=&empNoInput;
	 select * into mrec from rahul_emp where empno = mempno;
	 service_years:=trunc(months_between(sysdate,mrec.hiredate)/12);
	 
	 if service_years >25 then
	 	mrec.sal:=mrec.sal+(mrec.sal*.2);
	 elsif service_years >23 then
	 	mrec.sal:=mrec.sal+(mrec.sal*.15);
	 else	
		mrec.sal:=mrec.sal+(mrec.sal*.02);
	 end if;	
	 
	 dbms_output.put_line(' the reveised salary of employee '||mrec.ename||' is '||mrec.sal ||' job= '||mrec.job);
exception
     when no_data_found then
	 dbms_output.put_line('no such employee found');
end;	

  • Exercise on if elsif else
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

declare
	mrec rahul_emp%rowtype;
	mempno rahul_emp.EMPNO%type;
begin
	 mempno:=&empNoInput;
	 select * into mrec from rahul_emp where empno = mempno;
	 if mrec.sal >4500 then
	 	mrec.sal:=mrec.sal+(mrec.sal*.30);
	 elsif mrec.sal >2500 and mrec.sal <=4500then
	 	mrec.sal:=mrec.sal+(mrec.sal*.20);
	 else
		mrec.sal:=mrec.sal+(mrec.sal*.10);
	 end if;	
	 dbms_output.put_line(' the reveised salary with bonus of employee '||mrec.ename||' is '||mrec.sal ||' job= '||mrec.job);
exception
     when no_data_found then
	 dbms_output.put_line('no such employee found');
end;	

This post is licensed under CC BY 4.0 by the author.