Freitag, 4. August 2023

ORA-01788 connect by clause required

This can be quite misleading. It occurred when a delimited list was split into its element as a table. Actually, it was a bad handling of code. There were several instances in PL/SQL to split a list. One of them only was to get a count. Actually, two bad handlings. The first one, the splitting was repeated and not done once putting the result in a table type variable to retrieve the count from there. The other one was, a fix having gone wrong a bit. To improve/facilitate test, there was put an order clause to stabilise the order of the result.

WITH CONSTS AS 
        (SELECT     ';0509;0543;509;543;545;' AS ZL_LISTE 
                    ,';2;2;2;2;4;'            AS HZL_LISTE 
                    ,';'                      AS v_delim 
               FROM dual 
        )
        ,BASE AS 
        (SELECT     RTRIM (LTRIM (ZL_LISTE,v_delim),v_delim)   AS v_przl_codes 
                    ,RTRIM (LTRIM (HZL_LISTE,v_delim),v_delim) AS 
                                                v_przl_origins 
                    ,'[^' || v_delim || ']+' AS v_regexp_delim 
                    ,v_delim 
               FROM CONSTS 
        )
SELECT     COUNT (*)
   FROM (SELECT     TRIM (REGEXP_SUBSTR (v_przl_codes,v_regexp_delim,1,LEVEL)) 
                    str
               FROM BASE
                    CONNECT BY LEVEL <= REGEXP_COUNT (v_przl_codes,v_delim) + 
                    1) 
                    code_tab
  WHERE 
        str IN (203 
                ,208 
                ,372)
     OR str BETWEEN 2051 AND 2099
ORDER BY level ASC -- this order causes ORA-01788

Mittwoch, 14. Juni 2023

Compile invalid object of the schema

This procedure compiles all procedures, functions, packages, views and triggers in the specified schema.

BEGIN
  DBMS_UTILITY.COMPILE_SCHEMA(schema => 'XYZ', -- Name of the schema, obviously ;-)
                              compile_all => FALSE, -- If TRUE, will compile everything within the schema regardless of whether it is VALID
                              reuse_settings => TRUE); -- Indicates whether the session settings in the objects should be reused, or whether the current session settings should be adopted instead
END;
/