Database laboratory

Updates, Integrity, Transactions, Coherence, PL/SQL

SQL*PLUS help for this lab. Technical Oracle documentation

In the first lab, you have queried the following tables: Buveurs, Achats, Vins, Recoltes, Producteurs. You have also created the following views on the tables : Bons_buveurs, Buveurs_asec, Buveurs_achats, and q83pv.
Verify that the views  exist before beginning this lab!


SQL> set long 1024

SQL> describe USER_VIEWS

SQL> select * from USER_VIEWS

You can recreate them using the informations provided in the  TP1.

1  Updates through views.

In the relational model, tables and views are generally handled in a similar manner: he SELECT clause can be used with views as in the case of true tables. However, in the case of INSERT, UPDATE and DELETE there are some differences. The following exercises are meant to reveal those differences.

 



  2  PL/SQL and Procedures

The language PL/SQL allows us to program complex manipulations over the data in the DB. PL/SQL also allows to specify procedures and functions which will be stored in order to be executed at the BDMS level. We are going to see in the sequel how to define and use PL/SQL programs.
Remark: you can use your favorite text editor in order to write and save your PL/SQL programs. You can execute them from Oracle using the command "START filename"

2.1 PL/SQL Modules. Loops and control structures.
2.2 Cursor usage, explicit FETCH command
2.3 Cursor utilization, implicit FETCH command

DECLARE
cursor V_CUR is select * from vins
where nv in (select nv from recoltes, producteurs
where region='Alsace' and producteurs.np=recoltes.np)
order by nv;
BEGIN
for V_Ligne in V_CUR loop
IF V_Ligne.mill in (1976, 1978, 1983) THEN
INSERT INTO TEMP
VALUES (V_Ligne.nv, V_Ligne.cru || '(' || to_char(V_Ligne.mill) || ')', 'Excellent harvest !');
ELSE
INSERT INTO TEMP
VALUES (V_Ligne.nv, V_Ligne.cru || '(' || to_char(V_Ligne.mill) || ')', 'Nothing special !');
END IF;
end loop;
END;
/


2.4 Stored procedures.
CREATE OR REPLACE PROCEDURE choix_experts AS
--DECLARE
cursor V_CUR is select * from vins
where nv in (select nv from recoltes, producteurs
where region='Alsace' and producteurs.np=recoltes.np)
order by nv;
BEGIN
for V_Ligne in V_CUR loop
IF V_Ligne.mill in (1976, 1978, 1983) THEN
INSERT INTO TEMP
VALUES (V_Ligne.nv, V_Ligne.cru || '(' || to_char(V_Ligne.mill) || ')', 'Excellent harvest !');
ELSE
INSERT INTO TEMP
VALUES (V_Ligne.nv, V_Ligne.cru || '(' || to_char(V_Ligne.mill) || ')', 'Nothing special !');
END IF;
end loop;
END;
/

3: Exercises:

Pour tous commentaires: Equipe Bases de Donnes