Professional Documents
Culture Documents
declare
n number;
m number;
temp number:=0;
rem number;
begin
n:=5432112345;
m:=n;
while n>0
loop
rem:=mod(n,10);
temp:=(temp*10)+rem;
n:=trunc(n/10);
end loop;
if m = temp
then
dbms_output.put_line('true');
else
dbms_output.put_line('false');
end if;
end;
declare
x number(5);
y number(5);
z number(7);
begin
x:=10;
y:=20;
z:=x+y;
dbms_output.put_line('Sum is '||z);
end;
declare
num number := 6;
fact number := 1;
temp number;
begin
temp :=num;
while( temp>0 )
loop
fact := fact*temp;
temp := temp-1;
end loop;
dbms_output.put_line('factorial of '|| num || ' is ' || fact);
end;
DECLARE
num1 INTEGER;
num2 INTEGER;
t INTEGER;
BEGIN
num1 := 8;
num2 := 48;
WHILE MOD(num2, num1) != 0 LOOP
t := MOD(num2, num1);
num2 := num1;
num1 := t;
END LOOP;
dbms_output.Put_line('GCD of '||num1||' and '||num2 ||' is '||num1);
END;
declare
n number;
i number;
temp number;
begin
n := 13;
i := 2;
temp := 1;
for i in 2..n/2
loop
if mod(n, i) = 0
then
temp := 0;
exit;
end if;
end loop;
if temp = 1
then
dbms_output.put_line('true');
else
dbms_output.put_line('false');
end if;
end;
first number := 0;
second number := 1;
temp number;
n number := 5;
i number;
begin
dbms_output.put_line('Series:');
dbms_output.put_line(first);
dbms_output.put_line(second);
for i in 2..n
loop
temp:=first+second;
first := second;
second := temp;
dbms_output.put_line(temp);
end loop;
end;
DECLARE
str VARCHAR(20) := 'skeegrofskeeg';
len NUMBER;
str1 VARCHAR(20);
BEGIN
len := Length(str);
FOR i IN REVERSE 1.. len LOOP
str1 := str1|| Substr(str, i, 1);
END LOOP;
dbms_output.Put_line('Reverse of string is '|| str1);
END;
DECLARE
a NUMBER := 12;
b NUMBER := 14;
c NUMBER := 20;
sumOf3 NUMBER;
avgOf3 NUMBER;
BEGIN
sumOf3 := a + b + c;
avgOf3 := sumOf3 / 3;
dbms_output.Put_line('Sum = '||sumOf3);
dbms_output.Put_line('Average = '||avgOf3);
END;
DECLARE
num INTEGER;
num_to_word VARCHAR2(100);
str VARCHAR2(100);
len INTEGER;
c INTEGER;
BEGIN
num := 123456;
len := Length(num);
dbms_output.Put_line('Entered Number is: '||num);
FOR i IN 1..len LOOP
c := Substr(num, i, 1);
SELECT Decode(c, 0, 'Zero ',
1, 'One ',
2, 'Two ',
3, 'Three ',
4, 'Four ',
5, 'Five ',
6, 'Six ',
7, 'Seven ',
8, 'Eight ',
9, 'Nine ')
INTO str
FROM dual;
num_to_word := num_to_word ||str;
END LOOP;
dbms_output.Put_line('Number to words: '||num_to_word);
END;
DECLARE
n NUMBER;
m NUMBER;
s NUMBER := 0;
BEGIN
FOR i IN 1..999 LOOP
n := i;
WHILE n > 0 LOOP
m := MOD(n, 10);
s := s + m;
n := Trunc(n / 10);
END LOOP;
IF s = 25 THEN
dbms_output.Put_line(i||' ');
END IF;
s := 0;
END LOOP;
END;
DECLARE
km NUMBER := 6.9;
met NUMBER := 0;
cem NUMBER := 0;
BEGIN
met := km * 1000;
cem := met * 100;
dbms_output.Put_line('6.9KM is equivalent to meters: ' ||met);
dbms_output.Put_line('6.9KM is equivalent to centimeters:' ||cem);
END;