DEV Community

umzzil nng
umzzil nng

Posted on • Originally published at oraerror.com

Oracle ORA-00932 Error: Causes and Solutions Complete Guide

ORA-00932: Inconsistent Datatypes — Causes, Fixes & Prevention

ORA-00932 is one of the most common Oracle errors developers encounter when mixing incompatible data types in SQL or PL/SQL statements. Oracle raises this error when it cannot perform an implicit conversion between the data types involved in a comparison, function call, or set operation. Understanding the root cause quickly is critical because this error can surface in simple queries, complex stored procedures, and even ORM-generated SQL.


Top 3 Causes with SQL Examples

Cause 1: Type Mismatch in WHERE Clause or JOIN Conditions

Comparing a NUMBER column to a non-numeric string, or a DATE column directly against an integer, is a classic trigger for ORA-00932.

-- Problematic: Comparing NUMBER column with an invalid string
SELECT * FROM employees WHERE employee_id = '100A';

-- Problematic: DATE column compared with a plain number
SELECT * FROM orders WHERE order_date = 20240101;

-- Fixed: Use explicit conversion functions
SELECT * FROM employees WHERE employee_id = 100;

SELECT * FROM orders
WHERE order_date = TO_DATE('20240101', 'YYYYMMDD');
Enter fullscreen mode Exit fullscreen mode

Cause 2: Column Type Mismatch in UNION / UNION ALL

Every column in the same position across UNION queries must be type-compatible. Mixing DATE and VARCHAR2, or NUMBER and CLOB, in the same column position will immediately cause ORA-00932.

-- Problematic: DATE vs VARCHAR2 in same column position
SELECT employee_id, hire_date        -- hire_date is DATE
FROM employees
UNION ALL
SELECT dept_id, dept_name            -- dept_name is VARCHAR2 → ERROR
FROM departments;

-- Fixed: Cast to a common type explicitly
SELECT employee_id, TO_CHAR(hire_date, 'YYYY-MM-DD') AS info_col
FROM employees
UNION ALL
SELECT dept_id, dept_name
FROM departments;
Enter fullscreen mode Exit fullscreen mode

Cause 3: Passing Wrong Data Type to a Function

Aggregate functions like SUM() or AVG() expect numeric arguments. Passing a VARCHAR2 column without conversion will fail. Similarly, applying standard string functions directly to CLOB columns triggers ORA-00932.

-- Problematic: SUM on a VARCHAR2 column
SELECT SUM(salary_text) FROM employee_payroll;  -- ORA-00932

-- Problematic: UPPER() on a CLOB column
SELECT * FROM documents WHERE UPPER(doc_content) = 'ORACLE';

-- Fixed: Explicit conversion before aggregation
SELECT SUM(TO_NUMBER(salary_text))
FROM employee_payroll
WHERE REGEXP_LIKE(salary_text, '^\d+(\.\d+)?$');

-- Fixed: Use DBMS_LOB for CLOB operations
SELECT * FROM documents
WHERE UPPER(DBMS_LOB.SUBSTR(doc_content, 200, 1)) = 'ORACLE';
Enter fullscreen mode Exit fullscreen mode

Quick Fix Solutions

Scenario Fix
String vs NUMBER Use TO_NUMBER() or correct the literal
String vs DATE Use TO_DATE('value', 'format')
NUMBER vs VARCHAR2 Use TO_CHAR() to convert the number
CLOB in comparisons Use DBMS_LOB.SUBSTR() to extract text
UNION type clash Cast all columns to a consistent type
-- Universal quick-fix pattern: always cast explicitly
SELECT
    TO_CHAR(order_date, 'YYYY-MM-DD')  AS order_date_str,
    TO_NUMBER(revenue_text)            AS revenue_num,
    TO_DATE(created_str, 'YYYYMMDD')   AS created_date
FROM sales_staging;
Enter fullscreen mode Exit fullscreen mode

Prevention Tips

1. Enforce Correct Column Types at Design Time

Never store numeric or date data as VARCHAR2 in your schema. Define columns with proper types (NUMBER, DATE, TIMESTAMP) from the start. Add a rule to your team's SQL coding standards: always use explicit conversion functions — never rely on implicit casting.

2. Use Static Analysis Tools and Test Before Deploying

Integrate tools like SQL Developer's code analysis or SonarQube into your CI/CD pipeline to catch type mismatches early. Write unit tests covering edge-case data types, especially for UNION queries and stored procedures, before promoting code to production.

-- Always validate data before numeric conversion in ETL pipelines
INSERT INTO target_table (id, amount)
SELECT
    id,
    TO_NUMBER(raw_amount)
FROM source_staging
WHERE REGEXP_LIKE(raw_amount, '^\d+(\.\d+)?$');  -- Guard clause
Enter fullscreen mode Exit fullscreen mode

Related Oracle Errors

  • ORA-01722 – Invalid number; triggered when implicit string-to-number conversion fails
  • ORA-01858 – Non-numeric character found in date format conversion
  • ORA-06502 – PL/SQL numeric or value error; the PL/SQL counterpart of ORA-00932

📖 Want a more detailed guide?
Check out the full in-depth version (Korean) on oraerror.com — includes detailed analysis, additional SQL examples, and prevention tips.

Top comments (0)