Docsity

PRACTICA DE CURSORES PL/SQL, Ejercicios de Programación de Bases de Datos

Toggle sidebar
bg1
Angie Zuleima Romero Villamizar
c.c. 1.024.546.389
ACTIVIDAD DE CURSORES.
Explicit Cursor Declared by the programmer for queries that return more than one row
Cursor A label for a context area or a pointer to the context area
CLOSE Disables a cursor, releases the context area, and undefines the active set
Area de contexto An allocated memory area used to store the data processed by a SQL statement
Implicit Cursor Defined automatically by Oracle for all SQL DML statements, and for SELECT
statements that return only one row
OPEN Statement that executes the query associated with the cursor, identifies the active
set, and positions the cursor pointer to the first row
FETCH Statement that retrieves the current row and advances the cursor to the next row
either until there are no more rows or until a specified condition is met
Active set The set of rows returned by a multiple row query in an explicit cursor operation
1) La principal diferencia entre los cursores, es que el implícito se utiliza para consultas que devuelven un
solo registro, por el contrario, el cursor explicito devuelve un conjunto de registros ante una consulta
realizada.
2) SELECT
3) Cuando se necesita que una consulta devuelva más de un registro, y cuando cada fila deba recuperarse
manualmente.
4)
a) DECLARE
CURSOR monedas_cur
IS SELECT codigo_moneda, nombre_moneda
FROM monedas
b) Open monedas_cur;
c) v_cur_codigo monedas.codigo_moneda%TYPE;
v_cur_nombre monedas.moneda_nombre%TYPE;
d) FETCH monedas_cur INTO v_cur_codigo, v_cur_nombre;
DBMS_OUTPUT.PUT_LINE( v_cur_codigo|| ' ' || v_cur_nombre);
CLOSE monedas_cur;
e) DECLARE
pf3

Vista previa parcial del texto

¡Descarga PRACTICA DE CURSORES PL/SQL y más Ejercicios en PDF de Programación de Bases de Datos solo en Docsity!

c.c. 1.024.546.

ACTIVIDAD DE CURSORES.

Explicit Cursor Declared by the programmer for queries that return more than one row Cursor A label for a context area or a pointer to the context area CLOSE Disables a cursor, releases the context area, and undefines the active set Area de contexto An allocated memory area used to store the data processed by a SQL statement Implicit Cursor Defined automatically by Oracle for all SQL DML statements, and for SELECT statements that return only one row OPEN Statement that executes the query associated with the cursor, identifies the active set, and positions the cursor pointer to the first row FETCH Statement that retrieves the current row and advances the cursor to the next row either until there are no more rows or until a specified condition is met Active set The set of rows returned by a multiple row query in an explicit cursor operation

  1. La principal diferencia entre los cursores, es que el implícito se utiliza para consultas que devuelven un solo registro, por el contrario, el cursor explicito devuelve un conjunto de registros ante una consulta realizada.
  2. SELECT
  3. Cuando se necesita que una consulta devuelva más de un registro, y cuando cada fila deba recuperarse manualmente.

a) DECLARE CURSOR monedas_cur IS SELECT codigo_moneda, nombre_moneda FROM monedas b) Open monedas_cur; c) v_cur_codigo monedas.codigo_moneda%TYPE; v_cur_nombre monedas.moneda_nombre%TYPE; d) FETCH monedas_cur INTO v_cur_codigo, v_cur_nombre; DBMS_OUTPUT.PUT_LINE( v_cur_codigo|| ' ' || v_cur_nombre); CLOSE monedas_cur; e) DECLARE

c.c. 1.024.546.

CURSOR monedas_cur IS SELECT moneda_codigo, moneda_nombre FROM monedas; v_cur_codigo monedas. codigo_moneda%TYPE; v_cur_nombre monedas.nombre_moneda%TYPE; BEGIN OPEN monedas_cur; FETCH monedas_cur NTO v_cur_codigo, v_cur_nombre; DBMS_OUTPUT.PUT_LINE( v_cur_codigo|| ' ' || v_cur_nombre); CLOSE monedas_cur; END; f) DECLARE CURSOR monedas_cur IS SELECT codigo_moneda, nombre_moneda FROM monedas; v_cur_codigo monedas. codigo_moneda %TYPE; v_cur_nombre monedas. nombre_moneda %TYPE; BEGIN OPEN monedas_cur; LOOP FETCH monedas_cur INTO v_cur_codigo, v_cur_nombre; DBMS_OUTPUT.PUT_LINE( v_cur_codigo|| ' ' || v_cur_nombre); EXIT WHEN monedas_cur%NOTFOUND; END LOOP; CLOSE monedas_cur; END; g) DECLARE CURSOR festivo IS SELECT nombre_pais, festivo_nacional, nombre_festivo FROM paises WHERE idRegion=5 AND festivo_nacional IS NOT NULL; v_nombre_pais paises.nombre_pais%TYPE; v_festivo_nacional paises.festivo_nacional%TYPE; v_nombre_festivo paises.nombre_festivo%TYPE; BEGIN DBMS_OUTPUT.PUT_LINE('Paises de la region5 y sus festivos:'); OPEN festivo; LOOP FETCH festivo INTO v_nombre_pais, v_festivo_nacional, v_nombre_festivo; EXIT WHEN festivo%NOTFOUND; DBMS_OUTPUT.PUT_LINE(v_nombre_pais||' '|| v_festivo_nacional||' '||v_nombre_festivo); END LOOP; CLOSE festivo; END;

 Declarar el cursor.  Ejecutar el cursor.  Cortar el cursor.