Adsense Ad

Thursday 25 May 2017

Oracle: ORA-00960 Error Message

ORA-00960 Error Message

Learn the cause and how to resolve the ORA-00960 error message in Oracle.

Description

When you encounter an ORA-00960 error, the following error message will appear:
  • ORA-00960: ambiguous column naming in select list

Cause

You tried to execute a SELECT statement where a column with the same name is listed in the SELECT list and then ambiguously defined within the ORDER BY clause.

Resolution

The option(s) to resolve this Oracle error are:

Option #1

Try prefixing the column that is ambiguously defined in the ORDER BY clause with the table name.
For example, if you tried to execute the following SELECT statement:
SELECT suppliers.supplier_id, orders.supplier_id
FROM suppliers
INNER JOIN orders
ON suppliers.supplier_id = orders.supplier_id
ORDER BY supplier_id;
You would receive the following error message:
Oracle PLSQL
You could correct this error by prefixing the supplier_id column in the ORDER BY clause with either supplier or orders.
For example:
SELECT suppliers.supplier_id, orders.supplier_id
FROM suppliers
INNER JOIN orders
ON suppliers.supplier_id = orders.supplier_id
ORDER BY suppliers.supplier_id;
OR
SELECT suppliers.supplier_id, orders.supplier_id
FROM suppliers
INNER JOIN orders
ON suppliers.supplier_id = orders.supplier_id
ORDER BY orders.supplier_id;

No comments: