Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Friday 10 August 2018

PL/SQL: extract digits from a number

In this PL/SQL  program i use nested table to store the digits and then print them in reverse order



declare
type arr_num is table of number;
temp_arr_num arr_num:=arr_num();
num number := &Enter_Number;
i number :=1;
begin
 -- temp_arr_num.extend(6);
while(num >0)
loop
  temp_arr_num.extend(1);
  temp_arr_num(i) := mod(num,10);
  num := floor(num/10);
  i :=i+1;
end loop;
for i in reverse 1..temp_arr_num.count
  loop
    dbms_output.put_line(temp_arr_num(i));
  end loop;  
end;  

No comments:

Post a Comment