| 12
 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
 35
 36
 37
 38
 39
 40
 41
 
 | PROCEDURE insert_orga (
                        nb_jud_cat IN NUMBER(4,0),
                        nb_orga_type IN NUMBER(4,0)
                      ) 
IS
    nSiret          NUMBER(14,0);
    jud_cat_id      NUMBER(4,0);
    orga_type_id    NUMBER(4,0);
 
    nTest           Number ;
BEGIN
 
    -- génération des No 
    SELECT trunc(dbms_random.value(10000000000000,99999999999999)) INTO siret FROM DUAL;
    SELECT trunc(dbms_random.value(1,nb_jud_cat)) INTO jud_cat_id FROM DUAL;
    SELECT trunc(dbms_random.value(1,nb_orga_type)) INTO orga_type_id FROM DUAL;
 
    -- TEST unicité 
    Select
            orga_id
    Into    nTest
    From    Organization
    Where   siret = nSiret ;
 
    -- on a trouvé UNE ligne, on lève l'erreur comme si on en avait trouvé plusieures 
    Raise Too_Many_Rows ;
 
    Exception
    When Too_Many_Rows -- on traite l'erreur, qu'on aie trouvé une ou plusieurs lignes 
    Then
        -- la procédure se relance elle-même et va donc générer d'autres no aléatoires 
        insert_orga(nb_jud_cat, nb_orga_type); 
 
    When No_Data_Found -- cette erreur sera levée si le test d'unicité ne ramène rien... c'est ce qu'on veut ! 
    Then
        INSERT INTO organization (orga_id, orga_type_id, judicial_category_id, siret, name, name_complement) 
        VALUES (SEQ_ORGANIZATION.NEXTVAL,orga_type_id, jud_cat_id ,nSiret,'nom','complenom');
 
    COMMIT;
 
END insert_orga; | 
Partager