How to print even numbers and odd numbers by PL/SQL

 Even and Odd Numbers

--------------------------------------------

Even numbers are divisible by 2 without remainders. They end in 0, 2, 4, 6, or 8. 

Odd numbers are not evenly divisible by 2 and end in 1, 3, 5, 7, or 9.

set serveroutput on;

declare

v_input number := 10;

v_counter number := 1;

v_odd_number clob;

v_even_number clob;

begin

while (v_counter <= v_input) loop

if (mod(v_counter, 2) = 0) then

v_even_number := v_even_number||','||v_counter;

else

v_odd_number := v_odd_number||','||v_counter;

end if;

v_counter := v_counter+1;

end loop;

dbms_output.put_line('Even Numbers = '||trim(leading ',' from v_even_number));

dbms_output.put_line('Odd Numbers = '||trim(leading ',' from v_odd_number));

end;

Result:

Even Numbers = 2,4,6,8,10

Odd Numbers = 1,3,5,7,9



Comments

Popular posts from this blog

How to create and show html report by ajax callback and print report in Oracle Apex

How to insert and show blob images in form and report of Oracle Apex

CRUD Operation from HTML