- http://pdb002.blogspot.com/search?updated-max=2011-05-02T16%3A21%3A00-07%3A00&max-results=7
jueves, 30 de junio de 2011
create or replace package pkgMipaquete is
function suma (p1 number, p2 number) return number;
function resta (p1 number, p2 number) return number;
function multiplica(p1 number, p2 number) return number;
function divide(p1 number, p2 number) return number;
end pkgMipaquete;
create or replace package BODY pkgMipaquete is
procedure imprime(pvalor number) is
BEGIN
dbms_output.put_line('Resultado : ' || pvalor);
end;
function suma(p1 number, p2 number) return number is
begin
imprime(p1+p2);
return(p1+p2);
end suma;
function resta(p1 number, p2 number) return number is
begin
imprime(p1-p2);
return(p1-p2);
end resta;
function multiplica(p1 number, p2 number) return number is
begin
imprime(p1*p2);
return(p1*p2);
end multiplica;
function divide(p1 number, p2 number) return number is
begin
imprime(p1/p2);
return(p1/p2);
EXCEPTION
when zero_divide then
dbms_output.put_line ('Cuack : Division por cero');
return 0;
end divide;
end pkgMipaquete;
declare
r number(10);
begin
r:= pkgMipaquete.suma(2,3);
end
jueves, 16 de junio de 2011
Corregir
1. Realizar una función que reciba una cadena ej: 'ARCA' y la muestre por consola repetida n veces Ej: 7 veces.
CREATE OR REPLACE function RepiteCadena(pstr1 varchar2,pn number)
return varchar2 as
str2 varchar(100) = null;
i numeric = 1;
begin
loop
str2 = concat(str2,pstr1);
i = i + 1;
exit when i >= pn;
end loop;
return str2;
end;
2. Crear un procedimiento con un cursor que actualice el atributo TotEmpleado
Declare
cursor miCursor
is
select e.numoficina, count(e.numempleado) as Empleados
from oficina p, empleado e
where p.numoficina = e.numoficina
group by e.numoficina;
vnumoficina oficina.numoficina%type;
vtotempleado oficina.numoficina%type;
begin
open micursor;
loop
fetch micursor into vnumoficina, vtotempleado;
exit when micursor%notfound;
update oficina
set totempleado = vtotempleado
where numoficina = vnumoficina;
end loop;
close micursor;
End;
select * from oficina
Declare
cursor miCursor
is
select e.numoficina, count(e.numempleado) as Empleados
from oficina p, empleado e
where p.numoficina = e.numoficina
group by e.numoficina;
vnumoficina oficina.numoficina%type;
vtotempleado oficina.numoficina%type;
begin
open micursor;
loop
fetch micursor into vnumoficina, vtotempleado;
exit when micursor%notfound;
update oficina
set totempleado = vtotempleado
where numoficina = vnumoficina;
end loop;
close micursor;
End;
select * from oficina
lunes, 13 de junio de 2011
Suscribirse a:
Entradas (Atom)