Sie sind auf Seite 1von 3

CREATE OR REPLACE PROCEDURE DEptEmp IS

CURSOR c_deptEmp IS SELECT dname,deptno from dept_tp4;


c_deptName dept_tp4.dname%type;
c_deptno dept_tp4.deptno%type;
c_count number(2);

BEGIN
OPEN c_deptEmp;
LOOP
FETCH c_deptEmp into c_deptName,c_deptno;
EXIT WHEN c_moyenne%notfound;
dbms_output.put_line(' le nom de departement ' || c_deptName || ' le nombre des
employées : ' || c_deptno );
END LOOP;
CLOSE c_deptEmp;
end;
end;
/

// question 1 :

DECLARE

PROCEDURE c_deptEmp IS
CURSOR c_deptEmp IS SELECT dname,deptno from dept_tp4;
c_deptName dept_tp4.dname%type;
c_deptno dept_tp4.deptno%type;
c_count number(2);
BEGIN
OPEN c_deptEmp;
LOOP
FETCH c_deptEmp into c_deptName,c_deptno;
EXIT WHEN c_deptEmp%notfound;
SELECT count(deptno) into c_count from emp_tp4
where deptno = c_deptno;
dbms_output.put_line(' le nom de departement ' || c_deptName || ' le nombre des
employées : ' || c_count );
END LOOP;
CLOSE c_deptEmp;
END;
BEGIN

c_deptEmp();

END;
/

SELECT count(deptno) into c_count from emep_tp4


where deptno = c_deptno;

question 3 :
DECLARE

PROCEDURE c_deptEmp IS
CURSOR c_deptEmp IS SELECT dname,deptno from dept_tp4;
c_deptName dept_tp4.dname%type;
c_deptno dept_tp4.deptno%type;
c_count number(2);
BEGIN
OPEN c_deptEmp;
LOOP
FETCH c_deptEmp into c_deptName,c_deptno;
EXIT WHEN c_deptEmp%notfound;
SELECT count(deptno) into c_count from emp_tp4
where deptno = c_deptno;
dbms_output.put_line(' le nom de departement ' || c_deptName || ' le nombre des
employées : ' || c_count );
END LOOP;
CLOSE c_deptEmp;
END;
BEGIN

c_deptEmp();

END;
/

create or replace PROCEDURE add_departement(id in int ,nom in varchar2(14), lieu in


varchar2(13) ) is
id_existe exception;
begin
insert into dept_tp4 (deptno,dname,loc) values(id,nom,lieu);
exception
when id_existe then
dbms_output.put_line(ORA-20010,'ID existe');
end;
/
CREATE TABLE test (unique (deptno)) SELECT deptno FROM deptno;
CREATE TABLE dept_tp4 (deptno PRIMARY KEY, dname, loc) AS SELECT deptno, dname, loc
FROM dept;

CREATE TABLE dept4 as SELECT deptno FROM dept;


CREATE TABLE test (deptno NUMBER(2) NOT NULL,dname,loc,
PRIMARY KEY (deptno)) as
SELECT deptno,dname,loc FROM dept;

create or replace PROCEDURE add_departement (id in number,nom in varchar, lieu in


varchar ) is
id_existe exception;
begin
insert into dept_tp4 (deptno,dname,loc) values(id,nom,lieu);
exception
when id_existe then
dbms_output.put_line('ID existe');
end;
/

create or replace procedure add_departement (id in number ,


nom in varchar,
lieu in varchar) is
id_existe exception;
Dno dept_tp4.deptno%type := 0;
pragma exception_init(id_existe, -20010);
begin
select deptno into Dno from dept_tp4 where deptno = id;
if id = Dno then
raise_application_error(-20010,'id existe');
else
insert into dept_tp4 (deptno,dname,loc) values(id,nom,lieu);
end if;
exception
when id_existe then
dbms_output.put_line('ID existe');
end;
/

Das könnte Ihnen auch gefallen