Solucion Evaluacion Base de Datos II (1)

Embed Size (px)

Citation preview

SOLUCION EVALUACION B. DATOS IIPROGRAMA 1:set serveroutput ondeclarecursor c1 isselect *from empwhere deptno=20;begin for v1 in c1 loop dbms_output.put_line(v1.empno||' '||v1.ename||' '||v1.job); end loop;end;RESULTADO:7369 SMITH CLERK7566 JONES MANAGER7788 SCOTT ANALYST7876 ADAMS CLERK7902 FORD ANALYSTProcedimiento PL/SQL terminado correctamente.

PROGRAMA 2:

set serveroutput ondeclarevar1 emp.deptno%type;var2 emp.ename%type;var3 emp.job%type;begin select deptno,ename,job into var1,var2,var3 from emp where deptno=20; if sql%found then dbms_output.put_line ('se encontro registro'); end if; if sql%notfound then dbms_output.put_line ('no se encontro registro'); end if; exception when too_many_rows then dbms_output.put_line(' muchas lineas ' || ' '||sql%rowcount); end; RESULTADO:muchas lineas 1

Procedimiento PL/SQL terminado correctamente

PROGRAMA 3:

create or replace function suma(a number, b number)return numberissuma number;begin suma:= a+b; return(suma);end suma;

RESULTADO:

SQL> declare 2 begin 3 dbms_output.put_line(suma(1,2)); 4 end; 5 /Procedimiento PL/SQL terminado correctamente.

PROGRAMA 4:create or replace trigger pruebabefore insert on empfor each rowdeclarebegin insert into auditoria values(sysdate,rtrim(:new.ename)); end;

RESULTADO:SQL> create table auditoria 2 (fecha date, 3 nombre varchar2(20));SQL> insert into emp(empno,ename) 2 values(7884,'raul');1 fila creada.

SQL> select *from auditoria;FECHA NOMBRE-------- --------------------10/07/1510/07/15 raul