Friday, December 27, 2019

Sum Of Series - PL/SQL

Program:

declare
n number:=&n;
i number;
begin
i:=n*(n+1);
n:i/2;
dbms_output.put_line('The sum of series is:'||n);
end;

Output:

Enter value for n; 5
The sum of series is: 15

Fibonacci - PL/SQL

Program:

declare
i number;
c number;
n number;
a number;
b number;
begin
for i in 1..n
loop
c:=a+b;
dbms_output.put_line(c);
a:=b;
b:=c;
end loop;
end

Output:

Enter valur for n; 5
0
1
1
2
3

Palindrome - PL/SQL

Program:

declare
len number;
a integer;
str1 varchar(10):='&str1';
str2 varchar(10);
begin
len:=length(str1);
a:=len;
for i in 1..a
loop
str2:=str2||substr(str1,len,1);
len:=len-1;
end loop;
if(str1=str2) then
dbms_output,put_line(str1 ||' is a palindrome');
else
dbms_output,put_line(str1 ||' not a palindrome');
end if;
end

Output1:

Enter value for str1; liril
liril is a palindrome

Output2;

Enter value for str1; faith
faith not a palindrome


Factorial Of A Number - PL/SQL

Program:

declare
f number:=1;
i number;
n number:=&n;
begin
for i in 1..n
loop
f:=f*i;
end loop;
dbms_output.put_line('The factorial of a given no is:'||f);
end;

Output:
Enter alue for n: 6
The factorial of a given n is: 720

Addition Of Two Numbers - PL/SQL

Program:

declare
x integer;
y integer;
z integer;
begin
x:=&x;
y:=&y;
z:=x+y;
dbms_output.put_line('The sum of two number is ='||z);
end;



Output:

Enter value for x: 9
Enter value for y: 9
The sum of two number is =18