PLSQL
PLSQL
FACTORIAL
declare
n number(3);
fact number(20);
i number(2);
begin
fact:=1;
n:='&num';
if(n<=21)
then
for i in 1..n
loop
fact:=fact*i;
end loop;
DBMS_OUTPUT.PUT_LINE('FACTORIALOF THE GIVEN NUMBER: '||fact);
else
DBMS_OUTPUT.PUT_LINE('INPUT SHOULD BE GIVEN UNDER 21');
end if;
end;
2. GRADE CALCULATION
declare
n number(3);
begin
n:=&marks;
if(n>=0 and n<40)
then
DBMS_OUTPUT.PUT_LINE('GRADE: F');
elsif(n>=40 and n<50)
then
DBMS_OUTPUT.PUT_LINE('GRADE: D');
elsif(n>=50 and n<60)
then
DBMS_OUTPUT.PUT_LINE('GRADE: C');
elsif(n>=60 and n<70)
then
DBMS_OUTPUT.PUT_LINE('GRADE: B');
elsif(n>=70 and n<80)
then
DBMS_OUTPUT.PUT_LINE('GRADE: A');
elsif(n>=80 and n<90)
then
DBMS_OUTPUT.PUT_LINE('GRADE: E');
elsif(n>=90 and n<=100)
then
DBMS_OUTPUT.PUT_LINE('GRADE: O');
else
DBMS_OUTPUT.PUT_LINE('WRONG INPUT');
end if;
end;
3. REVERSE OF A STRING
declare
n varchar(10);
p varchar(10);
l number(3);
begin
n:='&old_string';
l:=length(n);
loop
t:=f+s;
f:=s;
s:=t;
DBMS_OUTPUT.PUT_LINE(t);
end loop;
end;
2ND SOLUTION
declare
n1 number(5);
n2 number(5);
n3 number(5);
i number(2);
begin
n1:=0;
n2:=1;
dbms_output.put_line('Fibonacci series upto 20 values:');
for i in 1..20
loop
dbms_output.put_line(n1);
n3:=n1+n2;
n1:=n2;
n2:=n3;
end loop;
end;
5. SALARY CALCULATION
declare
b number(10,2);
t number(10,2);
begin
b:='&basic';
DBMS_OUTPUT.PUT_LINE('hra='||(b*.6)||'da='||(b*.9));
t:=b+b*.6+b*.9+350;
DBMS_OUTPUT.PUT_LINE('Total='||t);
end;
6. PRIME NUMBER CHECK
declare
n number(8);
f number(1);
i number(8);
begin
n:='&number';
f:=0;
for i in 2..(n-1)
loop
if(mod(n,i)=0)
then f:=1;
end if;
end loop;
if(f!=0)
then dbms_output.put_line('The number is not prime');
else dbms_output.put_line('The number is prime');
end if;
end;