Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Reverse of Number

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

REVERSE OF NUMBER

declare
 num varchar2(5):='12345';             
 len number(2);            
 revnum varchar2(5);        
     
begin
   
len := length(num);                
 
for i in reverse 1.. len
 loop
 
revnum := revnum || substr(num,i,1);
 end loop;
dbms_output.put_line('given number ='|| num); 
dbms_output.put_line('reverse number ='|| revnum); 
 end;                        

Factorial Number

declare
fac number :=1;

n number := &1;

begin
while n > 0 loop
fac:=n*fac;
n:=n-1;
end loop;
dbms_output.put_line(fac);

end;

Armstrong NO
declare
-- declare variable n, s,r, len
-- and m of datatype number
    n number:=1634;
    s number:=0;
    r number;
    len number;
    m number;
  
begin
    m := n;
  
    len := length(to_char(n));
      
    -- while loop till n>0
    while n>0
    loop
        r := mod(n , 10);
        s := s + power(r , len);
        n := trunc(n / 10);
    end loop;
      
    if m = s
    then
        dbms_output.put_line('yes');
    else
        dbms_output.put_line('no');
    end if;
      
end;
  

Print Fabbonic Series

declare
  
-- declare variable first = 0,
-- second = 1 and temp of datatype number
first number := 0;
second number := 1;
temp number;
  
n number := 5;
i number;
  
begin
  
    dbms_output.put_line('Series:');
  
--print first two term first and second
    dbms_output.put_line(first);
    dbms_output.put_line(second);
  
-- loop i = 2 to n
    for i in 2..n
    loop
        temp:=first+second;
  
first := second;
second := temp;
  
--print terms of fibonacci series
    dbms_output.put_line(temp);
end loop;
  
end;
Prime Numbber

declare
    
-- declare variable n, i 
-- and temp of datatype number
n number;             
i number;            
temp number;        
    
begin
    
-- Here we Assigning 10 into n
n := 13;                 
    
-- Assigning 2 to i
i := 2; 
   
-- Assigning 1 to temp
temp := 1; 
   
-- loop from i = 2 to n/2
  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;          
  

Iteration FOR While

DECLARE

a number(2);

BEGIN

FOR a in 10 .. 20 LOOP
dbms_output.put_line('value of a: ' || a);

END LOOP;

END;

Insertion
BEGIN
INSERT INTO <table_name>(<column1 >,<column2>,...<column_n>)
VALUES(<valuel><value2>,...:<value_n>);
END;

Update
BEGIN
UPDATE <table_name>
SET <columnl>=<VALUE1>,<column2>=<Yalue2>,<column_n>=<value_n>
WHERE <condition that uniquely identifies the record that needs to be update>;
END;

Delete
BEGIN
DELETE
FROM
<table_name>
WHERE <condition that uniquely identifies the record that needs to be update>;
END;

Area And Parameter


--Find the area and perimeter of circle
DECLARE 
  
    -- Variables to store area and perimeter
    area   NUMBER(6, 2)  ;  
    perimeter   NUMBER(6, 2)  ; 
      
    --Assigning the value of radius 
    radius NUMBER(1) := 3; 
      
    --Constant value of  PI 
    pi CONSTANT NUMBER(3, 2) := 3.14; 
      
BEGIN 
  
        --Formula for area and perimeter of a circle 
        area := pi * radius * radius; 
        perimeter := 2 * pi * radius;
        dbms_output.Put_line('Area = ' || area); 
        dbms_output.Put_line(' Perimeter = ' || perimeter); 
  
END; 

You might also like