Skip to content

ORA-00911 - Invalid Character

The ORA-00911 error occurs when Oracle encounters an invalid or unexpected character in a SQL statement. This error is commonly caused by copy-paste operations, encoding issues, or using incorrect syntax.

  • Error Code: ORA-00911
  • Error Message: “invalid character”
  • Error Type: SQL Syntax Error
  • Severity: Compilation Error

Hidden or invisible characters copied from documents or web pages.

Character encoding problems when transferring SQL between systems.

Using characters that have special meaning in SQL in incorrect contexts.

Non-printable characters introduced during copy-paste operations.

Problems with Unicode characters in SQL statements.

Example 1: Hidden Characters from Copy-Paste

Section titled “Example 1: Hidden Characters from Copy-Paste”

Problem:

SELECT * FROM employees WHERE department_id = 10; -- Contains hidden character
-- ORA-00911: invalid character

Solution:

-- Retype the statement instead of copy-paste
SELECT * FROM employees WHERE department_id = 10;
-- Or use a text editor to show invisible characters
-- Remove any non-ASCII characters

Problem:

SELECT 'John's Department' FROM dual;
-- ORA-00911: invalid character (smart quote character)

Solution:

-- Use standard single quotes
SELECT 'John''s Department' FROM dual;
-- Or use double quotes for identifiers
SELECT "John's Department" AS description FROM dual;

Problem:

SELECT "invalid" FROM dual; -- Using wrong quote type for string literal
-- ORA-00911: invalid character

Solution:

-- Use single quotes for string literals
SELECT 'valid' FROM dual;
-- Use double quotes for identifiers only
SELECT column_name AS "Column Name" FROM table_name;

Problem:

-- BOM character at beginning of file
SELECT * FROM employees;
-- ORA-00911: invalid character

Solution:

-- Remove BOM from file
-- Save file as UTF-8 without BOM
-- Or use text editor to remove BOM
SELECT * FROM employees;

Problem:

SELECT * FROM employées WHERE département = 'IT';
-- ORA-00911: invalid character (accented characters)

Solution:

-- Use ASCII characters for object names
SELECT * FROM employees WHERE department = 'IT';
-- Or enable proper character set support
-- ALTER DATABASE CHARACTER SET AL32UTF8;
-- (Requires DBA privileges and proper planning)
-- Check ASCII values of characters
SELECT ASCII(SUBSTR('problematic_string', 1, 1)) FROM dual;
-- Convert string to hex to see exact bytes
SELECT RAWTOHEX(UTL_RAW.CAST_TO_RAW('problematic_string')) FROM dual;
-- Check database character set
SELECT parameter, value
FROM nls_database_parameters
WHERE parameter IN ('NLS_CHARACTERSET', 'NLS_NCHAR_CHARACTERSET');
-- Check session character set
SELECT parameter, value
FROM nls_session_parameters
WHERE parameter IN ('NLS_LANGUAGE', 'NLS_TERRITORY', 'NLS_CHARACTERSET');
-- Use EXPLAIN PLAN to validate syntax without execution
EXPLAIN PLAN FOR
SELECT * FROM employees;
-- Check for parsing errors
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
-- Use editors that show invisible characters
-- Examples: Notepad++, VS Code, vim with :set list
-- Avoid copying from Word documents or web pages
-- Create function to validate SQL strings
CREATE OR REPLACE FUNCTION is_valid_sql_char(p_char VARCHAR2)
RETURN BOOLEAN IS
BEGIN
-- Check if character is valid SQL character
RETURN ASCII(p_char) BETWEEN 32 AND 126
OR p_char IN (CHR(9), CHR(10), CHR(13)); -- Tab, LF, CR
END;
/
-- Ensure consistent character sets across environment
-- Database: AL32UTF8
-- Client: UTF8
-- Files: UTF-8 without BOM
-- Follow SQL standards
-- Use single quotes for literals
SELECT 'String literal' FROM dual;
-- Use double quotes for identifiers only when necessary
SELECT employee_id AS "Employee ID" FROM employees;
-- Avoid special characters in object names
CREATE TABLE employee_data (id NUMBER); -- Good
-- CREATE TABLE employee-data (id NUMBER); -- Avoid
Terminal window
# Linux/Unix - examine file for hidden characters
hexdump -C problematic_file.sql | head -20
# Windows - use PowerShell
Format-Hex problematic_file.sql | Select-Object -First 20
-- Show invisible characters in SQL*Plus
SET PAGESIZE 0
SET LINESIZE 1000
SET TRIMSPOOL ON
-- Enable better error reporting
SET SQLBLANKLINES ON
-- Notepad++: View > Show Symbol > Show All Characters
-- VS Code: View > Render Whitespace
-- Vim: :set list
-- Comment out sections to isolate the problem
/*
SELECT * FROM employees
WHERE department_id = 10;
*/
-- Add back sections one by one
SELECT * FROM employees;
-- WHERE department_id = 10;
-- Verify file encoding in text editor
-- Convert to UTF-8 without BOM if necessary
-- Remove any special formatting
-- Manually retype the SQL statement
-- Don't copy-paste from other sources
-- Use standard keyboard characters only
-- Use online SQL validators
-- Test in SQL*Plus or SQL Developer
-- Check Oracle documentation for syntax
  • Save SQL files as UTF-8 without BOM
  • Use plain text editors for SQL development
  • Avoid copying from formatted documents
  • Use ASCII characters for object names
  • Stick to standard SQL syntax
  • Avoid smart quotes and special symbols
  • Configure editors to show invisible characters
  • Use consistent character encoding across tools
  • Set up proper Oracle client character set
  • Review SQL for non-standard characters
  • Validate syntax before deployment
  • Use version control to track changes

ORA-00911 typically results from hidden characters, encoding issues, or incorrect syntax. The key to resolution is identifying and removing invalid characters, ensuring proper encoding, and following standard SQL syntax rules. Prevention involves using appropriate tools and maintaining consistent character encoding practices.