INF-272 Taller de Base de Datos
Nombre: Quenta Carvajal Luis Alberto
C.I.: 8320892 LP
Docente: Lic. Jose Luis Zeballos Abasto
Fecha: Jueves 17 de marzo del 2016
--------------------------------------------------------------------------------------------------------------------
EJERCICIOS RESUELTOS
Ejercicios Clase 1
1. Mejorar la funcin anterior considerando la igualdad de ambos nmeros.
Create or Replace Function mayorABy(a IN number, b IN number) Return Varchar2
IS
mensaje Varchar2(50);
BEGIN
IF a > b THEN
mensaje := a||' es mayor';
ELSE
if a=b then
mensaje :='son iguales';
else
mensaje := b||' es mayor';
end if;
END IF;
RETURN mensaje;
END mayorABy;
2. Crear la funcin para calcular la cantidad de aos a la fecha. Como parmetro
de entrada fecha a calcular.
Con funcin
select to_number(to_char(sysdate,'yyyy'))to_number(to_char(fechanaci,'yyyy'))edad
from empleado
Create or Replace Function nroAnios(fecha1 IN date) return number;
is
edadd number;
begin
edadd :=to_number(to_char(sysdate,'yyyy'))to_number(to_char(fecha1,'yyyy'));
return edadd;
END nroAnios
Sin funcion
Select ci, nombre, to_number(to_char(sysdate,'yyyy'))to_number(to_char(fechanaci,'yyyy')) edad
From empleado
Ejercicios clase 2
1. Desplegar la cantidad de empleados del sexo femenino, masculino y el total
de empleados
SIN FUNCION
select count(*) as FEMENINO
from EMPLEADO
where sexo like 'FEMENINO'
select count(*) as MASCULINO
from EMPLEADO
where sexo like 'MASCULINO'
SELECT COUNT(*) AS TOTAL
FROM empleado
Con funcin
select [Link] ,[Link], [Link]
from (select count(*) as FEMENINO
from EMPLEADO
where sexo like 'FEMENINO')ef, (
select count(*) as MASCULINO
from EMPLEADO
where sexo like 'MASCULINO')em,(SELECT
COUNT(*) AS TOTAL
FROM empleado)et
FUNCION+
Create or Replace Function nroSexo(ivsexo IN varchar2 ) return number
is
x number;
begin
select count(*) into x
from empleado e
where [Link] like ivsexo ;
return x;
end nroSexo
select nroSexo('FEMENINO') NROFEMENINO ,nroSexo('MASCULINO') NROMASCULINO
,[Link]
from(SELECT COUNT(*) AS TOTAL
FROM empleado)et
2. Desplegar alfabticamente la lista de empleado. Desplegar apellido, nombre
y el nmero de proyectos en los cuales trabaja el empleado.
SIN FUNCION
select [Link] , [Link], count(*) as nro
from empleado e, proyecto p, TRABAJA_EN te
where [Link] = [Link] and [Link] = [Link]
group by [Link], [Link]
order by [Link]
funcion
Create or Replace Function nropry_x_Emp(xci IN number)return number
is
r number;
begin
SELECT count(*) into r
from TRABAJA_EN te
where xci = [Link];
return r ;
end nropry_x_Emp
select nropry_x_Emp
Ejercicio clase 3
1. Desplegar el nmero de dependientes por jefe de departamento. Desplegar
ordenado alfabticamente.
select distinct [Link], [Link]
from departamento d, dependiente dp, empleado e
where [Link] = [Link]
and e.ci_supervisor = [Link]
order by [Link]
select e.ci_supervisor, count(*) nro
from empleado e
select count(*) nro
from (
select distinct [Link], [Link]
from departamento d, dependiente dp, empleado e
where [Link] = [Link]
and e.ci_supervisor = [Link]
order by [Link]
)
2. Desplegar la planilla de sueldos
TotalHrs
= Cantidad de horas trabajadas en proyectos por empleado
BonoHoras = TotalHrs * 10
Total Ganado = TotalHrs + BonoHoras
select [Link], [Link], [Link]
from empleado e
order by [Link]
----TotalHrs
= Cantidad de horas trabajadas en proyectos por empleado---select [Link], (nvl(sum(horas),0)) as TOTALHORAS
from trabaja_en t
group by [Link]
---BonoHoras = TotalHrs * 10--select [Link], nvl((B.t*10),0) as BONOHORAS
from (select [Link], nvl(sum(horas),0) as t
from trabaja_en t
group by [Link]) B
---Total Ganado = TotalHrs + BonoHoras--SELECT (A+B) as TOTALGANADO
FROM (select [Link], nvl(sum(horas),0) as t
from trabaja_en t
group by [Link]) A,
(select [Link], nvl(sum(horas),0)
from trabaja_en t
group by [Link]) B
--UNION PARCIAL-SELECT distinct [Link], [Link]
FROM (select [Link], (nvl(sum(horas),0)) as TOTALHORAS
from trabaja_en t
group by [Link]) A,
(select [Link], nvl((B.t*10),0) as BONOHORAS
from (select [Link], nvl(sum(horas),0) as t
from trabaja_en t
group by [Link]) B) B1
[Link] los empleados que tiene como nico
dependiente al conyugue (Esposa o Esposo).
select [Link],COUNT ([Link])as nro
from empleado e,(select [Link],count([Link]) nro
from dependiente d
group by [Link])tmp
where [Link] = [Link] AND [Link] like 'ESPOSO' OR [Link] like
'ESPOSA'and
select count([Link])
from dependiente d
group by [Link]