martes, 22 de noviembre de 2016

MANTENIMIENTO AGREGAR 

,ACTUALIZAR,ELIMINAR TBS ANTENOR 

ORREGO 

---PA CARRERA  agregar VALIDADO
describe TCarrera;
create  or replace procedure spAgregarCarrera
(
vCodcarrera char,vCarrera varchar2)
is
i number;
eCodCarrera  exception;
Begin
   select count(*) into  i from  TCarrera where  CodCarrera=vCodcarrera;
   if  (i <> 0) then
    raise eCodCarrera;
   end if;
   insert into  TCarrera values(vCodcarrera,vCarrera);
  
   commit;
   DBMS_OutPut.put_Line('Se agrego la carrera correctamente ');
   exception
   when eCodCarrera then
        DBMS_OutPut.put_Line('Errror:Duplicado ');
end;

SET SERVEROUTPUT ON;

execute  spAgregarCarrera('C0011','hola');
select * from  TCarrera;



   ------Actualizar Carrera--
  
 create  or replace procedure spActualizarCarrera
(
vCodcarrera char,vCarrera varchar2)
is
i number;
eCodCarrera  exception;
Begin
   select count(*) into  i from  TCarrera where  CodCarrera=vCodcarrera;
   if  (i = 0) then
    raise eCodCarrera;
   end if;
   update   TCarrera set  Carrera=vCarrera where CodCarrera=vCodcarrera;
  
   commit;
   DBMS_OutPut.put_Line('Se actualizo  la carrera correctamente ');
   exception
   when eCodCarrera then
        DBMS_OutPut.put_Line('Errror:no existe  en TCarrera ');
end;
execute  spActualizarCarrera('C0011','dddd');
select * from  TCarrera;







-----Eliminar Carrera ---

 create  or replace procedure spEliminarCarrera
(
vCodcarrera char)
is
i number;
eCodCarrera  exception;
eAlumno exception;
Begin
   select count(*) into  i from  TCarrera where  CodCarrera=vCodcarrera;
   if  (i = 0) then
    raise eCodCarrera;
   end if;
   select count(*) into  i from  TAlumno where  CodCarrera=vCodcarrera;
   if  (i <> 0) then
    raise eAlumno;
   end if;
   Delete    TCarrera  where CodCarrera=vCodcarrera;
  
   commit;
   DBMS_OutPut.put_Line('Se Elimino  la carrera correctamente ');
   exception
   when eCodCarrera then
        DBMS_OutPut.put_Line('Errror:no existe  en TCarrera ');
   when eAlumno then
   DBMS_OutPut.put_Line('Errror: existe  en alumnos en la carrera ');
end;

execute  spEliminarCarrera('C0011');
select * from  TCarrera;
--- Agregar  Usuario  ----
describe TUsuario;
create  or replace procedure spAgregarUsuario
(
vUsuario  char,vContraseña char)
is
i number;
eCodUsuario exception;
Begin
  select count(*) into  i from  TUsuario where  Usuario=vUsuario;
  if  (i <> 0) then
    raise eCodUsuario;
  end if;
     insert into  TUsuario values(vUsuario,vContraseña);
  
   commit;
   DBMS_OutPut.put_Line('Se agrego el usuario correctamente ');
   exception
   when eCodUsuario then
        DBMS_OutPut.put_Line('Errror:Duplicado ');
end;
execute spAgregarUsuario('U0031','222');
select * from TUsuario order by  Usuario asc  ;
----Actualizar Usuario---
create  or replace procedure spActualizarrUsuario
(
vUsuario  char,vContraseña char)
is
i number;
eCodUsuario exception;
Begin
  select count(*) into  i from  TUsuario where  Usuario=vUsuario;
  if  (i = 0) then
    raise eCodUsuario;
  end if;
     Update     TUsuario set Contraseña=vContraseña where Usuario=vUsuario;
  
   commit;
   DBMS_OutPut.put_Line('Se actualizo el usuario correctamente ');
   exception
   when eCodUsuario then
        DBMS_OutPut.put_Line('Errror:no existe ');
end;
execute spActualizarrUsuario('U0031','33333');
select * from TUsuario order by  Usuario asc  ; 
-- Eliminar Usuario  ---
create  or replace procedure spEliminarUsuario
(
vUsuario  char)
is
i number;
eCodUsuario exception;
eAlumno exception;
eDocente exception;
Begin
  select count(*) into  i from  TUsuario where  Usuario=vUsuario;
  if  (i = 0) then
    raise eCodUsuario;
  end if;
  select count(*) into  i from  TAlumno where  Usuario=vUsuario;
  if  (i <> 0) then
    raise eAlumno;
  end if;
  select count(*) into  i from  TDocente where  Usuario=vUsuario;
  if  (i <> 0) then
    raise eDocente;
  end if;
     Delete   TUsuario  where Usuario=vUsuario;
  
   commit;
   DBMS_OutPut.put_Line('Se elimino el usuario correctamente ');
   exception
   when eCodUsuario then
        DBMS_OutPut.put_Line('Errror:no existe ');
   when eAlumno then
        DBMS_OutPut.put_Line('Errror:usuario existe en alumno ');
   when eDocente then
        DBMS_OutPut.put_Line('Errror:docente existe en alumno ');
end;
execute spEliminarUsuario('U0031');
select * from TUsuario order by  Usuario asc  ; 
---- Agregar Docente----
describe Tdocente;
create or replace procedure spAgregarDocente
(
vCodDocente char,vAPePaterno varchar2,vAPeMaterno varchar2,vNombres varchar2,vUsuario char)
is
i number;
eCodDocente exception;
eUsuario exception;
eUsuarioA exception;
Begin
    select  count(*) into i from Tdocente where CodDocente=vCodDocente;
    if  (i <> 0) then
     raise eCodDocente;
    end if;
   
    select count(*) into i from TUsuario where Usuario=vUsuario;
    if  (i = 0) then
     raise eUsuario;
    end if;
   
    select count(*) into i from Tdocente where Usuario=vUsuario;
    if  (i <> 0) then
     raise eUsuarioA;
    end if;   
    insert  into TDocente values(vCodDocente,vAPePaterno,vAPeMaterno,vNombres,vUsuario);
    commit;
   DBMS_OutPut.put_Line('Se Agrego el Docente correctamente ');
   exception
   when eCodDocente then
        DBMS_OutPut.put_Line('Errror: Duplicado ');
   when eUsuario then
        DBMS_OutPut.put_Line('Errror: Usuario no existe ');
   when eUsuarioA then
        DBMS_OutPut.put_Line('Errror: Usuario esta en uso');
end;   
   
    execute spAgregarDocente('D0021','LAURRARI', 'AZQABACHE','JESUS','U0031');
    execute spAgregarDocente('D0022','daa', 'ssss','rrr','U0032');
    select  * from TDocente;
---Actualizar docente--
create or replace procedure spActualizarDocente
(
vCodDocente char,vAPePaterno varchar2,vAPeMaterno varchar2,vNombres varchar2,vUsuario char)
is
i number;
eCodDocente exception;
eUsuario exception;
Begin
    select  count(*) into i from Tdocente where CodDocente=vCodDocente;
    if  (i = 0) then
     raise eCodDocente;
    end if;
   
    select count(*) into i from TUsuario where Usuario=vUsuario;
    if  (i = 0) then
     raise eUsuario;
    end if;
   
    Update   TDocente set APePaterno=vAPePaterno,APeMaterno=vAPeMaterno,Nombres=vNombres,Usuario=vUsuario where CodDocente=vCodDocente;
    commit;
   DBMS_OutPut.put_Line('Se Actualizo el Docente correctamente ');
   exception
   when eCodDocente then
        DBMS_OutPut.put_Line('Errror: Docente no existe ');
   when eUsuario then
        DBMS_OutPut.put_Line('Errror: Usuario no existe ');
end;
    execute spActualizarDocente('D0021','Hola', 'Hola','HOla','U0031');
    execute spActualizarDocente('D0022','Hola', 'Hola','HOla','U0032');
    select  * from TDocente;

---ELIMINAR DOCENTE –
create or replace procedure spEliminarDocente
(
vCodDocente char)
is
i number;
eCodDocente exception;
eCarga exception;
Begin
    select  count(*) into i from Tdocente where CodDocente=vCodDocente;
    if  (i = 0) then
     raise eCodDocente;
    end if;
   
    select count(*) into i from TCarga where CodDocente=vCodDocente;
    if  (i <> 0) then
     raise eCarga;
    end if;
   
    Delete  TDocente  where CodDocente=vCodDocente;
    commit;
   DBMS_OutPut.put_Line('Se Elimino el Docente correctamente ');
   exception
   when eCodDocente then
        DBMS_OutPut.put_Line('Errror: Docente no existe ');
   when eCarga then
        DBMS_OutPut.put_Line('Errror: El docente existe en Carga ');
end;
    execute spEliminarDocente('D0021');
    execute spEliminarDocente('D0022');
    select  * from TDocente;




---Agregar Alumno ---
Create  or replace procedure spAgregarAlumno
(
vCodAlumno char,vAPePaterno varchar2,vAPeMaterno varchar2,vNombres varchar2,vFechaNac date,vUsuario char,vCodCarrera char)
is
i number;
eCodAlumno exception;
eUsuario exception;
eUsuarioA exception;
Begin
     select count(*) into  i from TAlumno where CodAlumno=vCodAlumno;
     if (i<>0) then
       raise eCodAlumno;
     end if;
     select count(*) into  i from  TUsuario where Usuario=vUsuario;
     if (i=0) then
       raise eUsuario;
     end if;
     select count(*) into i from TAlumno where Usuario=vUsuario;
     if (i<>0) then
       raise eUsuarioA;
     end if;
     Insert  into TAlumno values(vCodAlumno,vAPePaterno,vAPeMaterno,vNombres,vFechaNac,vUsuario,vCodCarrera);
     commit;
     DBMS_OutPut.Put_Line('Alumno Agregado correctamente');
    
     exception
     When eCodAlumno then
     DBMS_OutPut.Put_Line('Error:Duplicado');
     When eUsuario then
     DBMS_OutPut.Put_Line('Error:Usuario no Existe');
     When eUsuarioA then
     DBMS_OutPut.Put_Line('Error:Usuario en uso');
end;

begin
spAgregarAlumno('A0020','AZABACHE','MENDIZABALA','JUANA','12/06/1980','U0020','C0010');
end;
begin
spListarAlumno;
end;

---Actualizar Alumno ---
Create  or replace procedure spActualizarAlumno
(
vCodAlumno char,vAPePaterno varchar2,vAPeMaterno varchar2,vNombres varchar2,vFechaNac date,vUsuario char,vCodCarrera char)
is
i number;
eCodAlumno exception;
eUsuario exception;
Begin
     select count(*) into  i from TAlumno where CodAlumno=vCodAlumno;
     if (i=0) then
       raise eCodAlumno;
     end if;
     select count(*) into  i from  TUsuario where Usuario=vUsuario;
     if (i=0) then
       raise eUsuario;
     end if;
     Update TAlumno set APePaterno=vAPePaterno,APeMaterno=vAPeMaterno,Nombres=vNombres,FechaNac=vFechaNac,Usuario=vUsuario,CodCarrera=vCodCarrera where CodAlumno=vCodAlumno;
     commit;
     DBMS_OutPut.Put_Line('Alumno Actualizado correctamente');
    
     exception
     When eCodAlumno then
     DBMS_OutPut.Put_Line('Error:Alumno no existe');
     When eUsuario then
     DBMS_OutPut.Put_Line('Error:Usuario no Existe');
end;
begin
spActualizarAlumno('A0020','AZABACHE','hola','JUANA','12/06/1980','U0020','C0010');
end;
begin
spListarAlumno;
end;
---Eliminar Alumno--
Create  or replace procedure spEliminarAlumno
(
vCodAlumno char)
is
i number;
eCodAlumno exception;
eNotas exception;
Begin
     select count(*) into  i from TAlumno where CodAlumno=vCodAlumno;
     if (i=0) then
       raise eCodAlumno;
     end if;
     select count(*) into  i from  TNotas where CodAlumno=vCodAlumno;
     if (i<>0) then
       raise eNotas;
     end if;
     Delete TAlumno  where CodAlumno=vCodAlumno;
     commit;
     DBMS_OutPut.Put_Line('Alumno Eliminado correctamente');
    
     exception
     When eCodAlumno then
     DBMS_OutPut.Put_Line('Error:Alumno no existe');
     When eNotas then
     DBMS_OutPut.Put_Line('Error:Alumno Existe en la tabla Notas');
end;
begin
spEliminarAlumno('A0021');
end;
begin
spListarAlumno;
end;
----Agregar Carga----
describe TCarga;
Create  or replace procedure spAgregarCarga
(
vIDCarga char,vCodDocente char,vCodAsignatura char,vSemestre varchar2)
is
i number;
eCodCarga exception;
eCodDocente exception;
eCodAsignatura exception;
Begin
    select count(*) into i from TCarga where IDCarga=vIDCarga;
    if (i<>0) then
     raise eCodCarga;
    end if;
    select count(*) into i from TDocente where CodDocente=vCodDocente;
    if (i=0) then
     raise eCodDocente;
    end if;
    select count(*) into i from TAsignatura where CodAsignatura=vCodAsignatura;
    if (i=0) then
     raise  eCodAsignatura;
    end if;
   
    insert into  TCarga values(vIDCarga,vCodDocente,vCodAsignatura,vSemestre);
    commit;
    DBMS_OutPut.Put_Line('Carga agregado correctamente ');
    exception
    When eCodCarga then
    DBMS_OutPut.Put_Line('Error:Duplicado');
    When eCodDocente then
    DBMS_OutPut.Put_Line('Error:Docente  no existe');
    When eCodAsignatura then
    DBMS_OutPut.Put_Line('Error:Asignatura no existe');
end;
begin
spAgregarCarga('C0021','D0010','S0010','I');
end;
begin
spListarCarga;
end;

----Actualziar Carga---
Create  or replace procedure spActualizarCarga
(
vIDCarga char,vCodDocente char,vCodAsignatura char,vSemestre varchar2)
is
i number;
eCodCarga exception;
eCodDocente exception;
eCodAsignatura exception;
Begin
    select count(*) into i from TCarga where IDCarga=vIDCarga;
    if (i=0) then
     raise eCodCarga;
    end if;
    select count(*) into i from TDocente where CodDocente=vCodDocente;
    if (i=0) then
     raise eCodDocente;
    end if;
    select count(*) into i from TAsignatura where CodAsignatura=vCodAsignatura;
    if (i=0) then
     raise  eCodAsignatura;
    end if;
   
    Update TCarga set CodDocente=vCodDocente,CodAsignatura=vCodAsignatura,Semestre=vSemestre where IDCarga=vIDCarga;
    commit;
    DBMS_OutPut.Put_Line('Carga agregado correctamente ');
    exception
    When eCodCarga then
    DBMS_OutPut.Put_Line('Error:Carga no existe');
    When eCodDocente then
    DBMS_OutPut.Put_Line('Error:Docente  no existe');
    When eCodAsignatura then
    DBMS_OutPut.Put_Line('Error:Asignatura no existe');
end;
begin
spActualizarCarga('C0021','D0010','S0010','V');
end;
begin
spListarCarga;
end;
---Eliminar Carga---
Create  or replace procedure spEliminarCarga
(
vIDCarga char)
is
i number;
eCodCarga exception;
Begin
    select count(*) into i from TCarga where IDCarga=vIDCarga;
    if (i=0) then
     raise eCodCarga;
    end if;
    Delete TCarga where IDCarga=vIDCarga;
    commit;
    DBMS_OutPut.Put_Line('Carga eliminado correctamente ');
    exception
    When eCodCarga then
    DBMS_OutPut.Put_Line('Error:Carga no existe');
end;
begin
spEliminarCarga('C0021');
end;
begin
spListarCarga;
end;
----Agregar Asignatura---
Describe TAsignatura;
Create  or replace procedure spAgregarAsignatura
(
vCodAsignatura char,vAsignatura varchar2,vCodRequisito char)
is
i number;
eCodAsignatura exception;
Begin
    select count(*) into i from TAsignatura where CodAsignatura=vCodAsignatura;
    if (i<>0) then
     raise eCodAsignatura;
    end if;
    insert into TAsignatura values (vCodAsignatura,vAsignatura,vCodRequisito);
    commit;
    DBMS_OutPut.Put_Line('Asignatura agregado correctamente');
    exception
    When eCodAsignatura then
    DBMS_OutPut.Put_Line('Error:Duplicado');
end;
begin
spAgregarAsignatura('S0021','FISICA','S0010');
end;
begin
spListarAsignatura;
end;
---Actualizar Asignatura----
Create  or replace procedure spActualizarAsignatura
(
vCodAsignatura char,vAsignatura varchar2,vCodRequisito char)
is
i number;
eCodAsignatura exception;
Begin
    select count(*) into i from TAsignatura where CodAsignatura=vCodAsignatura;
    if (i=0) then
     raise eCodAsignatura;
    end if;
    update TAsignatura set Asignatura=vAsignatura,CodRequisito=vCodRequisito where CodAsignatura=vCodAsignatura;
    commit;
    DBMS_OutPut.Put_Line('Asignatura agregado correctamente');
    exception
    When eCodAsignatura then
    DBMS_OutPut.Put_Line('Error:Asignatura no existe');
end;
begin
spActualizarAsignatura('S0021','holaa','S0010');
end;
begin
spListarAsignatura;
end;
---Eliminar Asignatura----
Create  or replace procedure spEliminarAsignatura
(
vCodAsignatura char)
is
i number;
eCodAsignatura exception;
eNotas  exception;
Begin
    select count(*) into i from TAsignatura where CodAsignatura=vCodAsignatura;
    if (i=0) then
     raise eCodAsignatura;
    end if;
    select count(*) into  i from TNotas where  CodAsignatura=vCodAsignatura;
    if(i<>0) then
     raise eNotas;
    end if;
    Delete TAsignatura  where CodAsignatura=vCodAsignatura;
    commit;
    DBMS_OutPut.Put_Line('Asignatura Eliminada correctamente');
    exception
    When eCodAsignatura then
    DBMS_OutPut.Put_Line('Error:Asignatura no existe');
    When eNotas then
    DBMS_OutPut.Put_Line('Error:Asignatura existe en TNotas');
end;
begin
spEliminarAsignatura('S0021');
end;
begin
spListarAsignatura;
end;
----Agregar Notas---
describe TNotas;
Create or replace procedure spAgregarNotas
(
vCodAlumno char,vCodAsignatura char,vSemestre char,vPractica1 decimal,vPractica2 decimal,vNotaFinal decimal)
is
i number;
eClave exception;
eCodAlumno exception;
eCodAsignatura exception;
Begin
     select count(*) into  i  from TNotas where CodAlumno=vCodAlumno and CodAsignatura=vCodAsignatura and Semestre=vSemestre;
     if (i<>0) then
       raise eClave;
     end if;
     select count(*) into  i from TAlumno where CodAlumno=vCodAlumno;
     if (i=0) then
       raise eCodAlumno;
     end if;
     select count(*) into i from TAsignatura where CodAsignatura=vCodAsignatura;
     if (i=0) then
       raise eCodAsignatura;
     end if;   
     insert into TNotas values (vCodAlumno,vCodAsignatura,vSemestre,vPractica1,vPractica2,vNotaFinal);
     commit;
     DBMS_OutPut.Put_Line('Nota Agregada correctamente');
     exception
     When eClave then
     DBMS_OutPut.Put_Line('Error: Duplicado ');
     When eCodAlumno then    
     DBMS_OutPut.Put_Line('Error: Alumno no existe ');
     When eCodAsignatura then
     DBMS_OutPut.Put_Line('Error: Asignatura no existe');
end;
begin
spAgregarNotas('A0010','S0010','III','17','17','15');
end;
begin
spListarNotas;
end;  

-----Actualizar Notas----
Create or replace procedure spActualizarNotas
(
vCodAlumno char,vCodAsignatura char,vSemestre char,vPractica1 decimal,vPractica2 decimal,vNotaFinal decimal)
is
i number;
eClave exception;
Begin
     select count(*) into  i  from TNotas where CodAlumno=vCodAlumno and CodAsignatura=vCodAsignatura and Semestre=vSemestre;
     if (i=0) then
       raise eClave;
     end if;
     update TNotas set Practica1=vPractica1,Practica2=vPractica2,NotaFinal=vNotaFinal    where CodAlumno=vCodAlumno  and CodAsignatura=vCodAsignatura and Semestre=vSemestre ;
     commit;
     DBMS_OutPut.Put_Line('Nota Actualizado correctamente');
     exception
     When eClave then
     DBMS_OutPut.Put_Line('Error: Nota no existe');  
end; 
begin
spActualizarNotas('A0010','S0010','III','20','20','20');
end;
begin
spListarNotas;
end;
----Eliminar Notas----
Create or replace procedure spEliminarNotas
(
vCodAlumno char,vCodAsignatura char,vSemestre char,vPractica1 decimal,vPractica2 decimal,vNotaFinal decimal)
is
i number;
eClave exception;
Begin
     select count(*) into  i  from TNotas where CodAlumno=vCodAlumno and CodAsignatura=vCodAsignatura and Semestre=vSemestre;
     if (i=0) then
       raise eClave;
     end if;
     Delete TNotas    where CodAlumno=vCodAlumno  and CodAsignatura=vCodAsignatura and Semestre=vSemestre ;
     commit;
     DBMS_OutPut.Put_Line('Nota Eliminada correctamente');
     exception
     When eClave then
     DBMS_OutPut.Put_Line('Error: Nota no existe');  
end;
begin
spEliminarNotas('A0010','S0010','III','20','20','20');
end;
begin
spListarNotas;

end;

No hay comentarios.:

Publicar un comentario

Gracias por participar ..!!