SQL DECLARAR CURSOR

CREATE TABLE PAISES
(CODPA NUMBER(3) NOT NULL PRIMARY KEY,
NOMPA VARCHAR2(20),
CONPA VARCHAR2 (10));

INSERT INTO PAISES VALUES(10,'COLOMBIA','AMERICA');
INSERT INTO PAISES VALUES(20,'BRASIL','AMERICA');
INSERT INTO PAISES VALUES(30,'PERU','AMERICA');
INSERT INTO PAISES VALUES(40,'ESPAÑA','AMERICA');
INSERT INTO PAISES VALUES(50,'FRANCIA','AMERICA');
INSERT INTO PAISES VALUES(60,'UGANDA','AMERICA');

SELECT * FROM PAISES;

set SERVEROUTPUT ON;

declare cursor cpaises
is
select codpa, nompa, conpa
from paises;
copa number(3);
nopa varchar2(20);
conpa varchar2(10);
begin
 open cpaises;
 loop
   fetch cpaises into copa,nopa,conpa;
   exit when cpaises%notfound;
   dbms_output.put_line(cpaises%rowcount ||'Pais'||nopa);
 end loop;
 close cpaises;
 end;


Share this

Related Posts

Previous
Next Post »

Buscar en Wikipedia

Resultados de la búsqueda