PL SQL Programme
PL SQL Programme
declare
n number:=&n;
begin
if mod(n,2)=0
then
dbms_output.put_line('number is even');
else
dbms_output.put_line('number is odd');
end if;
end;
/
2.Write a PL/SQL block for insertion into table EMPDET table with the following.
Calculations:
DECLARE
eno number;
ename varchar2(20);
deptno number;
basic number;
HRA number(10,2);
DA number(10,2);
PF number(10,2);
NETPAY number(10,2);
BEGIN
eno := &eno;
ename:=&ename;
deptno:=&deptno;
basic := &basic;
HRA := 0.5 * basic;
DA := 0.2 * basic;
PF := 0.07 * basic;
netpay := basic + hra + da + pf;
insert into empdet values (eno,ename,deptno,basic,hra,da,pf,netpay);
END;/
3.Write a PL/SQL block that will accept student id number from the user, and
check is student attendance is less than 80% then display message that student
cannot appear in exam.
DECLARE
xstud_id number(5);
xstud_att number(5);
xtotal_days number(3):=200;
BEGIN
xstud_id:=&xstud_id;
select stud_att into xstud_att from student where stud_id=xstud_id;
IF(xstud_att<(xtotal_days*0.80))
THEN
dbms_output.put_line('This student can not attend exam');
ELSE
dbms_output.put_line('This student can attend exam');
END IF;
END;
/
PL/SQL Program for Fibonacci Series
declare
first number:=0;
second number:=1;
third number;
n number:=&n;
i number;
begin
dbms_output.put_line('Fibonacci series is:'); dbms_output.put_line(first);
dbms_output.put_line(second);
for i in 2..n
loop
third:=first+second;
first:=second;
second:=third;
dbms_output.put_line(third);
end loop;
end;
/