Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. set serveroutput on;
  2.  
  3. DROP TYPE student;
  4. DROP TABLE studenti_tema6;
  5.  
  6. CREATE table studenti_tema6 of student;
  7.  
  8. CREATE OR REPLACE TYPE student AS OBJECT (
  9. nume varchar2(10),
  10. prenume varchar2(10),
  11. grupa varchar2(4),
  12. varsta NUMBER,
  13. member procedure afiseaza_foaie_matricola,
  14. member procedure afiseaza_nume_prenume,
  15. order member function stud_cmp(in_stud student) RETURN NUMBER,
  16. constructor function student(first_name VARCHAR2) RETURN SELF AS RESULT,
  17. constructor function student(first_name VARCHAR2, last_name VARCHAR2, in_data_nastere NUMBER) RETURN SELF AS RESULT
  18. );
  19. /
  20.  
  21.  
  22.  
  23. CREATE TYPE BODY student AS
  24. constructor function student(first_name VARCHAR2) RETURN SELF AS RESULT AS
  25. BEGIN
  26. SELF.nume := first_name;
  27.  
  28. DBMS_OUTPUT.PUT_LINE(SELF.nume);
  29. RETURN;
  30. END;
  31.  
  32.  
  33. constructor function student(first_name VARCHAR2, last_name VARCHAR2, in_data_nastere NUMBER) RETURN SELF AS RESULT AS
  34. BEGIN
  35. SELF.nume := first_name;
  36. SELF.prenume := last_name;
  37. self.varsta := in_data_nastere;
  38.  
  39. DBMS_OUTPUT.PUT_LINE(SELF.nume || SELF.prenume);
  40. RETURN;
  41. END;
  42.  
  43. member procedure afiseaza_foaie_matricola IS
  44. BEGIN
  45. DBMS_OUTPUT.PUT_LINE('afisam foaie matricola pentru ' || self.nume);
  46. END afiseaza_foaie_matricola;
  47.  
  48.  
  49. member procedure afiseaza_nume_prenume IS
  50. BEGIN
  51. DBMS_OUTPUT.PUT_LINE(self.nume || ' ' || self.prenume);
  52. END afiseaza_nume_prenume;
  53.  
  54.  
  55. order member function stud_cmp(in_stud student) RETURN NUMBER IS
  56. BEGIN
  57. if self.varsta > in_stud.varsta THEN RETURN 1;
  58. elsif self.varsta = in_stud.varsta THEN RETURN 0;
  59. elsif self.varsta < in_stud.varsta THEN RETURN -1;
  60. end if;
  61. END stud_cmp;
  62. END;
  63. /
  64.  
  65.  
  66.  
  67. DECLARE
  68. s1 student;
  69. s2 student;
  70. s3 student;
  71. BEGIN
  72. s1 := student('Ion', 'Antonescu', 17);
  73. s2 := student('Anton', 'Dan', 21);
  74. s3 := student('Cristoiu', 'Ionut', 20);
  75.  
  76. s1.afiseaza_foaie_matricola;
  77. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement