Professional Documents
Culture Documents
declare
v_ref ref tip_grupa;
begin
insert into grupa g values('matematica',2,1,null)
returning ref(g) into v_ref;
update studenti s
set grupa=v_ref
where s.persoana.cod_st=1;
1
end;
DECLARE
v_cladireRef REF tip_cladire;
v_bloc cladire.bloc%TYPE;
v_nr cladire.nr_cam%TYPE;
BEGIN
-- Select a reference to the room, not the room itself.
SELECT REF(c)
INTO v_cladireRef
FROM cladire c
WHERE cod = 1;
DECLARE
v_Stud REF tip_student;
BEGIN
UPDATE STUDENT
SET SALA = NULL
WHEN SALA IS DANGLING;
END;
/
2
operatorii VALUE şi DEREF
set serveroutput on
DECLARE
v_Room Room;
CURSOR c_Building7 IS
SELECT VALUE(r)
FROM rooms r
WHERE building = 'Building 7'
FOR UPDATE;
BEGIN
-- Loop through all of the rooms in Building 7, and add
-- 100 to the number of seats in each.
OPEN c_Building7;
LOOP
FETCH c_Building7 INTO v_Room;
EXIT WHEN c_Building7%NOTFOUND;
DECLARE
v_Room1 Room;
v_Room2 Room;
BEGIN
-- Select into v_Room1
SELECT VALUE(r)
INTO v_Room1
FROM rooms r
WHERE ID = 20007;
3
FROM rooms r
WHERE VALUE(r) = v_Room1;
v_Room2.Print;
END;
/
4
Sortare
REM This scripts illustrates the use of ORDER BY on object tables.
-- However, Class does not have either a MAP nor an ORDER method,
-- so we can't sort by a Class.
SELECT VALUE(c)
FROM classes c
ORDER BY 1;
Problema. De adaugat metoda de sortare la tip_cladire de tip MAP. In ordinea
crescatoare a numarului de locuri.
1. De sters toate obiecte (tabela CLADIRI), care au referinta la tip_cladire
2. De adaugat metoda
3. De recreat tabela CLADIRI.
4. De testat metoda sortarii.
1
drop table cladire;
3
create or replace type tip_grupa as object
(specialitatea varchar2(30),
an number(4),
nr number(2),
sala ref tip_cladire);
5
create or replace type tip_stud as object
(cod number,
Nume varchar2(22),
Prenume varchar2(22));
6
Statement processed.
0.04 seconds
4
SELECT C.BLOC,C.NR_LOC
FROM cladire c
ORDER BY 1 DESC;
SELECT C.BLOC,C.NR_LOC
FROM cladire c
ORDER BY 2;