Advertisement
Guest User

tablas

a guest
Feb 2nd, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.77 KB | None | 0 0
  1. create user tablas_se identified by tablas_se
  2. default tablespace users
  3. temporary tablespace temp
  4. quota unlimited on users;
  5.  
  6. create user tablas_sc identified by tablas_sc
  7. default tablespace users
  8. temporary tablespace temp
  9. quota unlimited on users;
  10.  
  11. create user tablas_sm identified by tablas_sm
  12. default tablespace users
  13. temporary tablespace temp
  14. quota unlimited on users;
  15.  
  16. grant create session, create table to tablas_sc;
  17. grant create session, create table to tablas_sm;
  18. grant create session, create table to tablas_se;
  19.  
  20. -------------------------------------------------
  21.  
  22. New connection
  23. Name: Conexion SC
  24. User: tablas_sc
  25. Pass: tablas_sc
  26. Connection type: TNS
  27. Network Alias: BD04/Test
  28.  
  29. (hacer lo mismo con sm y se)
  30. -------------------------------------------------
  31.  
  32. ** alterar pass
  33. alter user tablas_se by tablas_se
  34.  
  35. -------------------------------------------------
  36. ** DESDE TABLAS_SC **
  37.  
  38. create table Facultades(
  39. IdFacultad number constraint pk_Facultades primary key,
  40. NombreFacultad varchar2(30),
  41. Edificio varchar2(3));
  42.  
  43. ** Para revisar si existe, desde system
  44. select owner, object_name, object_type
  45. from dba_objects
  46. where owner like 'TABLAS%';
  47. **
  48.  
  49. Create table Carreras(
  50. IdCarrera number constraint pk_Carreras primary key,
  51. NombreCarrera varchar2(30),
  52. Facultad constraint fk1_Carreras references Facultades);
  53.  
  54. grant references on carreras to tablas_se;
  55.  
  56. Create table CursosC(
  57. Carrera constraint fk1_CursosC references Carreras,
  58. IdCurso number,
  59. NombreCurso varchar2(30),
  60. Creditos number,
  61. constraint pk_CursosC primary key(Carrera, IdCurso));
  62.  
  63. grant references on cursosc to tablas_sm;
  64.  
  65. select object_name, object_type
  66. from user_objects;
  67.  
  68. ** DESDE TABLAS_SE **
  69.  
  70. create table estudiantes(
  71. Carnet number constraint pk_estudiantes primary key,
  72. NombreEstudiante varchar2(30),
  73. Sexo varchar2(1),
  74. Telefono varchar2(7),
  75. Provincia varchar2(30));
  76.  
  77. grant references on estudiantes to tablas_sm;
  78.  
  79. Create table asociado(
  80. Carrera constraint fk1_Asociado references tablas_sc.Carreras,
  81. Estudiante constraint fk2_Asociado references Estudiantes,
  82. Desde date,
  83. Hasta date,
  84. constraint pk_asociado primary key (Carrera, Estudiante));
  85.  
  86.  
  87. ** DESDE SYSTEM **
  88. from dba_tab_privs
  89. where grantee like 'TABLAS%' or grantor like 'TABLAS%';
  90.  
  91. ** DESDE TABLAS_SM **
  92.  
  93. Create table Grupos(
  94. Carrera number,
  95. Curso number,
  96. NumeroGrupo number,
  97. Cuatrimestre varchar2(30),
  98. Aula varchar2(4),
  99. Horario varchar2(10),
  100. Capacidad number,
  101. constraint fk1_Grupos foreign key(Carrera,Curso) references tablas_sc.CursosC,
  102. constraint pk_Grupos primary key(Carrera,Curso,NumeroGrupo,Cuatrimestre));
  103.  
  104. -----------
  105.  
  106. user: sys as sysdba
  107. pass: test/bd04
  108. server: test/bd04
  109.  
  110. alter user system identified by test; -- o bd04
  111. alter user system account unlock;
  112.  
  113.  
  114. ------------- desde system
  115.  
  116. create user plsql identified by plsql
  117. default tablespace users
  118. temporary tablespace temp
  119. quota unlimited on users;
  120.  
  121. grant create session, create table, create procedure to plsql;
  122.  
  123.  
  124. -------------- nueva conexion
  125.  
  126. name: Conexion PLSQL
  127. user/pass: plsql
  128. server: test/bd04
  129.  
  130. ---------------- desde plsql
  131.  
  132. DECLARE
  133. x NUMBER := 100;
  134. BEGIN
  135. FOR i IN 1..10 LOOP
  136. IF MOD(i,2) = 0 THEN -- i is even
  137. INSERT INTO temp VALUES (i, x, 'i is even');
  138. ELSE
  139. INSERT INTO temp VALUES (i, x, 'i is odd');
  140. END IF;
  141.  
  142. x := x + 100;
  143. END LOOP;
  144. COMMIT;
  145. END;
  146. /
  147.  
  148.  
  149.  
  150.  
  151. select *
  152. from temp;
  153.  
  154. select *
  155. from emp;
  156.  
  157. delete temp;
  158.  
  159.  
  160.  
  161.  
  162. DECLARE
  163. CURSOR c1 is
  164. SELECT ename, empno, sal FROM emp
  165. ORDER BY sal DESC; -- start with highest-paid employee
  166. my_ename CHAR(10);
  167. my_empno NUMBER(4);
  168. my_sal NUMBER(7,2);
  169.  
  170. BEGIN
  171. OPEN c1;
  172.  
  173. FOR i IN 1..5 LOOP
  174. FETCH c1 INTO my_ename, my_empno, my_sal;
  175. EXIT WHEN c1%NOTFOUND; /* in case the number requested is more *
  176. * than the total number of employees */
  177. INSERT INTO temp VALUES (my_sal, my_empno, my_ename);
  178. COMMIT;
  179. END LOOP;
  180.  
  181. CLOSE c1;
  182. END;
  183. /
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190. select *
  191. from temp
  192. order by 1 desc;
  193.  
  194. delete temp;
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201. DECLARE
  202. x NUMBER := 0;
  203. counter NUMBER := 0;
  204. BEGIN
  205. FOR i IN 1..4 LOOP
  206. x := x + 1000;
  207. counter := counter + 1;
  208. INSERT INTO temp VALUES (x, counter, 'in OUTER loop');
  209.  
  210. /* start an inner block */
  211. DECLARE
  212. x NUMBER := 0; -- this is a local version of x
  213. BEGIN
  214. FOR i IN 1..4 LOOP
  215. x := x + 1; -- this increments the local x
  216. counter := counter + 1;
  217. INSERT INTO temp VALUES (x, counter, 'inner loop');
  218. END LOOP;
  219. END;
  220.  
  221. END LOOP;
  222. COMMIT;
  223. END;
  224. /
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231. select * from temp;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement