Advertisement
Guest User

Untitled

a guest
May 21st, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. // head
  2.  
  3. create or replace package pk_empleados is
  4.  
  5. procedure p_nuevo_empleado (p_id number,p_dni varchar2, p_nombre varchar2,
  6. p_apellido1 varchar2, p_apellido2 varchar2, p_domicilio varchar2, p_codigopostal number,
  7. p_telefono varchar2, p_email varchar2, p_catempl number, p_fechaalta date,p_username varchar2,
  8. p_password varchar2);
  9.  
  10. procedure p_eliminar_empleado (p_id number);
  11.  
  12. procedure p_modificar_empleado(p_id number,p_dni varchar2, p_nombre varchar2,
  13. p_apellido1 varchar2, p_apellido2 varchar2, p_domicilio varchar2, p_codigopostal number,
  14. p_telefono varchar2, p_email varchar2, p_catempl number, p_fechaalta date, p_nombreusuario varchar2,
  15. p_Password varchar2);
  16. end;
  17.  
  18. //body
  19.  
  20. create or replace package body pk_empleados as
  21.  
  22.  
  23. procedure p_nuevo_empleado (p_id number,p_dni varchar2, p_nombre varchar2,
  24. p_apellido1 varchar2, p_apellido2 varchar2, p_domicilio varchar2, p_codigopostal number,
  25. p_telefono varchar2, p_email varchar2, p_catempl number, p_fechaalta date,p_username varchar2,
  26. p_password varchar2) is
  27. sentencia varchar2(500);
  28. begin
  29. insert into empleado values(p_id,p_dni,p_nombre,p_apellido1,p_apellido2,p_domicilio,p_codigopostal,
  30. p_telefono,p_email,p_catempl,p_fechaalta,p_username);
  31. if p_username is not null then
  32. sentencia := 'create user ' || p_username || ' identified by ' ||p_password ||' default tablespace ts_mercoracle';
  33. dbms_output.put_line(sentencia);
  34. execute immediate (sentencia);
  35. if p_catempl = 1 then
  36. sentencia := 'grant R_DIRECTOR to ' || p_username;
  37. DBMS_OUTPUT.PUT_line(sentencia);
  38. execute immediate (sentencia);
  39. elsif p_catempl = 2 then
  40. sentencia := 'grant R_SUPERVISOR to ' || p_username;
  41. DBMS_OUTPUT.PUT_line(sentencia);
  42. execute immediate (sentencia);
  43. elsif p_catempl = 3 then
  44. sentencia := 'grant R_CAJERO to ' || p_username;
  45. DBMS_OUTPUT.PUT_line(sentencia);
  46. execute immediate (sentencia);
  47. end if;
  48. end if;
  49. end;
  50.  
  51. procedure p_eliminar_empleado (p_id number) is
  52. p_usuario varchar2 (30);
  53. sentencia2 varchar2(300);
  54. begin
  55. select usuario into p_usuario from empleado where id = p_id;
  56.  
  57. delete from empleado where id = p_id;
  58.  
  59. if p_usuario is not null then
  60. sentencia2 := 'drop user' || p_usuario;
  61. execute immediate (sentencia2);
  62. end if;
  63. end;
  64.  
  65. procedure p_modificar_empleado(p_id number,p_dni varchar2, p_nombre varchar2,
  66. p_apellido1 varchar2, p_apellido2 varchar2, p_domicilio varchar2, p_codigopostal number,
  67. p_telefono varchar2, p_email varchar2, p_catempl number, p_fechaalta date, p_nombreusuario varchar2,
  68. p_Password varchar2) is
  69. p_username varchar2(30);
  70. sentencia varchar2 (300);
  71. begin
  72.  
  73. select usuario into p_username from empleado where id = p_id;
  74.  
  75. if p_dni is not null then
  76. update empleado set dni = p_dni where id = p_id;
  77. end if;
  78. if p_nombre is not null then
  79. update empleado set nombre = p_nombre where id = p_id;
  80. end if;
  81. if p_apellido1 is not null then
  82. update empleado set apellido1 = p_apellido1 where id = p_id;
  83. end if;
  84. if p_apellido2 is not null then
  85. update empleado set apellido2 = p_apellido2 where id = p_id;
  86. end if;
  87. if p_domicilio is not null then
  88. update empleado set domicilio = p_domicilio where id = p_id;
  89. end if;
  90. if p_codigopostal is not null then
  91. update empleado set codigo_postal = p_codigopostal where id = p_id;
  92. end if;
  93. if p_telefono is not null then
  94. update empleado set telefono = p_telefono where id = p_id;
  95. end if;
  96. if p_email is not null then
  97. update empleado set email = p_email where id = p_id;
  98. end if;
  99. if p_catempl is not null then
  100. update empleado set cat_empleado = p_catempl where id = p_id;
  101. end if;
  102. if p_fechaalta is not null then
  103. update empleado set fecha_alta = p_fechaalta where id = p_id;
  104. end if;
  105.  
  106. if p_nombreusuario is not null and p_password is not null then
  107.  
  108. sentencia := 'alter user '||p_nombreusuario||' identify by '||p_password;
  109. execute immediate (sentencia);
  110. end if;
  111.  
  112. if p_nombreusuario is null and p_password is not null then
  113.  
  114. sentencia := 'create user ' || p_username || ' identified by ' ||p_password ||' default tablespace ts_mercoracle';
  115. dbms_output.put_line(sentencia);
  116. execute immediate (sentencia);
  117. if p_catempl = 1 then
  118. sentencia := 'grant R_DIRECTOR to ' || p_username;
  119. DBMS_OUTPUT.PUT_line(sentencia);
  120. execute immediate (sentencia);
  121. elsif p_catempl = 2 then
  122. sentencia := 'grant R_SUPERVISOR to ' || p_username;
  123. DBMS_OUTPUT.PUT_line(sentencia);
  124. execute immediate (sentencia);
  125. elsif p_catempl = 3 then
  126. sentencia := 'grant R_CAJERO to ' || p_username;
  127. DBMS_OUTPUT.PUT_line(sentencia);
  128. execute immediate (sentencia);
  129. end if;
  130. end if;
  131.  
  132.  
  133. commit;
  134.  
  135.  
  136.  
  137.  
  138. end;
  139.  
  140. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement