Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // head
- create or replace package pk_empleados is
- procedure p_nuevo_empleado (p_id number,p_dni varchar2, p_nombre varchar2,
- p_apellido1 varchar2, p_apellido2 varchar2, p_domicilio varchar2, p_codigopostal number,
- p_telefono varchar2, p_email varchar2, p_catempl number, p_fechaalta date,p_username varchar2,
- p_password varchar2);
- procedure p_eliminar_empleado (p_id number);
- procedure p_modificar_empleado(p_id number,p_dni varchar2, p_nombre varchar2,
- p_apellido1 varchar2, p_apellido2 varchar2, p_domicilio varchar2, p_codigopostal number,
- p_telefono varchar2, p_email varchar2, p_catempl number, p_fechaalta date, p_nombreusuario varchar2,
- p_Password varchar2);
- end;
- //body
- create or replace package body pk_empleados as
- procedure p_nuevo_empleado (p_id number,p_dni varchar2, p_nombre varchar2,
- p_apellido1 varchar2, p_apellido2 varchar2, p_domicilio varchar2, p_codigopostal number,
- p_telefono varchar2, p_email varchar2, p_catempl number, p_fechaalta date,p_username varchar2,
- p_password varchar2) is
- sentencia varchar2(500);
- begin
- insert into empleado values(p_id,p_dni,p_nombre,p_apellido1,p_apellido2,p_domicilio,p_codigopostal,
- p_telefono,p_email,p_catempl,p_fechaalta,p_username);
- if p_username is not null then
- sentencia := 'create user ' || p_username || ' identified by ' ||p_password ||' default tablespace ts_mercoracle';
- dbms_output.put_line(sentencia);
- execute immediate (sentencia);
- if p_catempl = 1 then
- sentencia := 'grant R_DIRECTOR to ' || p_username;
- DBMS_OUTPUT.PUT_line(sentencia);
- execute immediate (sentencia);
- elsif p_catempl = 2 then
- sentencia := 'grant R_SUPERVISOR to ' || p_username;
- DBMS_OUTPUT.PUT_line(sentencia);
- execute immediate (sentencia);
- elsif p_catempl = 3 then
- sentencia := 'grant R_CAJERO to ' || p_username;
- DBMS_OUTPUT.PUT_line(sentencia);
- execute immediate (sentencia);
- end if;
- end if;
- end;
- procedure p_eliminar_empleado (p_id number) is
- p_usuario varchar2 (30);
- sentencia2 varchar2(300);
- begin
- select usuario into p_usuario from empleado where id = p_id;
- delete from empleado where id = p_id;
- if p_usuario is not null then
- sentencia2 := 'drop user' || p_usuario;
- execute immediate (sentencia2);
- end if;
- end;
- procedure p_modificar_empleado(p_id number,p_dni varchar2, p_nombre varchar2,
- p_apellido1 varchar2, p_apellido2 varchar2, p_domicilio varchar2, p_codigopostal number,
- p_telefono varchar2, p_email varchar2, p_catempl number, p_fechaalta date, p_nombreusuario varchar2,
- p_Password varchar2) is
- p_username varchar2(30);
- sentencia varchar2 (300);
- begin
- select usuario into p_username from empleado where id = p_id;
- if p_dni is not null then
- update empleado set dni = p_dni where id = p_id;
- end if;
- if p_nombre is not null then
- update empleado set nombre = p_nombre where id = p_id;
- end if;
- if p_apellido1 is not null then
- update empleado set apellido1 = p_apellido1 where id = p_id;
- end if;
- if p_apellido2 is not null then
- update empleado set apellido2 = p_apellido2 where id = p_id;
- end if;
- if p_domicilio is not null then
- update empleado set domicilio = p_domicilio where id = p_id;
- end if;
- if p_codigopostal is not null then
- update empleado set codigo_postal = p_codigopostal where id = p_id;
- end if;
- if p_telefono is not null then
- update empleado set telefono = p_telefono where id = p_id;
- end if;
- if p_email is not null then
- update empleado set email = p_email where id = p_id;
- end if;
- if p_catempl is not null then
- update empleado set cat_empleado = p_catempl where id = p_id;
- end if;
- if p_fechaalta is not null then
- update empleado set fecha_alta = p_fechaalta where id = p_id;
- end if;
- if p_nombreusuario is not null and p_password is not null then
- sentencia := 'alter user '||p_nombreusuario||' identify by '||p_password;
- execute immediate (sentencia);
- end if;
- if p_nombreusuario is null and p_password is not null then
- sentencia := 'create user ' || p_username || ' identified by ' ||p_password ||' default tablespace ts_mercoracle';
- dbms_output.put_line(sentencia);
- execute immediate (sentencia);
- if p_catempl = 1 then
- sentencia := 'grant R_DIRECTOR to ' || p_username;
- DBMS_OUTPUT.PUT_line(sentencia);
- execute immediate (sentencia);
- elsif p_catempl = 2 then
- sentencia := 'grant R_SUPERVISOR to ' || p_username;
- DBMS_OUTPUT.PUT_line(sentencia);
- execute immediate (sentencia);
- elsif p_catempl = 3 then
- sentencia := 'grant R_CAJERO to ' || p_username;
- DBMS_OUTPUT.PUT_line(sentencia);
- execute immediate (sentencia);
- end if;
- end if;
- commit;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement