Resolve ORA-00957 Error Message in Oracle

Learn the reason and how to unravel the ORA-00957 error message in Oracle.

Description

When you come across an ORA-00957 error, the following error message will appear:

ORA-00957: duplicate column name

Cause

You tried to execute either a CREATE TABLE or INSERT assertion the place the identical column name used to be listed extra than once.

Or you tried to execute a UPDATE statement the place the identical column identify used to be listed greater than as soon as in the SET clause.

Resolution

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

Option #1

If this error befell during a CREATE TABLE, right the announcement so that each column listed in the CREATE TABLE statement is unique.

For example, if you tried to create the following table:

CREATE TABLE supplier
( supplier_id numeric(10) not null,
  supplier_name varchar2(50) not null,
  supplier_id numeric(8)
);

You would receive the following error message:

Since the supplier_id field appears twice, the CREATE TABLE announcement will fail. You need to make certain that each column title is unique.

You could correct the statement as follows:

CREATE TABLE supplier
( supplier_id numeric(10) not null,
  supplier_name varchar2(50) not null,
  supplier_id2 numeric(8)
);

Option #2

If this error happened for the duration of an INSERT statement, right the statement so that every column listed is unique.

For example, if you tried to execute the following INSERT statement:

INSERT INTO supplier
(supplier_id, supplier_name, supplier_id)
VALUES
(1000, 'IBM', '1000');

You would receive the following error message:

Since the supplier_id field seems twice, the INSERT announcement will fail. You can correct this by way of putting off the duplicate column name as follows:

INSERT INTO supplier
(supplier_id, supplier_name)
VALUES
(1000, 'IBM');

Option #3

If this error befell in the course of an UPDATE statement, right the declaration so that each column listed in the SET clause is unique.

For example, if you tried to execute the following UPDATE statement:

UPDATE suppliers
SET supplier_id = 1000,
    supplier_id = 1000
WHERE supplier_id = 1;

You would receive the following error message:

Since the supplier_id field appears twice in the SET clause, the UPDATE statement will fail. You can correct this by way of getting rid of the reproduction column identify as follows:

UPDATE suppliers
SET supplier_id = 1000
WHERE supplier_id = 1;