Skip to content

Table Owner Lookup (towner.sql)

This script provides Oracle database functionality via the towner.sql script.

rem towner.sql
rem
ttitle 'Table Owners'
rem
col name format a41 heading 'OWNER'
rem
select DISTINCT OWNER
from DBA_TABLES
where TABLE_NAME like UPPER('&name')
order by OWNER;

This simple but essential utility script helps locate which schemas contain tables with a specific name or name pattern. It’s particularly useful in environments with multiple schemas where table names might be duplicated across different owners, or when you need to find all instances of tables matching a pattern.

  • Cross-Schema Search: Searches all schemas in the database
  • Pattern Matching: Supports SQL wildcards for flexible table name searches
  • Distinct Results: Shows unique schema owners only
  • Case Insensitive: Automatically converts search pattern to uppercase
  • Quick Reference: Fast way to locate table ownership

Run the script and provide a table name pattern when prompted:

@towner.sql

Input Parameters:

  • Table Name: Table name or pattern (supports % and _ wildcards)
SELECT on DBA_TABLES
Table Owners
OWNER
-----------------------------------------
FINANCE
HR
PAYROLL
REPORTING
SCOTT
Enter value for name: EMPLOYEES

Shows all schemas containing a table named “EMPLOYEES”

Enter value for name: EMP%

Shows schemas with tables starting with “EMP”

Enter value for name: %_HIST

Shows schemas with tables ending in “_HIST”

Enter value for name: %CUSTOMER%

Shows schemas with tables containing “CUSTOMER”

  1. Table Location

    • Find which schema contains a specific table
    • Locate tables across multiple environments
  2. Schema Analysis

    • Identify duplicate table names across schemas
    • Understand table distribution patterns
  3. Migration Planning

    • Inventory table ownership before migrations
    • Identify schema dependencies
  4. Security Auditing

    • Find all schemas with sensitive table names
    • Audit table access across schemas
  5. Development Support

    • Help developers find the correct schema for tables
    • Resolve ambiguous table references
@towner.sql
Enter value for name: %CUSTOMER%
Result shows all schemas with customer tables:
HR
SALES
FINANCE
MARKETING
@towner.sql
Enter value for name: %AUDIT%
Result shows schemas with audit tables:
SECURITY
COMPLIANCE
APP_SCHEMA
@towner.sql
Enter value for name: TEMP_%
Result shows schemas with temporary tables:
ETL_SCHEMA
DATA_WAREHOUSE
STAGING

After finding owners, you can drill down further:

-- After running towner.sql, check table details
SELECT owner, table_name, num_rows, last_analyzed
FROM dba_tables
WHERE table_name LIKE 'EMPLOYEES%'
AND owner IN ('HR', 'PAYROLL');
-- Find all tables in schemas identified by towner.sql
SELECT table_name, num_rows
FROM dba_tables
WHERE owner = 'HR'
ORDER BY table_name;

No Results Returned

  • Check if table name is spelled correctly
  • Verify the table exists in the database
  • Ensure you have privileges to see DBA_TABLES

Too Many Results

  • Use more specific patterns to narrow the search
  • Consider exact table names instead of wildcards

Missing Expected Schemas

  • Some schemas might not be visible due to privilege restrictions
  • Check if tables are actually tables (not views or synonyms)
  • DBA_TABLES is a data dictionary view that’s generally fast
  • Using wildcards may slow down the query on very large databases
  • Results are cached by Oracle’s dictionary cache
SELECT owner, COUNT(*) table_count
FROM dba_tables
WHERE table_name LIKE UPPER('&name')
GROUP BY owner
ORDER BY owner;
SELECT DISTINCT owner
FROM dba_tables
WHERE table_name LIKE UPPER('&name')
AND num_rows > 0 -- Only tables with data
ORDER BY owner;
SELECT DISTINCT table_owner
FROM dba_synonyms
WHERE synonym_name LIKE UPPER('&name')
UNION
SELECT DISTINCT owner
FROM dba_tables
WHERE table_name LIKE UPPER('&name')
ORDER BY 1;