martes, 17 de abril de 2018

Procedimientos Almacenados - Ejemplos en Clase

CASE

CREATE DEFINER=`root`@`localhost` PROCEDURE `AlumnosX`(
in Vnum_con int,
in Vnombre varchar(45),
in Vapellido_p varchar(45),
in Vapellido_m varchar(45),
in Vcorreo varchar (90),
in accion varchar(30))
BEGIN
case accion
when 'nuevo' then
insert into alumnos (nombre, apellido_p, apellido_m, correo)
        values (Vnombre, Vapellido_p, Vapellido_m, Vcorreo);
when 'editar' then
update alumnos set
        nombre=Vnombre, apellido_p=Vapellido_p, apellido_m=Vapellido_m, correo=Vcorreo
        where num_con=Vnum_con;
when 'eliminar' then
delete from alumnos where num_con=Vnum_con;
when 'consultar' then
select * from alumnos where num_con=Vnum_con;
end case;

END

INSERTAR

CREATE DEFINER=`root`@`localhost` PROCEDURE `Alta_libros`(
in nombre_s varchar(45),
in editorial_s int(11))
BEGIN
insert into libros (nombre,editorial) values(nombre_s, editorial_s);
END

BORRAR


CREATE DEFINER=`root`@`localhost` PROCEDURE `borrar_libros`(IN id_libros INT)
BEGIN
Delete from libros where idlibros=id_libros;
END

CONSULTAR


CREATE DEFINER=`root`@`localhost` PROCEDURE `consulta_editorial`(IN re INT)
BEGIN
SELECT * FROM editorial WHERE id_editorial=re;
END

No hay comentarios:

Publicar un comentario