Skip to content

ORA-00942 Table or View Does Not Exist - Object Access Resolution

Error Text: ORA-00942: table or view does not exist

This error occurs when Oracle cannot find the specified table, view, or other database object. It can be caused by the object not existing, insufficient privileges to access it, incorrect schema qualification, or case sensitivity issues.

  • Table/view was dropped or never created
  • Misspelled object name
  • Wrong database or schema
  • No SELECT privilege on the object
  • Object exists but user lacks access rights
  • Role-based permissions not active
  • Object exists in different schema
  • Missing schema qualification
  • Current schema different from expected
  • Object created with quoted identifiers
  • Mixed case naming issues
  • Platform-specific case handling
-- Check if object exists in current schema
SELECT object_name, object_type, status, created, last_ddl_time
FROM user_objects
WHERE object_name = UPPER('table_name') -- Replace with your object name
ORDER BY object_type;
-- Check if object exists in any accessible schema
SELECT owner, object_name, object_type, status, created
FROM all_objects
WHERE object_name = UPPER('table_name')
ORDER BY owner, object_type;
-- Search for similar named objects (in case of typos)
SELECT owner, object_name, object_type
FROM all_objects
WHERE object_name LIKE UPPER('%partial_name%')
ORDER BY owner, object_name;
-- Check for case-sensitive objects (created with quotes)
SELECT owner, object_name, object_type
FROM all_objects
WHERE LOWER(object_name) = LOWER('table_name')
OR object_name LIKE '%' || INITCAP('table_name') || '%'
ORDER BY owner, object_name;
-- Check current user and default schema
SELECT USER as current_user,
SYS_CONTEXT('USERENV', 'CURRENT_SCHEMA') as current_schema,
SYS_CONTEXT('USERENV', 'SESSION_USER') as session_user
FROM dual;
-- Check if you're in the right database
SELECT name as database_name, db_unique_name, database_role
FROM v$database;
-- List all schemas you have access to
SELECT DISTINCT owner
FROM all_objects
ORDER BY owner;
-- Show current session information
SELECT sid, serial#, username, schemaname, program, machine, osuser
FROM v$session
WHERE sid = (SELECT sid FROM v$mystat WHERE rownum = 1);
-- Check your current privileges
SELECT privilege
FROM user_sys_privs
WHERE privilege LIKE '%TABLE%'
OR privilege LIKE '%SELECT%'
OR privilege = 'CREATE SESSION'
ORDER BY privilege;
-- Check object-specific privileges
SELECT owner, table_name, privilege, grantee, grantable
FROM all_tab_privs
WHERE table_name = UPPER('table_name')
AND (grantee = USER OR grantee = 'PUBLIC')
ORDER BY owner, privilege;
-- Check role-based privileges
SELECT granted_role, admin_option, default_role
FROM user_role_privs
ORDER BY granted_role;
-- Check what privileges a role has
SELECT role, privilege
FROM role_sys_privs
WHERE role IN (SELECT granted_role FROM user_role_privs)
AND (privilege LIKE '%TABLE%' OR privilege LIKE '%SELECT%')
ORDER BY role, privilege;
-- Check table privileges through roles
SELECT role, owner, table_name, privilege
FROM role_tab_privs
WHERE role IN (SELECT granted_role FROM user_role_privs)
AND table_name = UPPER('table_name')
ORDER BY role, owner;
-- Check for synonyms that might point to the object
SELECT synonym_name, table_owner, table_name, db_link
FROM all_synonyms
WHERE synonym_name = UPPER('table_name')
OR table_name = UPPER('table_name')
ORDER BY synonym_name;
-- Check private synonyms
SELECT synonym_name, table_owner, table_name, db_link
FROM user_synonyms
WHERE synonym_name = UPPER('table_name')
OR table_name = UPPER('table_name');
-- Check public synonyms
SELECT synonym_name, table_owner, table_name, db_link
FROM dba_synonyms
WHERE owner = 'PUBLIC'
AND (synonym_name = UPPER('table_name') OR table_name = UPPER('table_name'));
-- Check all tables you have access to (if looking for a specific table)
SELECT owner, table_name, tablespace_name, num_rows, last_analyzed
FROM all_tables
WHERE table_name LIKE '%' || UPPER('search_term') || '%'
ORDER BY owner, table_name;
-- Instead of unqualified reference
SELECT * FROM employees;
-- Use fully qualified name
SELECT * FROM hr.employees;
-- Or set current schema
ALTER SESSION SET CURRENT_SCHEMA = hr;
SELECT * FROM employees;
-- Check which schema contains the object
SELECT owner, object_name, object_type
FROM all_objects
WHERE object_name = 'EMPLOYEES'
ORDER BY owner;
-- Then use the correct schema
SELECT * FROM correct_schema.employees;
-- If object was created with quoted identifier
CREATE TABLE "MyTable" (id NUMBER); -- Creates case-sensitive name
-- Must reference with exact case and quotes
SELECT * FROM "MyTable"; -- Correct
-- SELECT * FROM MyTable; -- Would fail with ORA-00942
-- Check for case-sensitive objects
SELECT owner, object_name, object_type
FROM all_objects
WHERE object_name != UPPER(object_name)
ORDER BY owner, object_name;

Grant Table Access (if you’re the owner or have privileges)

Section titled “Grant Table Access (if you’re the owner or have privileges)”
-- Grant SELECT privilege to specific user
GRANT SELECT ON schema.table_name TO username;
-- Grant multiple privileges
GRANT SELECT, INSERT, UPDATE, DELETE ON schema.table_name TO username;
-- Grant to a role
GRANT SELECT ON schema.table_name TO role_name;
-- Grant to public (use sparingly)
GRANT SELECT ON schema.table_name TO PUBLIC;
-- Grant with ability to grant to others
GRANT SELECT ON schema.table_name TO username WITH GRANT OPTION;
-- Check grants (as the grantor)
SELECT grantee, privilege, grantable
FROM user_tab_privs_made
WHERE table_name = UPPER('table_name')
ORDER BY grantee, privilege;
-- Create access request script for DBA
SELECT 'GRANT SELECT ON ' || owner || '.' || object_name || ' TO ' || USER || ';' as grant_statement
FROM all_objects
WHERE object_name = UPPER('table_name')
AND object_type IN ('TABLE', 'VIEW')
AND owner != USER
ORDER BY owner;
-- Check what access you currently have
SELECT owner, table_name, privilege, grantable
FROM all_tab_privs
WHERE grantee = USER
AND table_name = UPPER('table_name')
ORDER BY owner, privilege;
-- Create table if it should exist
CREATE TABLE schema.table_name (
id NUMBER PRIMARY KEY,
name VARCHAR2(100),
created_date DATE DEFAULT SYSDATE
);
-- Create view if it should exist
CREATE OR REPLACE VIEW schema.view_name AS
SELECT t1.id, t1.name, t2.description
FROM schema.table1 t1
JOIN schema.table2 t2 ON t1.id = t2.table1_id
WHERE t1.status = 'ACTIVE';
-- Create synonym for easier access
CREATE SYNONYM table_name FOR schema.table_name;
-- Create public synonym (requires DBA privileges)
CREATE PUBLIC SYNONYM table_name FOR schema.table_name;

Restore from Backup (if accidentally dropped)

Section titled “Restore from Backup (if accidentally dropped)”
-- Check recycle bin for dropped objects
SELECT object_name, original_name, type, droptime
FROM user_recyclebin
WHERE original_name = UPPER('table_name')
ORDER BY droptime DESC;
-- Restore from recycle bin
FLASHBACK TABLE table_name TO BEFORE DROP;
-- If recycle bin is empty, restore from backup
-- This typically requires DBA assistance and RMAN recovery
-- Create application role
CREATE ROLE app_read_role;
CREATE ROLE app_write_role;
-- Grant object privileges to roles
GRANT SELECT ON schema.table1 TO app_read_role;
GRANT SELECT ON schema.table2 TO app_read_role;
GRANT SELECT ON schema.view1 TO app_read_role;
GRANT SELECT, INSERT, UPDATE, DELETE ON schema.table1 TO app_write_role;
GRANT SELECT, INSERT, UPDATE, DELETE ON schema.table2 TO app_write_role;
-- Grant roles to users
GRANT app_read_role TO readonly_user;
GRANT app_read_role, app_write_role TO app_user;
-- Make roles default
ALTER USER app_user DEFAULT ROLE app_read_role, app_write_role;
-- Create procedure to grant standard access
CREATE OR REPLACE PROCEDURE grant_app_access(p_username VARCHAR2) AS
BEGIN
EXECUTE IMMEDIATE 'GRANT app_read_role TO ' || p_username;
EXECUTE IMMEDIATE 'ALTER USER ' || p_username || ' DEFAULT ROLE app_read_role';
DBMS_OUTPUT.PUT_LINE('Granted app_read_role to ' || p_username);
END;
/
-- Create private synonyms for current user
CREATE SYNONYM customers FOR sales.customers;
CREATE SYNONYM orders FOR sales.orders;
CREATE SYNONYM products FOR inventory.products;
-- Script to create synonyms for all accessible tables
SELECT 'CREATE SYNONYM ' || table_name || ' FOR ' || owner || '.' || table_name || ';' as create_synonym
FROM all_tables
WHERE owner = 'TARGET_SCHEMA'
AND table_name NOT IN (SELECT synonym_name FROM user_synonyms)
ORDER BY table_name;
-- Create procedure to manage synonyms
CREATE OR REPLACE PROCEDURE create_user_synonyms(p_schema VARCHAR2) AS
v_sql VARCHAR2(1000);
BEGIN
FOR rec IN (
SELECT table_name, owner
FROM all_tables
WHERE owner = UPPER(p_schema)
AND table_name NOT IN (SELECT synonym_name FROM user_synonyms)
) LOOP
v_sql := 'CREATE SYNONYM ' || rec.table_name || ' FOR ' || rec.owner || '.' || rec.table_name;
EXECUTE IMMEDIATE v_sql;
DBMS_OUTPUT.PUT_LINE('Created synonym: ' || rec.table_name);
END LOOP;
END;
/
-- Create table to log access attempts
CREATE TABLE object_access_log (
log_time TIMESTAMP DEFAULT SYSTIMESTAMP,
username VARCHAR2(30),
object_name VARCHAR2(128),
object_owner VARCHAR2(30),
access_type VARCHAR2(20), -- SUCCESS, DENIED, NOT_FOUND
error_code NUMBER,
sql_text VARCHAR2(1000)
);
-- Create trigger to log failed object access (where possible)
-- Note: This would need to be implemented at application level
-- as Oracle doesn't provide automatic ORA-00942 logging
-- Query to analyze access patterns
SELECT
object_owner,
object_name,
username,
access_type,
COUNT(*) as attempts,
MIN(log_time) as first_attempt,
MAX(log_time) as last_attempt
FROM object_access_log
WHERE log_time > SYSTIMESTAMP - INTERVAL '7' DAY
GROUP BY object_owner, object_name, username, access_type
HAVING access_type != 'SUCCESS'
ORDER BY attempts DESC;
-- Create standards document for object naming
-- Example standards:
-- - All object names in UPPERCASE
-- - Use underscores for word separation
-- - Prefix tables with T_, views with V_, etc.
-- - Avoid quoted identifiers unless absolutely necessary
-- Script to check naming convention compliance
SELECT
owner,
object_name,
object_type,
CASE
WHEN object_name != UPPER(object_name) THEN 'Mixed case name'
WHEN object_name LIKE '% %' THEN 'Contains spaces'
WHEN LENGTH(object_name) > 30 THEN 'Name too long'
WHEN REGEXP_LIKE(object_name, '[^A-Z0-9_]') THEN 'Invalid characters'
ELSE 'OK'
END as naming_issue
FROM all_objects
WHERE owner IN ('APP_SCHEMA1', 'APP_SCHEMA2') -- Your application schemas
AND object_type IN ('TABLE', 'VIEW', 'INDEX', 'SEQUENCE')
ORDER BY owner, object_type, object_name;
// Java example with proper ORA-00942 handling
public class DatabaseAccessHelper {
public ResultSet executeQuery(String sql, Object... params) throws SQLException {
try {
PreparedStatement pstmt = connection.prepareStatement(sql);
// Set parameters
for (int i = 0; i < params.length; i++) {
pstmt.setObject(i + 1, params[i]);
}
return pstmt.executeQuery();
} catch (SQLException e) {
if (e.getErrorCode() == 942) { // ORA-00942
handleTableNotExistError(sql, e);
}
throw e;
}
}
private void handleTableNotExistError(String sql, SQLException e) {
// Extract table name from SQL (simplified)
String tableName = extractTableName(sql);
// Log the issue
logger.error("Table/view does not exist: " + tableName + " in SQL: " + sql);
// Check if it's a known missing object
if (isKnownMissingObject(tableName)) {
throw new ConfigurationException("Required database object " + tableName +
" is not available. Please contact your database administrator.");
} else {
// Check if user has access
if (!hasAccessToObject(tableName)) {
throw new SecurityException("Access denied to " + tableName +
". Please contact your database administrator to request access.");
} else {
// Unknown issue
throw new DatabaseException("Database object " + tableName +
" not found. This may indicate a configuration or deployment issue.");
}
}
}
private boolean hasAccessToObject(String objectName) {
String checkSql = "SELECT COUNT(*) FROM all_objects WHERE object_name = UPPER(?)";
try (PreparedStatement pstmt = connection.prepareStatement(checkSql)) {
pstmt.setString(1, objectName);
try (ResultSet rs = pstmt.executeQuery()) {
rs.next();
return rs.getInt(1) > 0;
}
} catch (SQLException e) {
return false;
}
}
}
-- Always test object existence before using
CREATE OR REPLACE FUNCTION object_exists(
p_owner VARCHAR2,
p_object_name VARCHAR2,
p_object_type VARCHAR2 DEFAULT 'TABLE'
) RETURN BOOLEAN AS
v_count NUMBER;
BEGIN
SELECT COUNT(*)
INTO v_count
FROM all_objects
WHERE owner = UPPER(p_owner)
AND object_name = UPPER(p_object_name)
AND object_type = UPPER(p_object_type);
RETURN v_count > 0;
END;
/
-- Use dynamic SQL with existence checks
CREATE OR REPLACE PROCEDURE safe_query_table(
p_table_name VARCHAR2,
p_where_clause VARCHAR2 DEFAULT '1=1'
) AS
v_sql VARCHAR2(4000);
v_cursor SYS_REFCURSOR;
BEGIN
-- Check if table exists first
IF NOT object_exists(USER, p_table_name, 'TABLE') THEN
RAISE_APPLICATION_ERROR(-20001, 'Table ' || p_table_name || ' does not exist');
END IF;
-- Build and execute query
v_sql := 'SELECT * FROM ' || p_table_name || ' WHERE ' || p_where_clause;
OPEN v_cursor FOR v_sql;
-- Process results...
CLOSE v_cursor;
END;
/
#!/bin/bash
# Script to verify database objects exist before deployment
# Database connection parameters
DB_USER="app_user"
DB_PASS="password"
DB_HOST="localhost"
DB_SID="orcl"
# List of required objects
REQUIRED_TABLES=(
"HR.EMPLOYEES"
"SALES.CUSTOMERS"
"SALES.ORDERS"
"INVENTORY.PRODUCTS"
)
REQUIRED_VIEWS=(
"HR.V_EMPLOYEE_SUMMARY"
"SALES.V_CUSTOMER_ORDERS"
)
echo "Verifying database objects..."
for table in "${REQUIRED_TABLES[@]}"; do
schema=$(echo $table | cut -d'.' -f1)
table_name=$(echo $table | cut -d'.' -f2)
result=$(sqlplus -s $DB_USER/$DB_PASS@$DB_HOST/$DB_SID <<EOF
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
SELECT COUNT(*) FROM all_tables WHERE owner='$schema' AND table_name='$table_name';
EXIT;
EOF
)
if [ "$result" -eq 0 ]; then
echo "ERROR: Table $table does not exist!"
exit 1
else
echo "OK: Table $table exists"
fi
done
echo "All required database objects verified successfully!"
  • ORA-00980 - Synonym translation is no longer valid
  • ORA-01031 - Insufficient privileges
  • ORA-01747 - Invalid user.table.column specification
  • ORA-01752 - Cannot delete from view without exactly one key-preserved table
  1. ✓ Verify object exists and check spelling
  2. ✓ Check current schema and user context
  3. ✓ Verify you have necessary privileges
  4. ✓ Look for synonyms or case-sensitive names
  5. ✓ Use fully qualified object names
  6. ✓ Request access from DBA if needed
-- Check if object exists
SELECT owner, object_name, object_type FROM all_objects
WHERE object_name = UPPER('table_name');
-- Check current user/schema
SELECT USER, SYS_CONTEXT('USERENV', 'CURRENT_SCHEMA') FROM dual;
-- Find similar objects
SELECT owner, object_name FROM all_objects
WHERE object_name LIKE '%partial_name%';
-- Check privileges
SELECT privilege FROM all_tab_privs
WHERE table_name = UPPER('table_name') AND grantee = USER;
-- Use qualified name
SELECT * FROM schema.table_name;
-- Set current schema
ALTER SESSION SET CURRENT_SCHEMA = schema_name;
  • Always use qualified names - schema.object_name
  • Verify object existence - Before using in production code
  • Use consistent naming - Follow naming conventions
  • Create synonyms - For frequently accessed objects
  • Test thoroughly - In environment matching production
  • Document dependencies - Keep track of required objects