Advertisement
Guest User

Untitled

a guest
May 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. create or replace function medieBarbati
  2. return float
  3. AS
  4. suma float;
  5. counnt int;
  6. CURSOR cur_product
  7. IS
  8. SELECT
  9. *
  10. FROM
  11. pacienti;
  12. BEGIN
  13. suma :=0;
  14. counnt :=0;
  15. FOR pacient IN cur_product
  16. LOOP
  17. if pacient.sex=1
  18. then counnt := counnt + 1;
  19. end if;
  20. END LOOP;
  21.  
  22. FOR pacient IN cur_product
  23. LOOP
  24. if pacient.sex=1 then
  25. suma := suma + (SYSDATE-pacient.data_nastere)/365;
  26. end if;
  27. END LOOP;
  28.  
  29. DBMS_OUTPUT.PUT_LINE(suma);
  30.  
  31. RETURN trunc(suma/counnt,3);
  32. END medieBarbati;
  33. /
  34. create or replace function medieFemei
  35. return float
  36. AS
  37. suma float;
  38. counnt int;
  39. CURSOR cur_product
  40. IS
  41. SELECT
  42. *
  43. FROM
  44. pacienti;
  45. BEGIN
  46. suma :=0;
  47. counnt :=0;
  48. FOR pacient IN cur_product
  49. LOOP
  50. if pacient.sex=2
  51. then counnt := counnt + 1;
  52. end if;
  53. END LOOP;
  54.  
  55. FOR pacient IN cur_product
  56. LOOP
  57. if pacient.sex=2 then
  58. suma := suma + (SYSDATE-pacient.data_nastere)/365;
  59. end if;
  60. END LOOP;
  61.  
  62. DBMS_OUTPUT.PUT_LINE(suma);
  63.  
  64. RETURN trunc(suma/counnt,3);
  65. END medieFemei;
  66. /
  67. select medieBarbati from dual;
  68. select medieFemei from dual;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement