0%(1)0% fanden dieses Dokument nützlich (1 Abstimmung)
88 Ansichten3 Seiten
The document contains SQL statements that create tables, functions, procedures and triggers to manage a theater booking system. The tables created are spectacol (performance), sala (hall), bilet (ticket), actor and joaca (performance-actor relationship). Functions and procedures are created to return the number of actors over 35 years old for a given role, display performance details and ticket sums for a given season, and triggers are created to check ticket availability before insertion and increment a counter.
The document contains SQL statements that create tables, functions, procedures and triggers to manage a theater booking system. The tables created are spectacol (performance), sala (hall), bilet (ticket), actor and joaca (performance-actor relationship). Functions and procedures are created to return the number of actors over 35 years old for a given role, display performance details and ticket sums for a given season, and triggers are created to check ticket availability before insertion and increment a counter.
The document contains SQL statements that create tables, functions, procedures and triggers to manage a theater booking system. The tables created are spectacol (performance), sala (hall), bilet (ticket), actor and joaca (performance-actor relationship). Functions and procedures are created to return the number of actors over 35 years old for a given role, display performance details and ticket sums for a given season, and triggers are created to check ticket availability before insertion and increment a counter.
denumire varchar2(50), stagiune number, cod_sala number, constraint fk_spectacol_sala foreign key (cod_sala) references sala(id_sala)); create table sala (id_sala number primary key, denumire varchar2(50), numar_locuri number); create table bilet (id_bilet number primary key, pret number, cod_spectacol number, data_spectacol date, rand number, loc number, constraint fk_bilet_spectacol foreign key (cod_spectacol) references spectacol(id_spectacol)); create table actor (id_actor number primary key, nume varchar2(50), prenume varchar2(50), data_nasterii date); create table joaca (cod_actor number, cod_spectacol number, rol varchar2(50), constraint fk_joaca_actor foreign key (cod_actor) references actor(id_actor), constraint fk_joaca_spectacol foreign key (cod_spectacol) references spectacol(id_spectacol), constraint pk_joaca primary key (cod_actor,cod_spectacol)); --1 create or replace function functie_ex1(p_rol varchar2) return number is v_rez number := 0; begin select count(*) into v_rez from joaca join actor on cod_actor = id_actor where rol = p_rol and (sysdate - data_nasterii)/365 > 35; dbms_output.put_line ('adas'); return v_rez; exception when No_Data_Found then RAISE_APPLICATION_ERROR(-20202, 'Nu exista actori '); end; --2 create or replace procedure proced_ex2 (p_stagiune spectacol.stagiune%type) is
type tab_imbri is table of number;
type dates is record (denumire varchar2(50), actori tab_imbri , suma number); type tab_index is table of dates index by pls_integer; lista tab_index; indx number; indx1 number; begin for i in (select * from spectacol where stagiune = p_stagiune) loop lista(i.id_spectacol).denumire := i.denumire; end loop; indx := lista.first; while (indx <= lista.last) loop select cod_actor bulk collect into lista(indx).actori from joaca where cod_spectacol = indx; indx := lista.next(indx); end loop; indx := lista.first; while (indx <= lista.last) loop select sum(pret) into lista(indx).suma from bilet where cod_spectacol = indx; indx := lista.next(indx); end loop; indx := lista.first; while (indx <= lista.last) loop dbms_output.put_line ('Denumire : ' || lista(indx).denumire); dbms_output.put_line ('Pret : ' || lista(indx).suma); dbms_output.put_line ('Actori : '); indx1 := lista(indx).actori.first; while (indx1 <= lista(indx).actori.last) loop dbms_output.put_line(lista(indx).actori(indx1)); indx1 := lista(indx).actori.next(indx1); end loop; indx := lista.next(indx); end loop; end; --3 create or replace package pachet is type tab_index is table of number index by pls_integer; lista tab_index; end; create or replace trigger trigg1_ex3 before insert on bilet begin for i in (select * from spectacol) loop pachet.lista(i.id_spectacol) := 0; end loop;
for i in (select * from bilet) loop
pachet.lista(i.cod_spectacol) := pachet.lista(i.cod_spectacol) + 1; end loop; end; create or replace trigger trigg2_ex3 before insert on bilet for each row declare v_locuri number; begin select numar_locuri into v_locuri from sala join spectacol on sala.id_sala = spectacol.cod_sala where id_spectacol = :new.cod_spectacol; if (pachet.lista(:new.cod_spectacol) >= v_locuri) then raise_application_error(-20202,'Nu mai exista locuri'); else pachet.lista(:new.cod_spectacol) := pachet.lista(:new.cod_spectacol) + 1; end if; end;