0% found this document useful (0 votes)
9 views10 pages

(1)

The document contains various PL/SQL programs and blocks that demonstrate different functionalities such as calculating the sum of odd numbers, finding factorials, printing Fibonacci series, checking for vowels, and managing employee data. It also includes procedures and functions for mathematical operations, swapping numbers, and error handling with exceptions. Additionally, it showcases the creation of tables, sequences, and triggers for updating employee salaries.

Uploaded by

freewatch077
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

(1)

The document contains various PL/SQL programs and blocks that demonstrate different functionalities such as calculating the sum of odd numbers, finding factorials, printing Fibonacci series, checking for vowels, and managing employee data. It also includes procedures and functions for mathematical operations, swapping numbers, and error handling with exceptions. Additionally, it showcases the creation of tables, sequences, and triggers for updating employee salaries.

Uploaded by

freewatch077
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

1.write a pl/sql program to display the sum of first 10 odd numbers.

declare

i int:=1;

total int:=0;

begin

while i<=19 loop

total:=total+i;

i:=i+2;

end loop;

dbms_output.put_line(‘sum: ’ ||total);

end;

4.write a pl/sql block to find the factorial of a number.

declare

n1 int:=13;

factorial int:=1;

begin

while n1>0 loop

factorial:=factorial*n1;

n1:=n1-1;

end loop;

dbms_output.put_line(‘Factorial ’ ||factorial);

end;

7.write a pl/sql block to print the Fibonacci series up to 10.

declare

a int:=0;

b int:=1;

c int;

begin

dbms_output.put_line(‘Fibonacci Series’);
dbms_output.put_line(a);

dbms_output.put_line(b);

while a+b<10 loop

c:=b;

b:=a+b;

dbms_output.put_line(b);

a:=c;

end loop;

end;

4.Write a pl/sql to check weather the character entered is a vowel or not.

declare

a char(1):=’&a’;

begin

case a

when ‘a’ then dbms_output.put_line(‘This alphabet is a vowel’);

when ‘e’ then dbms_output.put_line(‘This alphabet is a vowel’);

when ‘i’ then dbms_output.put_line(‘This alphabet is a vowel’);

when ‘o’ then dbms_output.put_line(‘This alphabet is a vowel’);

when ‘u’ then dbms_output.put_line(‘This alphabet is a vowel’);

when ‘A’ then dbms_output.put_line(‘This alphabet is a vowel’);

when ‘E’ then dbms_output.put_line(‘This alphabet is a vowel’);

when ‘I’ then dbms_output.put_line(‘This alphabet is a vowel’);

when ‘O’ then dbms_output.put_line(‘This alphabet is a vowel’);

when ‘U’ then dbms_output.put_line(‘This alphabet is a vowel’);

else dbms_output.put_line(‘this alphabet is not a vowel’);

end case;

end;

3.create table emp_rich(empid int primary key,name varchar(20),salary int);

insert into emp_rich values(1100,’elon mask’,30000);


insert into emp_rich values(1200,’larry Ellison’,8000);

insert into emp_rich values(3300,’warren buffet’,4000);

declare

empno int;

sal int;

begin

empno:=&empno;

select salary into sal from emp_rich where empid=empno;

if sal>10000 then

dbms_output.put_line(‘salary is ‘’high’ ’ .’);

elsif sal>=5000 and sal<=10000 then

dbms_output.put_line(‘salary is moderate’ ‘.’);

elsif sal<5000 then

dbms_output.put_line(‘salary is ‘ ’ low’ ‘ .’);

end if;

end;

2. write a sequence as 10,20,30….100 and bind it with the table product(product no,productname)

create sequence ps

start with 10

maxvalue 100

increment by 10;

//sequence created

create table product(productno int,product_name varchar(10));

insert into product values(ps.nextval,’Apple’);

insert into product values(ps.nextval,’Google’);

insert into product values(ps.nextval,’samsung’);

insert into product values(ps.nextval,’Alibaba’);

insert into product values(ps.nextval,’IBM’);


select * from product;

3.write a sequence with maximum value is 40 and is incremented by 4,starts with 1 and forming a
cycle.

create sequence abc

start with 1

maxvalue 40

increment by 4

cycle

cache 10;

sequence created.

2.crete procedure to display the square of a number.

create procedure squ(a in out int)

as

begin

dbms_output.put_line(A*A);

end;

declare

A int:=12;

begin

squ(A);

end;

7.write a pl/sql block to print greatest among three numbers.

declare

a int:=4;

b int:=10;
c int:=8;

begin

if a>b and a>c then

dbms_output.put_line(‘a is greater than b,c.’);

elsif b>a and b>c then

dbms_output.put_line(‘b is greater than a,c.’);

else

dbms_output.put_line(‘c is greater than a,b’);

end if;

end;

2)write a pl/sql block using cursor to display the employee names and their salaries till the record is
found using while loop.

declare

cursor c2 is select * from emp;

erec emp%rowtype;

begin

open c2;

fetch c2 into erec;

while c2%found loop

dbms_output.put_line(erec.ename||’ ‘||erec.sal);

fetch c2 into erec;

end loop;

close c2;

end;

create procedure squ(a in out int)

as

begin

dbms_output.put_line(A*A);

end;
/

declare

A int:=12;

begin

squ(A);

end;

7.write a pl/sql block to print greatest among three numbers.

declare

a int:=4;

b int:=10;

c int:=8;

begin

if a>b and a>c then

dbms_output.put_line(‘a is greater than b,c.’);

elsif b>a and b>c then

dbms_output.put_line(‘b is greater than a,c.’);

else

dbms_output.put_line(‘c is greater than a,b’);

end if;

end;

3.create a procedure to swap two numbers.

create or replace procedure swap(a in out int,B in out int)

as

c int;

begin

c:=A;
A:=B;

B:=c;

DBMS_output.put_line(‘A is now: ’ ||A);

dbms_output.put_line(‘B is now: ’ ||B);

end;

declare

A int:=12;

B int:=24;

begin

swap(A,B);

end;

1. create a function to display the square of a number.

create function func1

return int

as

a int :=24;

begin

return a*a;

end;

select func1 from dual;

2.create a function to swap two numbers.

create or replace function func2

return varchar

as

a int:=24;

b int:=32;
c int;

begin

a:=a;

c:=a;

a:=b;

b:=c;

return(‘A is now: ‘||A||’ ’||’and b is now: ’||b);

end;

7.create a function to find the minimum among two numbers.

create or replace function fmin(x number,y number)

return number

as

z number;

begin

if(x<y) then

return x;

else

return y;

end if;

end;

select fmin(2,3) from dual;

4.create a trigger to update the salary of employees and to show the old salary,new salary and the
difference.

create or replace trigger trg_diff

after update

on emps
for each row

begin

dbms_output.put_line(‘old salary: ’||:old salary: ‘||:new salary||’difference: ’ ||(:new


salary-:old.salary));

trigger created.

update emps

set salary=4000

where name=’DEF’;

old salary:5000 new salary: 4000 difference:- 1000

4.write a pl/sql block to raise an exception when divisor is 0.

declare

a int:=&a;

b int:=&b;

ans int;

zd exception;

begin

if b=0 then

raise zd;

end if;

ans:=a/b;

dbms_output.put_line(ans);

exception

when zd then

dbms_output.put_line(‘b must be >0.’);

end;

You might also like