0% found this document useful (0 votes)
15 views4 pages

Lab 4

The document outlines SQL commands for managing database privileges and operations related to an educational application. It includes the creation of tables, granting of permissions, and procedures for grading student submissions. Additionally, it demonstrates the insertion of user data and the handling of role assignments based on student status.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

Lab 4

The document outlines SQL commands for managing database privileges and operations related to an educational application. It includes the creation of tables, granting of permissions, and procedures for grading student submissions. Additionally, it demonstrates the insertion of user data and the handling of role assignments based on student status.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

select *

FROM DBA_TAB_PRIVS WHERE grantee like '%ELEARN%';

--1
create table tema_casa (
id number(4) primary key,
enunt varchar2(200) not null,
id_curs number(4),
deadline date,
punctaj number(4, 2),
foreign key(id_curs) references curs(id));

--Var 1
-- din conexiunea lui sys sau a lui elearn_app_admin2:
grant select on elearn_app_admin2.tema_casa to elearn_profesor11;
grant select on elearn_app_admin2.tema_casa to elearn_profesor12;
grant select on elearn_app_admin2.tema_casa to elearn_asistent13;

--var 2
--sys:
grant create view to elearn_app_admin2;

--app admin:
create or replace view viz_tema as select * from tema_casa;
grant select on viz_tema to elearn_profesor11;
grant select on viz_tema to elearn_profesor12;
grant select on viz_tema to elearn_asistent13;

--profesor1:
select * from elearn_app_admin2.viz_tema;

------

elearn_asistent3

select * from elearn_app_admin.tema_casa;

update elearn_app_admin.tema_casa
set deadline = deadline + 21
where id=1;

commit;

----------------------------------

elearn_student2

select * from user_col_privs ;

insert into elearn_app_admin.rezolva (id_tema, id_stud, data_upload) values (1, 1,


sysdate);

--3
create table rezolva (
id_tema number(4),
id_stud number(4),
data_upload date,
nota number(4,2),
id_corector number(4),
primary key(id_tema, id_stud));

create or replace procedure proc_notare (codstud number, codtema number,


codcorector number, notadata number)
is
verif_ok number(1) := -1;
contor1 number(1) := -1;
contor2 number(1) := -1;
begin
select count(*) into contor1
from tema_casa tc, rezolva r
where tc.id = r.id_tema
and r.id_stud=codstud
and tc.id=codtema;

select count(r.nota) into contor2


from rezolva r
where r.id_stud=codstud
and r.id_tema=codtema;

if contor1 = 0 then
dbms_output.put_line('Eroare: nu sunt respectate conditiile de notare,
studentul nu a depus tema');
else
if contor2 >= 1 then
dbms_output.put_line('Eroare: nu sunt respectate conditiile de notare, tema a
fost deja notata');
else
update rezolva
set nota=notadata, id_corector = codcorector
where id_stud=codstud and id_tema = codtema;
commit;
end if;
end if;

exception
when others then dbms_output.put_line('Eroare: ' || SQLERRM);
end;
/

grant execute on elearn_app_admin2.proc_notare to elearn_profesor11;


grant execute on elearn_app_admin2.proc_notare to elearn_profesor12;
grant execute on elearn_app_admin2.proc_notare to elearn_asistent13;

-------------------------------

elearn_profesor11

select * from user_tab_privs;

select * from elearn_app_admin.tema_casa;

select * from session_privs;


select * from session_roles;

update elearn_app_admin.tema_casa
set deadline = deadline + 7
where id=2;
commit;

commit;

select * from elearn_app_admin2.tema_casa;

execute elearn_app_admin2.proc_notare(1,1,1,10);

--------------------------------

--4
drop table utilizator cascade constraints;
drop table cursant;

create table utilizator (


id number(4) primary key,
tip varchar2(15) default 'STUDENT',
nume varchar2(20) not null,
prenume varchar2(20) not null,
numeuser varchar2(20) not null,
an_intrare date not null,
an_iesire date);

create table cursant (


id number(4) primary key,
an_studiu number(1) not null,
reluare_studii number(1),
intrerupere_studii number(1),
foreign key(id) references utilizator(id));

insert into utilizator values(1, 'STUDENT', 'Nume1', 'Prenume1',


'ELEARN_student12', sysdate - 300, null);
insert into utilizator values(2, 'STUDENT', 'Nume2', 'Prenume2',
'ELEARN_student13', sysdate - 1200, null);

insert into cursant values(1, 1, 0, 0);


insert into cursant values(2, 3, 0, 0);

----sys:
grant create role, grant any role to elearn_app_admin2;
grant create procedure to elearn_app_admin2;

create or replace procedure atrib_rol_stud is


cursor c is select u.numeuser, cr.an_studiu
from utilizator u join cursant cr using(id)
where u.tip='STUDENT';
begin
for v_rec in c loop
execute immediate 'GRANT INSERT(id_tema, id_stud, data_upload) ON rezolva to
'
|| v_rec.numeuser;
if v_rec.an_studiu = 3 or v_rec.an_studiu = 5 then
execute immediate 'REVOKE INSERT ON rezolva FROM ' || v_rec.numeuser;
end if;
end loop;

exception
when others then
dbms_output.put_line('Eroare: ' || SQLERRM);
end;
/

-----sys:

select * from dba_col_privs


where grantee like '%ELEARN_ST%';

You might also like