//Creo la tabla oficina
create table OFICINA (
NUMOFICINA CHAR(4) not null,
CALLE CHAR(30),
CIUDAD CHAR(25),
CODIGOPOSTAL CHAR(10),
constraint PK_OFICINA primary key (NUMOFICINA)
);
----------------------------------------------------------------------------------------------
//Diseñar un PA para Modificar la tabla oficina agregándole la columna Direccion.
create or Replace PROCEDURE agregarDireccion
as
BEGIN
execute immediate 'alter table Oficina
add Direccion varchar2(40)';
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Error en agregar atributo');
END;
-----------------------------------------------------------------------------------------------
//Compruebo que en mi tabla "Oficina" este el atributo "Direccion" agregado.
DESCRIBE OFICINA
-----------------------------------------------------------------------------------------------
create or Replace PROCEDURE agregarDireccion
as
BEGIN
execute immediate 'alter table Oficina
add Direccion varchar2(40)';
EXCEPTION
when NO_DATA_FOUND then
dbms_output.put_line('se gatilla NO_DATA_FOUND');
WHEN OTHERS THEN
dbms_output.put_line('se gatilla OTHERS supongo porque La tabla OFICINA no existe');
END;
bibliografia de errores que se le pueden agregar:
http://www.devjoker.com/contenidos/Tutorial-PLSQL/48/Excepciones-en-PLSQL.aspx
-----------------------------------------------------------------------------------------------
//Escriba un programa que gatille una excepción al tratar de eliminar un registro inexistente.
create or replace PRODECURE eliminarRegistro (pnumOficina oficina.numOficina%type)
is
vnumoficina oficina.numoficina%type;
begin
select numoficina into vnumoficina
from oficina
where numoficina = pnumOficina;
delete from oficina
when numOficina = pnumOficina;
exception
when NO_DATA_FOUND then
dbms_output.put_line('Registro :' || pnumoficina || ' No existe para eliminarlo);
End;
-----------------------------------------------------------------------------------------------
//Crear una función de calcule el total de empleados por Oficina.
create or replace FUNCTION CuentaEmpleados (pnumOficina oficina.numOficina%type)
return interger;
as
vtotEmpleados interger :=0;
vnumoficina oficina.numoficina%type;
begin
select numoficina into vtotEmpleados
from oficina
where numoficina = pnumOficina;
select count(numoficina) int vtotEmpleados
from empleados
where numoficina = pnumOficina;
return vtotEmpleados;
exception
when NO_DATA_FOUND then
dbms_output.put_line('Oficina :' || pnumoficina || ' No existe');
return 0;
End;
lunes, 18 de abril de 2011
jueves, 14 de abril de 2011
create or replace procedure VerCliente(Pnumcliente Number)
is
Vnombre employees.first_name%type;
Vapellido employees.last_name%type;
begin
select first_name,last_name into Vnombre,Vapellido
from employees
where employee_id = Pnumcliente ;
dbms_output.put_line('El cod ingresado es : '||Pnumcliente ||' Nombre: ' ||Vnombre ||' Apellido: '||Vapellido );
end;
begin
VerCliente(101) ;
end;
is
Vnombre employees.first_name%type;
Vapellido employees.last_name%type;
begin
select first_name,last_name into Vnombre,Vapellido
from employees
where employee_id = Pnumcliente ;
dbms_output.put_line('El cod ingresado es : '||Pnumcliente ||' Nombre: ' ||Vnombre ||' Apellido: '||Vapellido );
end;
begin
VerCliente(101) ;
end;
lunes, 11 de abril de 2011
1.-Crear una función SumaDos (n1, n2) que reciba 2 numeros y retorne la suma de ellos.
CREATE OR REPLACE FUNCTION sumaDos (n1 Numeric, n2 Numeric)
RETURN numeric
is
BEGIN
return (n1 + n2);
END;
2.-Crear la Función Potencia (n, p) que reciba un numero y retorne el numero elevado a la potencia p
CREATE OR REPLACE FUNCTION Potencia100 (n Numeric,p Numeric)
RETURN numeric
is
BEGIN
loop
return power(n,p);
end loop;
END;
create or replace function Potencia69(n Numeric, p Numeric)
return numeric;
is
resultado numeric := 1;
begin
for i in 1..p
loop
resultado := resultado * p;
end loop;
return resultado;
end
3.-Escribir la funcion MayorDeTres (n1, n2, n3) que retorne el mayor de los tres elementos ingresados
CREATE OR REPLACE FUNCTION mayorDeTres (n1 numeric, n2 numeric, n3 numeric)
RETURN numeric
is
BEGIN
RETURN (GREATEST(n1,n2,n3));
END;
4.-Diseñar una función Invertir3 (n) que reciba un numero de tres digitos y retorne el numero invertido. Ej: 123 retorna 321
5.-Implementar una funcion invertirN(n) que reciba un numero de N digitos y retorne el numero invertido
6.-Escriba la función BuscaString (Srt1, Str2) y retorna Verdadero o falso segun si el Str2 se encuentra en Str1
jueves, 7 de abril de 2011
Suscribirse a:
Entradas (Atom)