jueves, 28 de abril de 2011

Create or replace procedure CrearTablas
is
begin
if VerificaTabla('PROPIEDAD')then
execute immediate 'Drop table PROPIEDAD';
end if;
if VerificaTabla('EMPLEADO')then
execute immediate 'Drop table EMPLEADO';
end if;
if VerificaTabla('OFICINA')then
execute immediate 'Drop table OFICINA';
end if;

execute immediate 'Create table OFICINA(
idOficina integer not null,
direccion varchar2(45),
comuna varchar2(25),
ciudad varchar2(35),
codPostal varchar2(10),
constraint PK_OFICINA primary key (idOficina));
)';
execute immediate 'Create table EMPLEADO(
IdEmpleado int not null,
nombre varchar2(30) not null,
apellido varchar2(45)not null,
cargo varchar(35) not null,
sexo char(1)not null,
fechaNacimiento date not null,
salario int not null,
idOficina int not null,
CONSTRAINT ID_PK PRIMARY KEY (IdEmpleado),
CONSTRAINT NN_FK foreign key (IdOficina) references Oficina (IdOficina)
)';
execute immediate 'Create table Propiedad(
IdPropiedad int not null,
direccion varchar2(45) not null,
comuna varchar2(25)not null,
ciudad varchar(35) not null,
codigoPostal varchar(10) not null,
tipoVivienda int not null,
numeroHabitaciones int not null,
rentaMensual Float not null,
IdEmpleado int not null,
CONSTRAINT IDD_PK PRIMARY KEY (IdPropiedad),
CONSTRAINT NM_FK foreign key (IdEmpleado) references Empleado (IdEmpleado)
)';
end;

DESC OFICINA

begin
CrearTablas;
end

begin
if VerificaTabla('employees')= TRUE then
dbms_output.put_line('La tabla existe');
else
dbms_output.put_line('La tabla no existe');
end if;
end

Create or Replace procedure miCursor(pOficina integer)
as
cursor ListaPropiedadesCursor(pcOficina integer)
select nombre, apellido, count(idPropiedad)
from Empleadoe, Propiedad p
where e.idOficina = pcOficina
and e.idEmpleado=p.idEmpleado
group by nombre,apellido;

vnombre Empleado.nombre%type;
vapellido Empleado.nombre%type;
vPropXEmpleado integer;
vTotalxOficina integer;

begin
select Count (idPropiedad) into vTotalxOficina
from PROPIEDAD
where idOficina = pOficina;

No hay comentarios.:

Publicar un comentario