Foreword

"My journey of mastering oracle is in its nascent stage. I face problem in small-small things. As i'm learning through self studies, through googling, i always come across small-small discoveries, which i think should be shared for beginner's benefits."
-Mithilesh
01/06/2013.

Search This Blog

Friday, June 7, 2013

Finding duplicate values in a table in Oracle

When I was trying to add constraint of primary key on existing table with some data i was getting following error:
ORA-02437: cannot validate- primary key violated
Later i realize the error was due to duplicate entries in the column to be assigned as primary key. Then i executed following syntax to find duplicate entries for modification:

Syntax 1:

select column_name, count(column_name)
from table
group by column_name
having count (column_name) > 1;

Syntax 2:

select my_id, count(*) from my_table group by my_id having count(*) >1

No comments:

Post a Comment