DEV Community

umzzil nng
umzzil nng

Posted on • Originally published at oraerror.com

Oracle ORA-00998 Error: Causes and Solutions Complete Guide

ORA-00998: Must Name This Expression with a Column Alias

ORA-00998 is an Oracle error that occurs when you attempt to create a view or use a subquery where one or more columns in the SELECT clause are expressions (such as functions, arithmetic operations, or CASE statements) without an assigned column alias. Oracle requires every column in a view to have a unique, explicit name, and it cannot automatically generate a valid name for complex expressions. This error is one of the most common mistakes when building views in Oracle and is straightforward to fix once you understand the root cause.


Top 3 Causes

1. Arithmetic Expressions Without an Alias in CREATE VIEW

When you use mathematical operations in a SELECT list inside a CREATE VIEW statement and forget to add an alias, Oracle throws ORA-00998 immediately.

-- ❌ Causes ORA-00998
CREATE VIEW v_salary AS
SELECT 
    employee_id,
    salary * 12,       -- No alias!
    salary * 1.1       -- No alias!
FROM employees;

-- ✅ Fixed version
CREATE VIEW v_salary AS
SELECT 
    employee_id,
    salary * 12    AS annual_salary,
    salary * 1.1   AS adjusted_salary
FROM employees;
Enter fullscreen mode Exit fullscreen mode

2. Aggregate Functions Without an Alias

Aggregate functions like COUNT(), SUM(), AVG(), MAX(), and MIN() do not produce a named column automatically. Using them inside a CREATE VIEW without an alias triggers this error.

-- ❌ Causes ORA-00998
CREATE VIEW v_dept_summary AS
SELECT 
    department_id,
    COUNT(*),        -- No alias!
    AVG(salary),     -- No alias!
    SUM(salary)      -- No alias!
FROM employees
GROUP BY department_id;

-- ✅ Fixed version
CREATE VIEW v_dept_summary AS
SELECT 
    department_id,
    COUNT(*)     AS emp_count,
    AVG(salary)  AS avg_salary,
    SUM(salary)  AS total_salary
FROM employees
GROUP BY department_id;
Enter fullscreen mode Exit fullscreen mode

3. CASE, DECODE, and String Concatenation Without an Alias

Expressions using CASE WHEN, DECODE(), or the || string concatenation operator are complex expressions that Oracle cannot name automatically. Omitting an alias for any of these in a view definition will cause ORA-00998.

-- ❌ Causes ORA-00998
CREATE VIEW v_emp_details AS
SELECT 
    employee_id,
    first_name || ' ' || last_name,     -- No alias!
    CASE 
        WHEN salary > 10000 THEN 'HIGH'
        ELSE 'LOW'
    END,                                 -- No alias!
    DECODE(job_id, 'IT_PROG', 'Dev', 
                   'Other')             -- No alias!
FROM employees;

-- ✅ Fixed version
CREATE VIEW v_emp_details AS
SELECT 
    employee_id,
    first_name || ' ' || last_name      AS full_name,
    CASE 
        WHEN salary > 10000 THEN 'HIGH'
        ELSE 'LOW'
    END                                  AS salary_grade,
    DECODE(job_id, 'IT_PROG', 'Dev', 
                   'Other')              AS job_desc
FROM employees;
Enter fullscreen mode Exit fullscreen mode

Quick Fix Solutions

  • Add AS alias_name after every expression that is not a plain column reference.
  • Use the column list syntax in the CREATE VIEW header as an alternative:
-- Alternative: define column names upfront in the view header
CREATE VIEW v_emp_summary (emp_id, full_name, annual_salary) AS
SELECT 
    employee_id,
    first_name || ' ' || last_name,
    salary * 12
FROM employees;
Enter fullscreen mode Exit fullscreen mode

Prevention Tips

  1. Always alias every expression — Adopt a team coding standard that requires a meaningful alias for any non-trivial expression in SELECT lists, especially inside view definitions. Tools like SQLFluff can enforce this automatically in your CI/CD pipeline.

  2. Test your SELECT before creating the view — Run the SELECT statement standalone in your SQL client first. If you see a column header that looks like SALARY*12 or COUNT(*) instead of a clean name, that column needs an alias before you wrap it in a CREATE VIEW statement.


📖 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)