You are on page 1of 10

Practical 1 Program 1: declare i number:=&i; n number:=1; s number:=0; begin loop dbms_output.

put_line(n); s:=s+n; n:=n+1; if (n>i) then exit; end if; end loop; dbms_output.put_line('Sum is '||s); dbms_output.put_line('Average is '||s/i); end; Output: Enter value for i: 10 old 2: i number:=&i; new 2: i number:=10; 1 2 3 4 5 6 7 8 9 10 Sum is 55 Average is 5.5 PL/SQL procedure successfully completed. Program 2: declare f integer; n integer; begin n:=&n; f:=1; for i IN 1..n

loop f:=f*i; end loop; dbms_output.put_line('fact = '|| f); end; Output: Enter value for n: 6 old 5: n:=&n; new 5: n:=6; fact = 720 PL/SQL procedure successfully completed.

Program 3: Declare r number; a number(4,2); n number:= &n; Begin r:=1; while (r<=n) loop a:=3.14*r*r; Dbms_output.put_line('Radius is '|| r ||' then Area of Circle is '||a); r:=r+1; end loop; end; Output: Enter value for n: 8 old 4: n number:= &n; new 4: n number:= 8; Radius is 1 then Area of Circle is 3.14 Radius is 2 then Area of Circle is 12.56 Radius is 3 then Area of Circle is 28.26 Radius is 4 then Area of Circle is 50.24 Radius is 5 then Area of Circle is 78.5 Radius is 6 then Area of Circle is 113.04 Radius is 7 then Area of Circle is 153.86

Radius is 8 then Area of Circle is 200.96 PL/SQL procedure successfully completed.

Program 4:

Declare n1 number(3):=&n1; n2 number(3):=&n2; choice varchar(3):='&choice'; begin case choice when 'add' then dbms_output.put_line ('addition='||n1+n2); when 'sub' then dbms_output.put_line ('subtraction='|| n1-n2); when 'mul' then dbms_output.put_line ('Multiplication='|| n1*n2); when 'div' then dbms_output.put_line ('Division='|| n1/n2); when 'rem' then dbms_output.put_line ('Remainder='||n1 mod n2); else dbms_output.put_line ('invalid choice'); end case; end; Output: Enter value for n1: 15 old 2: n1 number(3):=&n1; new 2: n1 number(3):=15; Enter value for n2: 3 old 3: n2 number(3):=&n2; new 3: n2 number(3):=3; Enter value for choice: rem old 4: choice varchar(3):='&choice'; new 4: choice varchar(3):='rem'; Remainder=0 PL/SQL procedure successfully completed.

Program 5: SQL> Create table employee 2 (empno varchar(5) primary key, 3 empname varchar(10), 4 empaddr varchar(10), 5 empdesig varchar(10), 6 empSalary number(5)); Table created.

PL/SQL code: declare vno varchar(5); vname varchar(10); vadddr varchar(10); vdesig varchar(10); vsalary number(5); cursor c1 is select * from employee; begin open c1; fetch c1 into vno, vname, vadddr, vdesig, vsalary; if c1%notfound then dbms_output.put_line('no entey'); end if; loop fetch c1 into vno, vname, vadddr, vdesig, vsalary; exit when c1%notfound; dbms_output.put_line(vno||'==='||vname||'==='||vadddr||'==='||vdesig||'==='||vsalary); end loop; close c1; end;

Output:

SQL> @prac1.5 27 / no entey

SQL> select * from employee; EMPNO EMPNAME EMPADDR EMPDESIG EMPSALARY ----- ---------- ---------- ---------- ---------101 Riyaz raigad Developer 9500 102 Furkan Madanpura Accountent 7500 103 Huzeafa madanpura Maneger 13500 104 Abdul to taki Progremmar 11500 105 Sarfaraz deegi Accountent 4500

Output: SQL> @ prac1.5 26 / 102===Furkan===Madanpura===Accountent===7500 103===Huzeafa===madanpura===Maneger===13500 104===Abdul===to taki===Progremmar===11500 105===Sarfaraz===deegi===Accountent===4500 PL/SQL procedure successfully completed.

Program 6: declare vno employee.empno%type; vname employee.empname%type; vadddr employee.empaddr%type; vdesig employee.empdesig%type; vsalary employee.empSalary%type; cursor c1 is select * from employee; cursor c2 is select * from employee; begin open c1; fetch c1 into vno, vname, vadddr, vdesig, vsalary; if c1%notfound then dbms_output.put_line('no record inserted');

end if; loop fetch c1 into vno, vname, vadddr, vdesig, vsalary; exit when c1%notfound; dbms_output.put_line(vno||'==='||vname||'==='||vadddr||'==='||vdesig||'==='||vsalary); end loop; dbms_output.put_line(''); dbms_output.put_line(''); dbms_output.put_line('record inserted'); insert into employee values('106','salim','dadar','deeler',7300); close c1; dbms_output.put_line(''); dbms_output.put_line(''); open c2; loop fetch c2 into vno, vname, vadddr, vdesig, vsalary; exit when c2%notfound; dbms_output.put_line(vno||'==='||vname||'==='||vadddr||'==='||vdesig||'==='||vsalary); end loop; close c2; end;

Output:

SQL> @ prac1.6 56 / 102===Furkan===Madanpura===Accountent===7500 103===Huzeafa===madanpura===Maneger===13500 104===Abdul===to taki===Progremmar===11500 105===Sarfaraz===deegi===Accountent===4500 record inserted 101===Riyaz===raigad===Developer===9500 102===Furkan===Madanpura===Accountent===7500 103===Huzeafa===madanpura===Maneger===13500 104===Abdul===to taki===Progremmar===11500 105===Sarfaraz===deegi===Accountent===4500 106===salim===dadar===deeler===7300 PL/SQL procedure successfully completed.

Program 7: declare vno employee.empno%type :='&vno'; vname employee.empname%type; vadddr employee.empaddr%type; vdesig employee.empdesig%type; vsalary employee.empSalary%type; cursor c1 is select * from employee where empno= vno; begin open c1; fetch c1 into vno, vname, vadddr, vdesig, vsalary; if c1%notfound then dbms_output.put_line('no record found'); end if; if vsalary > 10000 then delete from employee where empno= vno; dbms_output.put_line('record deleted'); elsif vsalary > 5000 AND vsalary < 10000 then dbms_output.put_line(vno||'==='||vname||'==='||vadddr||'==='||vdesig||'==='||vsalary); dbms_output.put_line('record displayed'); elsif vsalary < 5000 then update employee set empsalary=empsalary + (empsalary *0.10)where empno= vno; dbms_output.put_line('record updated'); else dbms_output.put_line('not proper entry'); end if; close c1; end; Output: SQL> select * from employee; EMPNO EMPNAME EMPADDR EMPDESIG EMPSALARY ----- ---------- ---------- ---------- ---------101 Riyaz raigad Developer 9500 102 Furkan Madanpura Accountent 7500 103 Huzeafa madanpura Maneger 13500 104 Abdul to taki Progremmar 11500 105 Sarfaraz deegi Accountent 4500 106 salim dadar deeler 7300 6 rows selected.

Output: SQL> @ prac1.7 38 / Enter value for vno: 101 old 2: vno employee.empno%type :='&vno'; new 2: vno employee.empno%type :='101'; 101===Riyaz===raigad===Developer===9500 record displayed PL/SQL procedure successfully completed. Output: SQL> @ prac1.7 38 / Enter value for vno: 104 old 2: vno employee.empno%type :='&vno'; new 2: vno employee.empno%type :='104'; record deleted PL/SQL procedure successfully completed. SQL> select * from employee; EMPNO EMPNAME EMPADDR EMPDESIG EMPSALARY ----- ---------- ---------- ---------- ---------101 Riyaz raigad Developer 9500 102 Furkan Madanpura Accountent 7500 103 Huzeafa madanpura Maneger 13500 105 Sarfaraz deegi Accountent 4500 106 salim dadar deeler 7300

Output: SQL> @ prac1.7 38 / Enter value for vno: 105 old 2: vno employee.empno%type :='&vno'; new 2: vno employee.empno%type :='105'; record updated PL/SQL procedure successfully completed.

SQL> select * from employee EMPNO EMPNAME EMPADDR EMPDESIG EMPSALARY ----- ---------- ---------- ---------- ---------101 Riyaz raigad Developer 9500 102 Furkan Madanpura Accountent 7500 103 Huzeafa madanpura Maneger 13500 105 Sarfaraz deegi Accountent 4950 106 salim dadar deeler 7300

Program 8: declare vno employee.empno%type:='&vno'; vname employee.empname%type; vadddr employee.empaddr%type; vdesig employee.empdesig%type; vsalary employee.empSalary%type; cursor c1 is select * from employee where empno=vno; begin open c1; fetch c1 into vno, vname, vadddr, vdesig, vsalary; if c1%notfound then dbms_output.put_line('no record found'); end if; dbms_output.put_line(''); dbms_output.put_line(''); dbms_output.put_line(' vno vname vadddr vdesig vsalary '); dbms_output.put_line(vno||'==='||vname ||'==='||vadddr||'==='||vdesig||'==='|| vsalary); close c1; end; Output: SQL> @ prac1.8 35 / Enter value for vno: 101 old 2: vno employee.empno%type:='&vno'; new 2: vno employee.empno%type:='101'; vno vname vadddr vdesig vsalary 101===Riyaz===raigad===Developer===9500

PL/SQL procedure successfully completed.

You might also like