Advertisement
alexarcan

lab9_DBD_export_work

Nov 21st, 2016
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. --------------------------------------------------------
  2. -- File created - Monday-November-21-2016
  3. --------------------------------------------------------
  4. --------------------------------------------------------
  5. -- DDL for Table EMPLOYEE
  6. --------------------------------------------------------
  7.  
  8. CREATE TABLE "EMPLOYEE"
  9. ( "ID" NUMBER(20,0),
  10. "NAME" VARCHAR2(20 BYTE),
  11. "INCOME" NUMBER(20,0)
  12. ) ;
  13. REM INSERTING into EMPLOYEE
  14. Insert into EMPLOYEE (ID,NAME,INCOME) values (1,'A',10);
  15. Insert into EMPLOYEE (ID,NAME,INCOME) values (2,'B',20);
  16. Insert into EMPLOYEE (ID,NAME,INCOME) values (3,'C',10);
  17. Insert into EMPLOYEE (ID,NAME,INCOME) values (4,'A',40);
  18. --------------------------------------------------------
  19. -- DDL for Index EMPLOYEE_PK
  20. --------------------------------------------------------
  21.  
  22. CREATE UNIQUE INDEX "EMPLOYEE_PK" ON "EMPLOYEE" ("ID")
  23. ;
  24. --------------------------------------------------------
  25. -- Constraints for Table EMPLOYEE
  26. --------------------------------------------------------
  27.  
  28. ALTER TABLE "EMPLOYEE" ADD CONSTRAINT "EMPLOYEE_PK" PRIMARY KEY ("ID") ENABLE;
  29.  
  30. ALTER TABLE "EMPLOYEE" MODIFY ("ID" NOT NULL ENABLE);
  31. --------------------------------------------------------
  32. -- DDL for Function TINC
  33. --------------------------------------------------------
  34.  
  35. CREATE OR REPLACE FUNCTION "TINC"
  36. (
  37. NAME_IN IN VARCHAR2
  38. ) RETURN VARCHAR2 AS
  39. total_val NUMBER(20);
  40. BEGIN
  41. total_val := 0;
  42.  
  43. FOR emp in (SELECT income FROM employee WHERE name = name_in)
  44. LOOP
  45. total_val := total_val + emp.income;
  46. END LOOP;
  47. --dbms_output.put_line(total_val);
  48. RETURN total_val;
  49. END TINC;
  50.  
  51. /
  52.  
  53. --------------------------------------------------------
  54. -- DDL for Function TOTALINCOME
  55. --------------------------------------------------------
  56.  
  57. CREATE OR REPLACE FUNCTION "TOTALINCOME"
  58. ( name_in IN varchar2 )
  59. RETURN varchar2
  60. IS
  61. total_val number(20);
  62.  
  63. DECLARE
  64. total_val NUMBER := 0;
  65. cursor c1 is
  66. SELECT income
  67. FROM employee
  68. WHERE name = name_in;
  69. BEGIN
  70. FOR emp in c1
  71. LOOP
  72. total_val := total_val + emp.income;
  73. END LOOP;
  74. dbms_output.put_line(total_val);
  75. --RETURN total_val;
  76. END;
  77.  
  78. /
  79.  
  80. --------------------------------------------------------
  81. -- DDL for Procedure COMPUTEINCOME
  82. --------------------------------------------------------
  83. set define off;
  84.  
  85. CREATE OR REPLACE PROCEDURE "COMPUTEINCOME"
  86. AS
  87. BEGIN
  88. dbms_output.put_line('Hello World!');
  89. END;
  90. execute computeIncome;
  91.  
  92. /
  93.  
  94. --------------------------------------------------------
  95. -- DDL for Procedure COMPUTETOTAL
  96. --------------------------------------------------------
  97. set define off;
  98.  
  99. CREATE OR REPLACE PROCEDURE "COMPUTETOTAL"
  100. AS
  101. BEGIN
  102. -- TotalIncome('A');
  103. TINC('das');
  104. END;
  105.  
  106. EXECUTE computeTotal;
  107.  
  108. /
  109.  
  110. --------------------------------------------------------
  111. -- DDL for Procedure COMPUTETOTALINCOME
  112. --------------------------------------------------------
  113. set define off;
  114.  
  115. CREATE OR REPLACE PROCEDURE "COMPUTETOTALINCOME"
  116. AS
  117. BEGIN
  118. dbms_output.put_line(TINC('B'));
  119. END;
  120.  
  121. BEGIN
  122. computeTotalIncome();
  123. END;
  124.  
  125. /
  126.  
  127. --------------------------------------------------------
  128. -- DDL for Procedure GREETINGS
  129. --------------------------------------------------------
  130. set define off;
  131.  
  132. CREATE OR REPLACE PROCEDURE "GREETINGS"
  133. AS
  134. BEGIN
  135. dbms_output.put_line('Hello World!');
  136. END;
  137.  
  138. /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement