1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
CREATE OR REPLACE PACKAGE common AS
CURSOR c_oper IS
SELECT oper.nom, cont.tel_num
FROM operateurs oper, contacts cont;
TYPE REF_CURSOR IS REF CURSOR;
PROCEDURE get_operateurs(p_matr operateurs.matricule%TYPE DEFAULT NULL,
p_tel_type contacts.tel_type%TYPE DEFAULT NULL,
ret_cur OUT ref_cursor);
END;
/
CREATE OR REPLACE PACKAGE BODY common AS
PROCEDURE get_operateurs(p_matr operateurs.matricule%TYPE DEFAULT NULL,
p_tel_type contacts.tel_type%TYPE DEFAULT NULL,
ret_cur OUT ref_cursor) IS
v_req VARCHAR2(1024);
BEGIN
v_req := 'select oper.nom, cont.tel_num from operateurs oper, contacts cont';
v_req := v_req || ' where oper.matricule=cont.matricule';
IF (p_matr IS NOT NULL) THEN
v_req := v_req || ' and oper.matricule=:b_matr';
ELSE
v_req := v_req || ' and (1=1 or :b_matr is null)';
END IF;
IF (p_tel_type IS NOT NULL) THEN
v_req := v_req || ' and cont.tel_type=:b_tel_type';
ELSE
v_req := v_req || ' and (1=1 or :b_tel_type is null)';
END IF;
OPEN ret_cur FOR v_req
USING p_matr, p_tel_type;
END;
END;
/ |
Partager