           ) n
           ON n.parent_table = c.table_name
          AND n.owner = c.owner
-        -- get n:m tables which are the NULL candidates from the n block
-        -- the FK has to be set to CASCADE to decide for cleanup
-        OUTER APPLY (
-          SELECT
-            mn2.table_name AS m_table_name,
-            mna.column_name AS m_fk_column_name
-          FROM
-            all_constraints mn
-          JOIN
-            all_cons_columns mna
-            ON mna.constraint_name = mn.constraint_name
-           AND mna.table_name = mn.table_name
-           AND mna.owner = mn.owner
-          JOIN
-            all_constraints mn2
-            ON mn2.constraint_name = mn.r_constraint_name
-            AND mn2.owner = mn.owner
-          WHERE
-            mn.table_name = c.table_name
-            AND mn.owner = c.owner
-            AND n.parent_table IS NULL
-            AND mn2.table_name <> mn.table_name
-            AND mn.constraint_type = 'R'
-            AND mn.delete_rule = 'CASCADE'
-        ) m
         WHERE
           c2.table_name = upper(tab_name)
           AND c2.owner = upper(schema_name)

CREATE OR REPLACE PACKAGE BODY citydb_delete_gen
AS
  FUNCTION get_short_name(tab_name VARCHAR2) RETURN VARCHAR2;
  FUNCTION query_selfref_fk(tab_name VARCHAR2, schema_name VARCHAR2 := USER) RETURN SYS_REFCURSOR;
  FUNCTION gen_delete_selfref_by_ids_call(tab_name VARCHAR2, self_fk_column_name VARCHAR2) RETURN VARCHAR2;
  PROCEDURE create_selfref_array_delete(tab_name VARCHAR2, schema_name VARCHAR2 := USER, vars OUT VARCHAR2, self_block OUT VARCHAR2);

      ||chr(10)||'    '||lower(m_fk_column_name)
      ||chr(10)||'  BULK COLLECT INTO'
      ||chr(10)||'	  '||get_short_name(lower(m_tab_name))||'_ids;'
      ||chr(10)|| gen_delete_m_ref_by_ids_call(m_tab_name, ref_tables, ref_columns);
  END;

  PROCEDURE create_ref_delete(
