0% found this document useful (0 votes)
15 views2 pages

DBMSPLSQL

Uploaded by

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

DBMSPLSQL

Uploaded by

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

=====================================

write a program to print sum of n number of odd number


=====================================
SQL> declare
2 add number:=0;
3 n number:=&n;
4 begin
5 for a in 1..(2*n) loop
6 if mod(a,2) = 1 then
7 add := add + a;
8 end if;
9 end loop;
10 dbms_output.put_line(add);
11 end;
12 /
=====================================
----------------------------------
=====================================
write a program to print sum of odd number from 1 to n number or upto n number
=====================================
SQL> declare
2 add number:=0;
3 n number:=&n;
4 begin
5 for a in 1..n loop
6 if mod(a,2)=1 then
7 add := add + a;
8 end if;
9 end loop;
10 dbms_output.put_line(add);
11 end;
12 /
=====================================
----------------------------------
=====================================
write a program to print numbers from 10 to 1 in reverse order
=====================================
SQL> set serveroutput on;
SQL> declare
2 n number:=10;
3 begin
4 while n>0 loop
5 dbms_output.put_line(n);
6 n:=n-1;
7 end loop;
8 end;
9 /
=====================================
----------------------------------
=====================================
print n number of even number
=====================================
SQL> declare
2 n number:=&n;
3 begin
4 for a in 1..n loop
5 if mod(a,2)=0 then
6 dbms_output.put_line(a);
7 end if;
8 end loop;
9 end;
10 /
=====================================
----------------------------------
=====================================
Write a PL/SQL program to calculate factorial of a given number.
=====================================
---------------
using for loop
---------------
SQL> set serveroutput on;
SQL> declare
2 n number:=&n;
3 fact number:=1;
4 begin
5 for i in 1..n loop
6 fact := fact * i;
7 end loop;
8 dbms_output.put_line('Factorial = '||fact);
9 end;
10 /
-----------------
using while loop
-----------------
SQL> set serveroutput on;
SQL> declare
2 n number:=&n;
3 fact number:=1;
4 begin
5 while n!=0 loop
6 fact := fact*n;
7 n:=n-1;
8 end loop;
9 dbms_output.put_line('Factorial = '||fact);
10 end;
11 /
-----------------
using loop
-----------------
SQL> declare
n number:=&n;
fact number:=1;
begin
loop
exit when n=0;
fact := fact*n;
n:=n-1;
end loop;
dbms_output.put_line('Factorial = '||fact);
end;
/
=====================================
----------------------------------
=====================================

You might also like