Advertisement
alexarcan

dbd_lab11_last_export

Dec 12th, 2016
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. --------------------------------------------------------
  2. -- File created - Monday-December-05-2016
  3. --------------------------------------------------------
  4. --------------------------------------------------------
  5. -- DDL for Table DIRECTORIES
  6. --------------------------------------------------------
  7.  
  8. CREATE TABLE "DIRECTORIES"
  9. ( "DIRECTORYID" NUMBER(20,0),
  10. "NAME" VARCHAR2(20 BYTE),
  11. "PARENTID" NUMBER
  12. ) ;
  13. --------------------------------------------------------
  14. -- DDL for Table FILES
  15. --------------------------------------------------------
  16.  
  17. CREATE TABLE "FILES"
  18. ( "FILEID" NUMBER(20,0),
  19. "NAME" VARCHAR2(20 BYTE),
  20. "DIRECTORYID" NUMBER(20,0),
  21. "CONTENT" VARCHAR2(200 BYTE)
  22. ) ;
  23. REM INSERTING into DIRECTORIES
  24. Insert into DIRECTORIES (DIRECTORYID,NAME,PARENTID) values (10,'documentaries',3);
  25. Insert into DIRECTORIES (DIRECTORYID,NAME,PARENTID) values (11,'A',1);
  26. Insert into DIRECTORIES (DIRECTORYID,NAME,PARENTID) values (12,'B',7);
  27. Insert into DIRECTORIES (DIRECTORYID,NAME,PARENTID) values (1,'music',null);
  28. Insert into DIRECTORIES (DIRECTORYID,NAME,PARENTID) values (2,'genres',1);
  29. Insert into DIRECTORIES (DIRECTORYID,NAME,PARENTID) values (3,'movies',null);
  30. Insert into DIRECTORIES (DIRECTORYID,NAME,PARENTID) values (4,'documents',null);
  31. Insert into DIRECTORIES (DIRECTORYID,NAME,PARENTID) values (5,'books',4);
  32. Insert into DIRECTORIES (DIRECTORYID,NAME,PARENTID) values (6,'english books',5);
  33. Insert into DIRECTORIES (DIRECTORYID,NAME,PARENTID) values (7,'pop',2);
  34. Insert into DIRECTORIES (DIRECTORYID,NAME,PARENTID) values (8,'jazz',2);
  35. Insert into DIRECTORIES (DIRECTORYID,NAME,PARENTID) values (9,'oldies',7);
  36. REM INSERTING into FILES
  37. Insert into FILES (FILEID,NAME,DIRECTORYID,CONTENT) values (8,'best_jazz',8,'nopnop');
  38. Insert into FILES (FILEID,NAME,DIRECTORYID,CONTENT) values (1,'inna.mp3',7,'def');
  39. Insert into FILES (FILEID,NAME,DIRECTORYID,CONTENT) values (2,'pitbull.wav',7,'ghi');
  40. Insert into FILES (FILEID,NAME,DIRECTORYID,CONTENT) values (3,'titanic.avi',3,'j');
  41. Insert into FILES (FILEID,NAME,DIRECTORYID,CONTENT) values (4,'wall-e.avi',3,'k');
  42. Insert into FILES (FILEID,NAME,DIRECTORYID,CONTENT) values (5,'Rich dad Poor dad',5,'l');
  43. Insert into FILES (FILEID,NAME,DIRECTORYID,CONTENT) values (6,'Life of Pi',6,'m');
  44. Insert into FILES (FILEID,NAME,DIRECTORYID,CONTENT) values (7,'jazz.mp3',8,'nopnop');
  45. --------------------------------------------------------
  46. -- DDL for Index DIRECTORIES_PK
  47. --------------------------------------------------------
  48.  
  49. CREATE UNIQUE INDEX "DIRECTORIES_PK" ON "DIRECTORIES" ("DIRECTORYID")
  50. ;
  51. --------------------------------------------------------
  52. -- DDL for Index FILES_PK
  53. --------------------------------------------------------
  54.  
  55. CREATE UNIQUE INDEX "FILES_PK" ON "FILES" ("FILEID")
  56. ;
  57. --------------------------------------------------------
  58. -- Constraints for Table FILES
  59. --------------------------------------------------------
  60.  
  61. ALTER TABLE "FILES" ADD CONSTRAINT "FILES_PK" PRIMARY KEY ("FILEID") ENABLE;
  62.  
  63. ALTER TABLE "FILES" MODIFY ("FILEID" NOT NULL ENABLE);
  64. --------------------------------------------------------
  65. -- Constraints for Table DIRECTORIES
  66. --------------------------------------------------------
  67.  
  68. ALTER TABLE "DIRECTORIES" ADD CONSTRAINT "DIRECTORIES_PK" PRIMARY KEY ("DIRECTORYID") ENABLE;
  69.  
  70. ALTER TABLE "DIRECTORIES" MODIFY ("DIRECTORYID" NOT NULL ENABLE);
  71. --------------------------------------------------------
  72. -- Ref Constraints for Table DIRECTORIES
  73. --------------------------------------------------------
  74.  
  75. ALTER TABLE "DIRECTORIES" ADD CONSTRAINT "DIRECTORIES_DIRECTORIES_FK1" FOREIGN KEY ("PARENTID")
  76. REFERENCES "DIRECTORIES" ("DIRECTORYID") ENABLE;
  77. --------------------------------------------------------
  78. -- Ref Constraints for Table FILES
  79. --------------------------------------------------------
  80.  
  81. ALTER TABLE "FILES" ADD FOREIGN KEY ("DIRECTORYID")
  82. REFERENCES "DIRECTORIES" ("DIRECTORYID") ON DELETE CASCADE ENABLE;
  83. --------------------------------------------------------
  84. -- DDL for Function TINC
  85. --------------------------------------------------------
  86.  
  87. CREATE OR REPLACE FUNCTION "TINC"
  88. (
  89. NAME_IN IN VARCHAR2
  90. ) RETURN VARCHAR2 AS
  91. total_val NUMBER(20);
  92. BEGIN
  93. total_val := 0;
  94.  
  95. FOR emp in (SELECT income FROM employee WHERE name = name_in)
  96. LOOP
  97. total_val := total_val + emp.income;
  98. END LOOP;
  99. RETURN total_val;
  100. END TINC;
  101.  
  102. /
  103.  
  104. --------------------------------------------------------
  105. -- DDL for Procedure COMPUTETOTALINCOME
  106. --------------------------------------------------------
  107. set define off;
  108.  
  109. CREATE OR REPLACE PROCEDURE "COMPUTETOTALINCOME"
  110. AS
  111. BEGIN
  112. dbms_output.put_line(TINC('B'));
  113. END;
  114.  
  115. BEGIN
  116. computeTotalIncome();
  117. END;
  118.  
  119. /
  120.  
  121. --------------------------------------------------------
  122. -- DDL for Procedure LS
  123. --------------------------------------------------------
  124. set define off;
  125.  
  126. CREATE OR REPLACE PROCEDURE "LS"
  127. (
  128. DIRID IN directories.directoryid%TYPE
  129. ) AS
  130. norows EXCEPTION;
  131. CURSOR results IS
  132. select name
  133. from (select directoryid, name, parentid from directories
  134. union
  135. select 0, name, directoryid from files) res
  136. where parentid=dirid;
  137. BEGIN
  138. if SQL%ROWCOUNT=0 then
  139. raise norows;
  140. else
  141. dbms_output.put_line('Directories and files found in the directory with id '||dirid||':');
  142. FOR rec in results LOOP
  143. dbms_output.put_line(rec.name);
  144. END LOOP;
  145. end if;
  146. EXCEPTION
  147. when norows then
  148. dbms_output.put_line('Directory with id '||dirid||' is empty.');
  149. END LS;
  150.  
  151. /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement