PLSQL 4 3 Practice
PLSQL 4 3 Practice
PLSQL 4 3 Practice
com/academy
Loop basico Encloses a sequence of statements between the keywords LOOP and
END LOOP and must execute at least once.
Try It / Solve It
1. What purpose does a loop serve in PL/SQL?
ayuda a poder realizar varias situaciones.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
2
5. Modify your solution to question 4 above, replacing the IF statement with an EXIT....WHEN
statement.
declare
v_id number:=1;
v_nombre_pais varchar2(50);
begin
loop select country_id, country_name into v_id, v_nombre_pais
from countries
where v_id=country_id;
dbms_output.put_line('Id del pais '||v_id||'. el nombre es: '||v_nombre_pais);
v_id:=v_id+1;
exit when v_id>3;
end loop;
end;
B. Write a PL/SQL block to insert numbers into the MESSAGES table. Insert the numbers 1
through 10, excluding 6 and 8.
declare
v_numero number(2):=1;
begin
loop if v_numero<>6 AND v_numero<>8 then
insert into messages(results)values(v_numero);
end if;
v_numero:=v_numero+1;
exit when v_numero>10;
end loop;
end;
C. Execute a SELECT statement to verify that your PL/SQL block worked.
select * from messages
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.