SHARE
TWEET

CLONAR TABLAS , UNION INTERSECCION Y MINUS

Lisaard1045 Oct 12th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Como clonar tablas
  2. CREATE TABLE EMPLOYEES_2 AS
  3. (
  4. SELECT *
  5. FROM EMPLOYEES
  6. );
  7.  
  8. CREATE TABLE EMPLOYEES_3 AS
  9. (
  10. SELECT EMPLOYEE_ID AS ID_EMPLEADO,
  11.        FIRST_NAME || ' ' || LAST_NAME AS NOMBRE_COMPLETO
  12. FROM EMPLOYEES
  13. WHERE JOB_ID = 'IT_PROG'
  14. );
  15.  
  16. CREATE TABLE EMPLOYEES_4 AS
  17. (
  18. SELECT * FROM EMPLOYEES
  19. WHERE 1 = 2
  20. );
  21.  
  22. CREATE TABLE EMPDPTO30 AS
  23. (
  24. SELECT * FROM EMPLOYEES
  25. WHERE DEPARTMENT_ID = 30
  26. );
  27.  
  28. CREATE TABLE EMPDPTO20 AS
  29. (
  30. SELECT * FROM EMPLOYEES
  31. WHERE DEPARTMENT_ID = 20
  32. );
  33.  
  34. CREATE TABLE EMPLEADOS AS
  35. (
  36. SELECT * FROM EMPLOYEES
  37. WHERE DEPARTMENT_ID IN (20,30,70,90)
  38. );
  39.  
  40. SELECT * FROM EMPDPTO30;
  41. SELECT * FROM EMPDPTO20;
  42. SELECT * FROM EMPLEADOS;
  43.  
  44. DROP TABLE EMPDPTO30;
  45. -----------------------------------------------------
  46. --INSERTAR DOS VALORES NUEVOS
  47.  
  48. INSERT INTO EMPDPTO30
  49. VALUES ('201','Michael','Hartstein','MHARTSTE','515.123.5555','17/02/04','MK_MAN',13000,NULL,100,20);
  50.  
  51. INSERT INTO EMPDPTO30
  52. VALUES ('202','Pat','Fay','PFAY','603.123.6666','17/08/05','MK_REP',6000,NULL,201,20);
  53. ----------------------------------------------
  54. --UNION
  55. SELECT E.FIRST_NAME || ' ' ||E.LAST_NAME AS NOMBRE_COMPLETO,
  56.        D.DEPARTMENT_ID,
  57.        D.DEPARTMENT_NAME
  58. FROM EMPDPTO20 E
  59. INNER JOIN DEPARTMENTS D ON(E.DEPARTMENT_ID=D.DEPARTMENT_ID)
  60. UNION
  61. SELECT E.FIRST_NAME || ' ' ||E.LAST_NAME AS NOMBRE_COMPLETO,
  62.        D.DEPARTMENT_ID,
  63.        D.DEPARTMENT_NAME
  64. FROM EMPDPTO30 E
  65. INNER JOIN DEPARTMENTS D ON(E.DEPARTMENT_ID=D.DEPARTMENT_ID);
  66.  
  67. --VER PPT 27 PARA MAS INFORMACION
RAW Paste Data
Top