0% found this document useful (0 votes)
57 views

PLSQL

The document contains 6 PL/SQL code blocks that perform different calculations: 1) A factorial calculation program that calculates the factorial of a user-input number up to 21. 2) A grade calculation program that takes a mark as input and outputs the corresponding letter grade. 3) A string reversal program that reverses a user-input string. 4) A Fibonacci series program that outputs a Fibonacci series up to a user-specified number of terms. 5) A salary calculation program that calculates an employee's total salary based on their basic pay. 6) A prime number checking program that checks if a user-input number is prime.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

PLSQL

The document contains 6 PL/SQL code blocks that perform different calculations: 1) A factorial calculation program that calculates the factorial of a user-input number up to 21. 2) A grade calculation program that takes a mark as input and outputs the corresponding letter grade. 3) A string reversal program that reverses a user-input string. 4) A Fibonacci series program that outputs a Fibonacci series up to a user-specified number of terms. 5) A salary calculation program that calculates an employee's total salary based on their basic pay. 6) A prime number checking program that checks if a user-input number is prime.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

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);

for i in reverse 1..l


loop
p:=p||substr(n,i,1);
end loop;
DBMS_OUTPUT.PUT_LINE('NEW STRING: '||P);
end;
4. FIBONACCI SERIES
declare
n number(10);
t number(10);
s number(10);
f number(10);
begin
n:='&term';
DBMS_OUTPUT.PUT_LINE('0'||'1');
f:=0;
s:=1;
for i in 3..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;

You might also like