Advertisement
Benlahbib_Abdessamad

Untitled

May 26th, 2015
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.29 KB | None | 0 0
  1.  
  2. 2.
  3. Sql> Select ENAME,SAL from EMP where sal>1000 ;
  4.  
  5. 3.
  6. Sql> Select e.ename,d.dname from emp e,dept d where d.deptno=e.deptno and d.dname=’SALES’ ;
  7.  
  8. 4.
  9. Sql>select ename,(sal+nvl(comm,0)) « Salaire Totale » from emp ;
  10.  
  11.  
  12. 5.
  13. Sql> Select ename,nvl(to_char(comm),’Sans Commission’) « Commission » from emp ;
  14.  
  15. 6-a.
  16. Sql>select ename,hiredate,next_day(add_months(hiredate,6),’Lundi’) from emp ;
  17.  
  18. 6-b.
  19. Sql> select ‘<’ || ename || ‘> gangne <’ ||sal|| ‘> euros par mois,mais souhaite gangner <’ ||sal*3|| ’>dhs’ from emp ;
  20.  
  21. 7.
  22. Sql> Select ename,hiredate,to_char(hiredate,’day’) from emp order by to_char(hiredate,’d’) ;
  23.  
  24. 9.
  25. Sql> Select e.ename « Employé »,e.empno « No Emp »,m.ename « Chef »,m.empno « No Chef » from emp e,emp m where m.empno=e.mgr ;
  26.  
  27. 10.
  28. Sql> Select e.ename « Employé »,e.empno « No Employé »,m.ename « Chef »,m.empno « No Chef » from emp e,emp m where m.empno (+)=e.mgr ;
  29.  
  30. 11.
  31. Sql> Select e.ename,e.job,d.dname,e.sal,s.grade from emp e,dept d,salgrade s where e.deptno=d.deptno and e.sal between s.losal and s.hisal ;
  32. 12.
  33. Sql>select job,(select sum(sal) from emp group by deptno) « Somme par departement »,sum(sal) from emp group by job ;
  34.  
  35. OR
  36. Sql>select job,sum(DECODE(deptno,10,sal)) « DEPT10 », sum(DECODE(deptno,20,sal)) « DEPT20 », sum(DECODE(deptno,30,sal)) « DEPT30 »,sum(sal) « Somme Totale » from emp group by job ;
  37.  
  38. 13.
  39. Sql> Select deptno from dept minus select deptno from emp ;
  40.  
  41. 14.
  42. Sql> select ename,hiredate from emp where hiredate <= all(select hiredate from emp ) ;
  43.  
  44.  
  45. 15.
  46. Sql> select e.ename,e.sal from emp e where (select count(*) from emp where sal>e.sal) < 3 order by 2 ;
  47.  
  48.  
  49. 16.
  50. Sql> select deptno,dname,loc from dept where deptno=any(select deptno from dept minus select deptno from emp where job=’SALESMAN’) ;
  51.  
  52. 17.
  53. Sql>select empno,ename from emp where sal>(select avg(sal)from emp) and deptno=any(select d.deptno from emp e,dept d where d.deptno=e.deptno and e.ename like ‘%T%’) ;
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. Trigger
  70.  
  71. exercice 1 :
  72. create or replace trigger alert after insert or update or delete on etudiant
  73. begin
  74. dbms_output.put_line('Operation termine');
  75. end;
  76. /
  77.  
  78. exercice 2 :
  79. create or replace trigger verifeage
  80. before insert or update on etudiant
  81. for each row
  82. declare
  83. exc exception;
  84. begin
  85. if :new.ageet<18 or :new.ageet>100
  86. then
  87. raise exc;
  88. end if;
  89. exception
  90. when exc then
  91. Raise_Application_error(-20001, 'l age d un etudiant doit etre compris entre 18 et 100');
  92. end;
  93. /
  94.  
  95.  
  96. exercice 3 :
  97. Sql > select trigger_name frum user_triggers ;
  98.  
  99. exercice 4 :
  100. create or replace trigger update_age before update on etudiant
  101. for each row
  102. declare
  103. exc exception;
  104. begin
  105. if :new.ageet<:old.ageet
  106. then
  107.  
  108. raise exc;
  109. end if;
  110. exception
  111. when exc then
  112. Raise_Application_error(-20001, 'le ouveau age doit etre superieur a l anciene');
  113. end;
  114. /
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123. exercice 5 :
  124. create or replace trigger inc before insert on etudiant
  125. for each row
  126. declare
  127. id number;
  128. begin
  129. select count(*) into id from etudiant;
  130. if id = 0
  131. then
  132. :new.numet := 1 ;
  133. else
  134. select max(numet) into id from etudiant;
  135. :new.numet := id + 1;
  136. end if;
  137. end;
  138. /
  139.  
  140.  
  141. exercice 6 :
  142. CREATE or replace trigger updateCOMPRO
  143. after insert or update or delete on ligne_commande
  144. for each row
  145. declare
  146. MT float;
  147. qt Integer;
  148. stock1 Integer;
  149. NC Integer;
  150. NP Integer;
  151. begin
  152. IF Inserting then
  153. MT:=:new.qte * :new.prix_unité;
  154. qt:=:new.qte;
  155. NC:=:new.no_cmd;
  156. NP:=:new.no_prod;
  157. END IF;
  158.  
  159. IF deleting then
  160. MT:=-:old.qte * :old.prix_unité;
  161. qt:=-:old.qte;
  162. NC:=:old.no_cmd;
  163. NP:=:old.no_prod;
  164. END IF;
  165.  
  166. IF updating then
  167. MT:=:new.qte * :new.prix_unité - :old.qte*:old.prix_unité;
  168. qt:=:new.qte - :old.qte;
  169. NC:=:new.no_cmd;
  170. NP:=:new.no_prod;
  171. END IF;
  172. select stock into stock1 from produit where no-prod=NP;
  173. update commande set montant=MT where no_cmd=NC;
  174. update produit set stock=stock1 where no_prod=NP;
  175. end;
  176. /
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183. Curseurs
  184.  
  185. Question 1 :
  186.  
  187. DECLARE
  188. max_operation integer;
  189. new_solde integer;
  190. Begin
  191. select max(num_operation)+1 into max_operation from budget;
  192. select solde-500 into new_solde from budget where num_operation=(select max(num_operation) from budget);
  193. INSERT INTO BUDGET VALUES(max_operation,'Courses','Ddebit','14/01/2002',500,new_solde);
  194.  
  195. End;
  196. /
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210. Question 2 :
  211.  
  212. Declare
  213. Cursor budget_cursor is (select * from budget where NOM_OPERATION='Courses') ;
  214. ligne budget_cursor % Rowtype;
  215.  
  216. Begin
  217. open budget_cursor;
  218.  
  219. loop
  220. Fetch budget_cursor into ligne;
  221. exit when budget_cursor%NotFound ;
  222. INSERT INTO Courses VALUES (ligne.num_operation,ligne.nom_operation,ligne.categorie,ligne.date_operation,ligne.montant) ;
  223. end loop;
  224. close budget_cursor;
  225.  
  226. END;
  227. /
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238. Question 3 :
  239.  
  240. truncate table BUDGET_EURO;
  241.  
  242. Declare
  243. Cursor budget_ecursor is (select * from budget where DATE_OPERATION >'01/01/2002') ;
  244. ligne budget_ecursor % Rowtype;
  245.  
  246. Begin
  247. open budget_ecursor;
  248.  
  249. loop
  250. Fetch budget_ecursor into ligne;
  251. exit when budget_ecursor%NotFound ;
  252. INSERT INTO BUDGET_EURO VALUES (ligne.num_operation,ligne.nom_operation,ligne.categorie,ligne.date_operation,ligne.montant/11) ;
  253. end loop;
  254. close budget_ecursor;
  255.  
  256. END;
  257. /
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267. Question 4 :
  268.  
  269. 1. Curseur parametré
  270.  
  271. truncate table budget_seuil;
  272.  
  273. Accept x number Prompt " Entrez le seuil : "
  274. Declare
  275. Cursor budget_eSeuil(s number) is (select Num_operation,Date_operation,montant from budget where montant > s) ;
  276. ligne budget_eSeuil % Rowtype;
  277. seuil number;
  278. Begin
  279. seuil:=&x;
  280. open budget_eSeuil(seuil);
  281. loop
  282. Fetch budget_eSeuil into ligne;
  283. exit when budget_eSeuil%NotFound ;
  284. INSERT INTO BUDGET_SEUIL VALUES (ligne.num_operation,ligne.date_operation,ligne.montant) ;
  285. end loop;
  286. close budget_eSeuil;
  287.  
  288. END;
  289. /
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297. Curseur implicite
  298.  
  299. truncate table budget_seuil;
  300. Accept x number Prompt " Entrez le seuil : "
  301. Declare
  302. Begin
  303. for ligne in (select Num_operation,Date_operation,montant from budget where montant > &x)
  304. loop
  305. INSERT INTO BUDGET_SEUIL VALUES (ligne.num_operation,ligne.date_operation,ligne.montant) ;
  306. end loop;
  307. END;
  308. /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement