Académique Documents
Professionnel Documents
Culture Documents
COMPLEMENTS
===================================
RAISE_APPLICATION_ERROR (alpha,
‘message’)
Alpha dans l’intervalle -20999 et -20000
EXCEPTIONS
Une anomalie utilisateur peut être traitée comme une exception, pour cela il faut:
DECLARE
Nom_exception Exception;
Le déclencheur
IF………..Then
Raise nom_exception;
La traiter dans la partie exception:
EXECPTION
- Des erreurs standards détectées par PL/SQL. Dans ce cas, le programme s'arrête et il y a
génération d'une erreur avec un code ORAxxxxx. La solution consiste à définir une procédure.
Exemple d'une fonction stockée dans une instruction SELECT (a testé sur machine):
Begin
Return Deg_c;
End Conversion
==================================================================
==========
EXEMPLES
---Creation de la table Etudiant---
begin
end insertEtu;
exec insertEtu('Ali','majid',22);
exec insertEtu('Brahim','Mouhcine',23);
exec insertEtu('alami','Omar',22);
exec insertEtu('Hajji','Hicham',23);
exec insertEtu('karim','rachid',21);
/*
alter table emp add constraint nserv foreign key(nserv) references service(numservice);
alter table service add constraint nbemp foreign key (nbemp)references salgrade(grade);
*/
/*
create or replace package table_exe1 as
procedure insert_emp(nom varchar2,nemp number,fonction varchar2,nsup
number,date_emb date,salaire number,comm number,nserv number );
end table_exe1;
begin
end insert_emp;
begin
insert into service values(numservice,nom,lieu,nbemp);
end insert_service;
begin
end insert_salgrade;
begin
end supp_emp;
begin
end supp_service;
begin
end supp_salgrade;
end table_exe1;
/
*/
/*
exec table_exe1.insert_emp('',,'',,,,,);
exec table_exe1.insert_service(,'','',);
exec table_exe1.insert_salgrade(,,);
exec table_exe1.supp_emp();
exec table_exe1.supp_service();
exec table_exe1.supp_salgrade();
--http://localhost:5560/isqlplus/
*/
/*
raise_application_error(num,"jklhlkjnkl")
DECLARE
CURSOR InserCur IS
t_salg salgrade%ROWTYPE;
begin
open InserCur;
loop
end loop;
close InserCur;
end;
declare
cursor InserSal is
t_salg salgrade%rowtype;
begin
open InserSal;
loop
end loop;
close InserSal;
end;
/
--Exeption--
declare
cursor ExeptionSal is
somme number(10);
t_salg salgrade%rowtype;
begin
open ExeptionSal;
loop
somme:=t_salg.losal+t_salg.hisal;
if somme>=400
then
raise_application_error(-20055,'erreur');
else
end if;
end loop;
close ExeptionSal;
end;
/
*/
/*
grant create table create any table to mouh with admin option;
grant drop any table lock any table to mouh with admin option;
*/
/*
connect user1/user1@orcl2
connect scott/pwd@orcl2
connect mouh/mouh@orcl2
connect scott/pwd@orcl2
connect mouh/mouh@orcl2
connect system/manager@orcl2
desc sys.dba_col_privs
desc sys.dba_tab_privs
*/
/*
connect system/manager@orcl2
grant create role to user1;
connect user1/user1@orcl2
--Création--
desc dba_roles;
--Suppression--
*/
----Exe 1----
begin
dbms_output.enable(1000000);
dbms_output.put_line('Opération Términer');
end ;
exec insertEtu('ttt','ttt',17);
--Désactiver / activer
======================================