mercredi 6 mars 2013

Procedure stockee ORACLE




Pour rendre le debug possible:

set serveroutput on;

Voici une procedure stockée:


CREATE OR REPLACE PROCEDURE PROC_FILL_PARENT AS
v_id_parent integer;
v_id_grand_parent integer;
v_id integer;
CURSOR CUR_FILL_PARENT IS
SELECT id_action_formation,id_action_parent FROM action_formation;
BEGIN
   OPEN CUR_FILL_PARENT;
   LOOP
      FETCH CUR_FILL_PARENT INTO v_id, v_id_parent;
  --    dbms_output.put_line(v_id_parent);
  if(v_id_parent is not null) then
    dbms_output.put_line('update action_formation set id_action_grand_parent=(SELECT id_action_parent FROM action_formation where id_action_formation='||v_id_parent||') where id_action_formation='||v_id);
    update action_formation set id_action_grand_parent=(SELECT id_action_parent FROM action_formation where id_action_formation=v_id_parent) where id_action_formation=v_id;
  end if;
    commit;
      EXIT WHEN CUR_FILL_PARENT%NOTFOUND;
   END LOOP;
   CLOSE CUR_FILL_PARENT;
END;

Aucun commentaire: