diff --git a/packages/app.spec.sql b/packages/app.spec.sql index cb6dcf6..2a65b45 100644 --- a/packages/app.spec.sql +++ b/packages/app.spec.sql @@ -233,6 +233,16 @@ CREATE OR REPLACE PACKAGE app AS + -- + -- Return current owner (because APEX dont like using USER) + -- + FUNCTION get_owner ( + in_app_id apps.app_id%TYPE := NULL + ) + RETURN apex_applications.owner%TYPE; + + + diff --git a/packages/app.sql b/packages/app.sql index ae766f5..d4e3ae3 100644 --- a/packages/app.sql +++ b/packages/app.sql @@ -274,6 +274,25 @@ CREATE OR REPLACE PACKAGE BODY app AS + FUNCTION get_owner ( + in_app_id apps.app_id%TYPE := NULL + ) + RETURN apex_applications.owner%TYPE + AS + out_owner apex_applications.owner%TYPE; + BEGIN + SELECT a.owner INTO out_owner + FROM apex_applications a + WHERE a.application_id = COALESCE(in_app_id, app.get_app_id()); + -- + RETURN out_owner; + EXCEPTION + WHEN NO_DATA_FOUND THEN + RETURN app.schema_owner; + END; + + + PROCEDURE create_session AS PRAGMA AUTONOMOUS_TRANSACTION; diff --git a/views/obj_tables_ref_objects.sql b/views/obj_tables_ref_objects.sql index 7ed3faa..a200927 100644 --- a/views/obj_tables_ref_objects.sql +++ b/views/obj_tables_ref_objects.sql @@ -19,7 +19,7 @@ FROM ( LEVEL AS level_ FROM user_dependencies d CROSS JOIN x - WHERE d.referenced_owner = 'CORE' -- @TODO: hardcoded user + WHERE d.referenced_owner = app.get_owner() CONNECT BY NOCYCLE PRIOR d.name = d.referenced_name AND LEVEL <= 3 -- limit depth START WITH d.referenced_name = x.table_name diff --git a/views/obj_tables_ref_pages.sql b/views/obj_tables_ref_pages.sql index 6f83498..d52ee31 100644 --- a/views/obj_tables_ref_pages.sql +++ b/views/obj_tables_ref_pages.sql @@ -31,7 +31,7 @@ WHERE r.query_type_code = 'TABLE' SELECT DISTINCT d.name AS view_name FROM user_dependencies d CROSS JOIN x - WHERE d.referenced_owner = 'CORE' -- @TODO: hardcoded schema + WHERE d.referenced_owner = app.get_owner() AND d.type = 'VIEW' CONNECT BY NOCYCLE d.referenced_name = PRIOR d.name AND d.referenced_type = 'VIEW'