Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. create or replace package TestBD AS
  2. procedure displayAuthor (id_of_author AUTHOR.AUTHORID%TYPE);
  3. end TestBD;
  4. /
  5.  
  6. create or replace package body TestBD AS
  7. cursor c_books (id_of_author AUTHOR.AUTHORID%TYPE) IS
  8. (
  9. SELECT TITLE FROM BOOKAUTHOR
  10. INNER JOIN BOOKS
  11. ON BOOKAUTHOR.ISBN = BOOKS.ISBN
  12. WHERE AUTHORID = id_of_author
  13. );
  14.  
  15. book_title varchar2(50);
  16.  
  17. function countOrders (title_of_book varchar2) return number is total_orders number;
  18. begin
  19. SELECT COUNT(*) INTO total_orders
  20. FROM BOOKORDERS
  21. INNER JOIN BOOKORDERITEMS
  22. ON BOOKORDERS.ORDER# = BOOKORDERITEMS.ORDER#
  23. INNER JOIN BOOKS
  24. ON BOOKORDERITEMS.ISBN = BOOKS.ISBN
  25. WHERE TITLE = title_of_book;
  26.  
  27. return title_of_book;
  28. end;
  29.  
  30. procedure displayAuthor (id_of_author AUTHOR.AUTHORID%TYPE) IS
  31. begin
  32. OPEN c_books(id_of_author);
  33. LOOP
  34. exit when c_books%notfound;
  35. FETCH c_books into book_title;
  36. dbms_output.put_line(book_title);
  37. END LOOP;
  38. end;
  39. END TestBD;
  40. /
  41.  
  42. declare
  43.  
  44. begin
  45. TestBD.displayAuthor('autor');
  46. dbms_output.put_line('boss');
  47. end;
  48.  
  49.  
  50. ------------_--
  51.  
  52. --------------------------------- cursor
  53. --cursor clasic
  54.  
  55. declare
  56. cursor C is (select * from employees);
  57. angajati employees%rowtype;
  58.  
  59. begin
  60. open C;
  61. loop
  62. fetch C into angajati;
  63. exit when C%notfound;
  64. dbms_output.put_line(angajati.employee_id||' '||angajati.first_name);
  65.  
  66. end loop;
  67. close C;
  68. end;
  69. /
  70.  
  71.  
  72.  
  73.  
  74. --cursor clasic cu parametru
  75. declare
  76. cursor C(eid employees.employee_id%type) is
  77. (select * from employees
  78. where employee_id = eid);
  79. angajati employees%rowtype;
  80.  
  81. begin
  82. open C(100);
  83. loop
  84. fetch C into angajati;
  85. exit when C%notfound;
  86. dbms_output.put_line(angajati.employee_id||' '||angajati.first_name);
  87.  
  88. end loop;
  89. close C;
  90. end;
  91. /
  92.  
  93.  
  94.  
  95.  
  96.  
  97. --cursor ciclu
  98. declare
  99. cursor C is (select * from employees );
  100. angajati employees%rowtype;
  101.  
  102. begin
  103. for i in C loop
  104. --if C%isopen then
  105. -- dbms_output.put_line(i.employee_id||' este deschis');
  106. dbms_output.put_line(i.employee_id||' '||i.salary);
  107. -- end if;
  108. end loop;
  109.  
  110. end;
  111. /
  112.  
  113.  
  114.  
  115. --cursor ciclu cu subcereri
  116.  
  117. begin
  118. for i in (select * from employees) loop
  119. dbms_output.put_line(i.employee_id||' '||i.salary);
  120. end loop;
  121.  
  122. end;
  123. /
  124.  
  125. ---------------------------------------- functii
  126.  
  127. DECLARE
  128. num number;
  129. factorial number;
  130.  
  131. FUNCTION fact(x number)
  132. RETURN number
  133. IS
  134. f number;
  135. BEGIN
  136. IF x=0 THEN
  137. f := 1;
  138. ELSE
  139. f := x * fact(x-1);
  140. END IF;
  141. RETURN f;
  142. END;
  143.  
  144. BEGIN
  145. num:= 6;
  146. factorial := fact(num);
  147. dbms_output.put_line(' Factorial '|| num || ' is ' || factorial);
  148. END;
  149.  
  150.  
  151. -----------------------------------
  152.  
  153. l_first VARCHAR2 (10) := 'Steven';
  154.  
  155.  
  156. type grades IS VARRAY(5) OF INTEGER;
  157. marks grades;
  158.  
  159.  
  160.  
  161.  
  162. __________________________________
  163.  
  164. DECLARE
  165. cont NUMBER := 1;
  166. val NUMBER := 0;
  167. numarAng NUMBER := 0;
  168. ValoareTol NUMBER := 0;
  169.  
  170. BEGIN
  171. FOR jb IN (SELECT job_id,job_title FROM jobs ) LOOP
  172. DBMS_OUTPUT.new_line;
  173. DBMS_OUTPUT.put_line(jb.job_title);
  174. FOR anga IN (SELECT first_name,last_name,salary,commission_pct FROM employees WHERE job_id = jb.job_id) LOOP
  175. DBMS_OUTPUT.put_line(cont ||' '|| anga.first_name || ' ' || anga.last_name);
  176. cont := cont + 1;
  177. val := val + anga.salary;
  178. END LOOP;
  179. IF cont > 1 THEN
  180. cont := cont - 1;
  181. END IF;
  182. numarAng := numarAng + cont;
  183. ValoareTol := ValoareTol + val;
  184. DBMS_OUTPUT.put_line('Numar de angajati = ' || cont );
  185. DBMS_OUTPUT.put_line('Valoare Lunara = ' || val);
  186. DBMS_OUTPUT.put_line('Valoare medie = ' || val/cont);
  187. DBMS_OUTPUT.new_line;
  188. cont:=1;
  189. val := 0;
  190. END LOOP;
  191. DBMS_OUTPUT.put_line('Numar total de angajati = ' || numarAng );
  192. DBMS_OUTPUT.put_line('Valoare Lunara toti angajati = ' || ValoareTol );
  193. DBMS_OUTPUT.put_line('Valoare Lunara medie = ' || ValoareTol/numarAng );
  194. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement