Answer to Question #273349 in Databases | SQL | Oracle | MS Access for tenzee

Question #273349

Write a PL/SQL code to find the sum of digits of even digits from a number fetched from a table using implicit cursors and check if the sum is prime number or not.


1
Expert's answer
2021-11-29T18:26:39-0500
declare
  2    ad int := 0;
  3    i int;
  4    b int;
  5    cursor c_nm is select * From numb;
  6    temp c_nm%rowtype;
  7  begin
  8    open c_nm;
  9    loop
 10      fetch c_nm into temp;
 11      exit when c_nm%notfound;
 12      i := temp.num;                  --> this
 13
 14      while i > 0 loop
 15        b := mod(i, 10);
 16        if mod(b, 2) = 0 then
 17           ad := b + ad;
 18        end if;
 19        i := trunc(i/10);
 20      end loop;
 21    end loop;
 22    dbms_output.put_line('ad = ' ||ad);
 23    close c_nm;
 24  end;
 25  /
ad = 6

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS