Script to make a non-unique column unique?

Hi all,
Currently I have a table that contains nothing but ID's (the rest of the table is to be populated at a later date).
In this table there are around 500,000,000 ID's, of which only about 35,000,000 are unique.
I need to run a script that will find all duplicate entries of an ID and delete them (only the duplicates). Only one copy of each ID should be in the table so that I can make the column the PK.
I can't think of how to do this. Any ideas?
Thanks,
fakelvis

Hello
There's a couple of ways you could do this, but I think creating a new table with the distinct list of ids, truncating the original and re-inserting the distinct may be the most optimal...if I understand correctly.
SQL> --Set up some test data to use with method 1 CTAS + Truncate
SQL> CREATE TABLE dt_test_big_tab AS SELECT object_id FROM dba_objects WHERE object_id IS NOT NUL
  2  /
Table created.
SQL> INSERT INTO dt_test_big_tab SELECT * from dt_test_big_tab
  2  /
36210 rows created.
SQL> /
72420 rows created.
SQL> /
144840 rows created.
SQL> /
289680 rows created.
SQL> /
579360 rows created.
SQL> /
1158720 rows created.
SQL> commit;
Commit complete.
SQL> SELECT COUNT(*) from dt_test_big_tab
  2  /
  COUNT(*)
   2317440
SQL> SELECT COUNT(DISTINCT object_id) from dt_test_big_tab
  2  /
COUNT(DISTINCTOBJECT_ID)
                   36210
SQL> --Set up a copy of the test data to use with method 2 - Delete duplicates
SQL> CREATE TABLE dt_test_big_tab_2 as select * from dt_test_big_tab
  2  /
Table created.
SQL> set timi on
SQL> --Method one, ctas + truncate
SQL> CREATE TABLE dt_test_unique AS SELECT DISTINCT object_id FROM dt_test_big_tab
  2  /
Table created.
Elapsed: 00:00:02.07
SQL> SELECT COUNT(*) from dt_test_unique
  2  /
  COUNT(*)
     36210
Elapsed: 00:00:00.00
SQL> SELECT COUNT(DISTINCT object_id) from dt_test_unique
  2  /
COUNT(DISTINCTOBJECT_ID)
                   36210
Elapsed: 00:00:00.00
SQL> TRUNCATE TABLE dt_test_big_tab
  2  /
Table truncated.
Elapsed: 00:00:01.02
SQL> INSERT INTO dt_test_big_tab(object_id) SELECT object_id FROM dt_test_unique
  2  /
36210 rows created.
Elapsed: 00:00:00.00
SQL> SELECT COUNT(*) from dt_test_big_tab
  2  /
  COUNT(*)
     36210
Elapsed: 00:00:00.01
SQL> SELECT COUNT(DISTINCT object_id) from dt_test_big_tab
  2  /
COUNT(DISTINCTOBJECT_ID)
                   36210
Elapsed: 00:00:00.00
SQL> --Method 2, delete duplicates
SQL> DELETE
  2  FROM
  3     dt_test_big_tab_2
  4  WHERE
  5     rowid IN(SELECT
  6                             del_rowid
  7                     FROM
  8                             (SELECT
  9                                     rowid del_rowid,
10                                     ROW_NUMBER() OVER(partition by object_id ORDER BY object_id) rn
11                             FROM
12                                     dt_test_big_tab_2
13                             )
14                     WHERE
15                                     rn > 1
16                             );
2281230 rows deleted.
Elapsed: 00:05:39.06
SQL> select count(*) from dt_test_big_tab_2;
  COUNT(*)
     36210
Elapsed: 00:00:00.03
SQL> select count(distinct object_id) from dt_test_big_tab_2;
COUNT(DISTINCTOBJECT_ID)
                   36210
Elapsed: 00:00:00.00
SQL>HTH
David

Similar Messages

  • WHat is the best index type for non uniqueness / Varchar columns in SQL 2008 R2

    Hello All Greetings,
    Please help me here with my doubt,
    in my table i have two columns about a million rows, it has about 20 columns in it, three columns with name as Period, Gender so most of the time these two columns use in where clause,
    Gender  will contain Either M or F , Period contains YYYY-Month (2013-December, 2013-August) etc so i would like to add a Index to these two columns so that in will increase the performance, so please let me know what type of indexes i need to add to
    these columns in the table,
    please note that only one time we will add data to the table which will take only 2 minutes but we query the table every day
    so my question what is the best index type that i need to create on columns with non uniqueness values in the column.,
    Thank you In Advance,
    Milan

    There is nothing whatever wrong with creating an index on a VARCHAR column, or set of columns.
    Regarding the performance of VARCHAR/INT, as with everything in a RDBMS, it depends on what you are doing. What you may be thinking of is the fact that clustering a table on a VARCHAR key is (in SQL Server) marginally less efficient than clustering on a monotonically
    increasing numerical key, and can introduce fragmentation.
    Or you may be thinking of what you have heard about writing JOINs on VARCHAR columns - it is true, it is a little less efficient than a JOIN on numeric type, but it is only a little less efficient, nothing that would lead you to never join on varchar cols.
    None of this does not mean that you should not create indexes on VARCHAR columns. A needed index on a VARCHAR column will boost query performance, often by orders of magnitude. If you need an index on a VARCHAR, create it. It makes no sense to try to find an
    integer column to create the index on - the engine will never use it.
    Check this reference: http://stackoverflow.com/questions/14041481/is-it-good-to-create-a-nonclustered-index-on-a-column-of-type-varchar
    Mark ANSWER if this reply resolves your query, If helpful then VOTE HELPFUL
    INSQLSERVER.COM
    Mohammad Nizamuddin

  • OWB Dataprofiling - Unique Key Analysis on non-number columns

    Does anyone know an easy way to enable unique key analysis on non-Number columns (OWB 10.2.0.3).
    It seems that the profiler by default disables the
    'Use in relationsship discovery' when the documented datatype is non-Number.
    Is this a setting which can be configured for OWB, or is there a smart way to set this property for all columns?
    thks in advance

    Hi don't think there is a way to to automatically switch this on/off, a small script can be created to set the option on/off for all columns in the table.
    Cheers
    David

  • Can I have a primary key as a non-unique column

    Hi all,
    I have a table with 35 columns and only one column in a not null column. But this column data is not unique. I want to create a primary key with non-unique index, can I don it, if it is not possible is there any other way to it. Please help me with this.
    Thanks for your help.vinaykotha

    1) Do the 'Unique Column combination' check first, using this example. (Pl. Change the column name and number of columns you consider as candidate key.) The SQL as follows:-
    ;WITH CTE (ProductKey, CustomerKey, SalesTerritoryKey, DupRec)
     AS
      (SELECT ProductKey, CustomerKey, SalesTerritoryKey, ROW_NUMBER() OVER
         (PARTITION BY ProductKey, CustomerKey, SalesTerritoryKey
          ORDER BY ProductKey, CustomerKey, SalesTerritoryKey) AS DupRec
       FROM dbo.FactSales 
    SELECT *
    FROM CTE
    WHERE DupRec > 1
    2) if CTE Table returns no records, you are good to create a Composite CLUSTERED PRIMARY KEY, like:
    ALTER TABLE dbo.FactSales
    ADD CONSTRAINT PK_ProductKey_CustomerKey_SalesTerritoryKey 
    PRIMARY KEY CLUSTERED (ProductKey, CustomerKey, SalesTerritoryKey);
    If no error..bingo! if NOT, Don't worry, create a Composite Index like this:-
    3)
    CREATE NONCLUSTERED INDEX [IX_ProductKey_CustomerKey_SalesTerritoryKey] 
    ON dbo.FactSales(ProductKey, CustomerKey, SalesTerritoryKey);
    This will work still efficiently. Usually all transaction table are like that like Daily_Order table, Ship_Details table etc.
    -NC

  • Display columns as rows from non-unique key table

    Hi OTN/Users, I hope you can assist me
    Given a table:
    create table t (a varchar2(30), b int, c date );
    with this data within:
    insert into t values ( a1, 40, to_date( '01-Dec-2012'));
    insert into t values ( a1, 50, to_date( '01-Dec-2012'));
    insert into t values ( a1, 60, to_date( '01-Dec-2012'));
    insert into t values ( b1, 10, to_date( '01-Dec-2012'));
    insert into t values ( b1, 20, to_date( '01-Dec-2012'));
    insert into t values ( b1, 30, to_date( '01-Dec-2012'));
    insert into t values ( c1, 60, to_date( '01-Dec-2012'));
    insert into t values ( c1, 70, to_date( '01-Dec-2012'));
    insert into t values ( c1, 80, to_date( '01-Dec-2012'));
    - I want to output the columns for each of 'a' as a single row e.g:
    a1 40 50 60 01-Dec-2012
    b1 10 20 30 01-Dec-2012
    I've almost got it right, but the 'a' col repeats 4 times for each row of output:
    a1 40
    a1 50
    a1 60
    a1 01-Dec-2012
    -I want to supress repeat output of the first column 'a' but display the rest in a straight line.
    I've tried various things (Pivot, Rollup etc), but the fact i'm keying on a table with non unique rows has complicated things perhaps.
    Any help would be much appreciated

    Hi,
    Pre-11g this is how you would do it :[11.2] Pri @ Bepripd1 > !cat t.sql
    with t(a,b,c) as (
         select  'a1', 40, to_date( '01-Dec-2012') from dual union all
         select  'a1', 50, to_date( '01-Dec-2012') from dual union all
         select  'a1', 60, to_date( '01-Dec-2012') from dual union all
         select  'b1', 10, to_date( '01-Dec-2012') from dual union all
         select  'b1', 20, to_date( '01-Dec-2012') from dual union all
         select  'b1', 30, to_date( '01-Dec-2012') from dual union all
         select  'c1', 60, to_date( '01-Dec-2012') from dual union all
         select  'c1', 70, to_date( '01-Dec-2012') from dual union all
         select  'c1', 80, to_date( '01-Dec-2012') from dual
    ------ end of sample data ------
    select
         a
         ,max(decode(n,1,b,null)) q1
         ,max(decode(n,2,b,null)) q2
         ,max(decode(n,3,b,null)) q3
         ,c
    from (
         select a, b, c, row_number() over (partition by a order by b) n
         from t
    group by a,c
    order by a,c
    [11.2] Pri @ Bepripd1 > @t
    A          Q1         Q2         Q3 C
    a1         40         50         60 01/12/2012 00:00:00
    b1         10         20         30 01/12/2012 00:00:00
    c1         60         70         80 01/12/2012 00:00:00------
    From 11g onward, you would :[11.2] Pri @ Bepripd1 > !cat t.sql
    with t(a,b,c) as (
         select  'a1', 40, to_date( '01-Dec-2012') from dual union all
         select  'a1', 50, to_date( '01-Dec-2012') from dual union all
         select  'a1', 60, to_date( '01-Dec-2012') from dual union all
         select  'b1', 10, to_date( '01-Dec-2012') from dual union all
         select  'b1', 20, to_date( '01-Dec-2012') from dual union all
         select  'b1', 30, to_date( '01-Dec-2012') from dual union all
         select  'c1', 60, to_date( '01-Dec-2012') from dual union all
         select  'c1', 70, to_date( '01-Dec-2012') from dual union all
         select  'c1', 80, to_date( '01-Dec-2012') from dual
    ------ end of sample data ------
    select a,q1,q2,q3,c
    from (
         select a, b, c, row_number() over (partition by a order by b) n
         from t
    pivot (
         max(b)
         for n in (
              1 as q1
              ,2 as q2
              ,3 as q3
    order by a,c
    [11.2] Pri @ Bepripd1 > @t
    A          Q1         Q2         Q3 C
    a1         40         50         60 01/12/2012 00:00:00
    b1         10         20         30 01/12/2012 00:00:00
    c1         60         70         80 01/12/2012 00:00:00Edited by: Nicosa on Nov 9, 2012 2:42 PM

  • Primary Key supported by a non-unique index?

    Encountered a weird situation today. A utility we setup which allows Analysts to restore data into their tables, started failing when it attempted to drop an index. The index was supporting a Primary Key. Makes sense. But our script was supposed to only be attempting to drop/recreate non-unique indexes. Turns out the supporting index on the Primary Key was non-unique, and to the best of my knowledge came about as follows:
    SQL> create table junk (f number(1));
    Table created.
    SQL> create index junk_ix on junk(f);
    Index created.
    SQL> select UNIQUENESS from DBA_INDEXES where index_name = 'JUNK_IX';
    UNIQUENES
    NONUNIQUE
    SQL> alter table forbesc.junk add constraint junk_pk primary key (f) using index junk_ix;
    Table altered.
    SQL> select UNIQUENESS from DBA_INDEXES where index_name = 'JUNK_IX';
    UNIQUENES
    NONUNIQUE
    SQL> insert into junk values (1);
    1 row created.
    SQL> insert into junk values (1);
    insert into junk values (1)
    ERROR at line 1:
    ORA-00001: unique constraint (FORBESC.JUNK_PK) violated
    SQL> select index_name from dba_constraints where constraint_name = 'JUNK_PK';
    INDEX_NAME
    JUNK_IXWhat I can't figure out is how a non-unique index is enforcing uniqueness. I thought that it was the key in that very same process. I thought that perhaps an index with the 'SYS_123456' was getting created, perhaps, but I couldn't find one:
    SQL> select object_name, object_type from dba_objects order by created desc;
    OBJECT_NAME   OBJECT_TYPE
    JUNK_IX     INDEX
    JUNK     TABLE
    ...How is the uniqueness getting enforced in this case? This is in Oracle 11.1.0.7
    Thanks,
    --=Chuck

    It has always been that way. Oracle can, and will, use a non-unique index to enforce a PK constraint, The existing index just needs to have the PK column(s) as the leading column(s) of the index:
    SQL> create table t (id number, id1 number, descr varchar2(10));
    Table created.
    SQL> create index t_ids on t(id, id1);
    Index created.
    SQL> select index_name from user_indexes
      2  where table_name = 'T';
    INDEX_NAME
    T_IDS
    SQL> alter table t add constraint t_pk
      2  primary key (id);
    Table altered.
    SQL> select index_name from user_indexes
      2  where table_name = 'T';
    INDEX_NAME
    T_IDS
    SQL> insert into t values (1, 1, 'One');
    1 row created.
    SQL> insert into t values (1, 2, 'Two');
    insert into t values (1, 2, 'Two')
    ERROR at line 1:
    ORA-00001: unique constraint (OPS$ORACLE.T_PK) violatedJohn

  • Unique index vs non-unique index

    Hi Gurus,
    I'm getting lots of "TABLE ACCESS FULL" for lots of columns which have non-unique indexes is some queries. So my question is does optimizer does not pick up non-unique index but only pickes up unique indexes for those columns.
    Thanks
    Amitava.

    amitavachatterjee1975 wrote:
    Hi Gurus,
    I'm getting lots of "TABLE ACCESS FULL" for lots of columns which have non-unique indexes is some queries. So my question is does optimizer does not pick up non-unique index but only pickes up unique indexes for those columns.
    Thanks
    Amitava.WHY MY INDEX IS NOT BEING USED
    http://communities.bmc.com/communities/docs/DOC-10031
    http://searchoracle.techtarget.com/tip/Why-isn-t-my-index-getting-used
    http://www.orafaq.com/tuningguide/not%20using%20index.html

  • Auto-Suggest feature in Combo-box LOV is not displaying non-unique values

    Hi,
    I have an auto-suggest feature implementation on a combo-box lov that displays the name and email-id of a list of people. There are non-unique names in the back-end, for example :
    Abraham Mason [email protected]
    Abraham Mason [email protected]
    But when I use the auto-suggest feature and type in, say 'Ab', instead of showing both the Abraham Masons the auto-suggest displays only one of the values.
    As in the example above the email-ids of the two Abraham Masons are different and unique.
    If I use the conventional drop down menu of the combo-box then both the values are visible.
    Is the auto-suggest feature implemented in a manner so as to display only unique values?
    This is the implementation of the auto-suggest feature that I have done -
    <af:column headerText="#{bindings.RqmtAtLevel1.hints.Owner.label}"
    id="c23" sortable="true" filterable="true"
    sortProperty="Owner"
    filterFeatures="caseInsensitive">
    <af:inputComboboxListOfValues id="ownerId"
    popupTitle="#{ResourcesGenBundle['Header.SearchandSelect.Searchandselectanobjectusingad']}: #{bindings.RqmtAtLevel1.hints.Owner.label}"
    value="#{row.bindings.Owner.inputValue}"
    model="#{row.bindings.Owner.listOfValuesModel}"
    required="#{bindings.RqmtAtLevel1.hints.Owner.mandatory}"
    columns="#{bindings.RqmtAtLevel1.hints.Owner.displayWidth}"
    shortDesc="#{bindings.RqmtAtLevel1.hints.Owner.tooltip}"
    autoSubmit="true">
    <f:validator binding="#{row.bindings.Owner.validator}"/>
    <af:autoSuggestBehavior suggestedItems="#{row.bindings.Owner.suggestedItems}"/>
    </af:inputComboboxListOfValues>
    </af:column>
    Thanks,
    Anirudh Acharya

    Hi,
    don't find a bug entry about this, so if this indeed is a defect then this has not been filed. Do you have a test case ? If you have please zip it up and send it in a mail to me. My mail address is in my OTN profile (just click on my name until you get to the profile). Pleas rename the "zip" extension to "unzip" and mention the JDeveloper release you work with. The test case should work against the Oracle HR schema.
    If you need to track the issue, I suggest to file a service request with customer support yourself
    Frank

  • Java OracleXML putXML & non-unique keys

    I am using the XML SQL Utility for java on the client (NT) to insert multi-row XML documents into an ORACLE table. Everything works fine until I hit a row with a non-unique key. It appears insertXML throws an error and the insert stops at that point. Rows after the non-unique key row are not processed.
    Is there any way to process all rows of an XML document, telling me how many read, how many inserted, how many not processed??
    Also, what about update capabilities? Presently I am not needing to update from XML into ORACLE, all I can do now is insert.
    Thanks in advance,
    Rick

    One way to make this work would be to take advantage of Oracle8i's INSTEAD OF triggers on views.
    Basically, you would:
    (1) CREATE VIEW someview
    AS SELECT * FROM sometable;
    (2) CREATE TRIGGER someview_trig
    INSTEAD OF INSERT ON someview
    DECLARE
    BEGIN
    -- Check for existence of
    -- row using the value of
    -- :NEW.pk_column_name
    IF (you-found-an-existing-one) THEN
    -- Do something here like
    -- NULL; to ignore the insert altogether
    -- or possible an INSERT into
    -- and EXCEPTIONS table...
    ELSE
    INSERT INTO sometable
    VALUES (:NEW.column1, ..., :NEW.columnn);
    END IF;
    END;
    (3) Then point XML SQL Utility at someview
    instead of sometable
    and you'll be in business, as they say.

  • ICal 3.x .ics import - problem with recurring events and non-unique UIDs

    Upgraded to Leopard over the holiday break. Under Tiger's iCal (v2.x), .ics files exported from other calendar programs (Outlook via iAppoint/O2M in this case) and imported into iCal behaved 'normally'. However, in iCal 3.x in Leopard, for recurring appointments in the exported calendar, only the last appointment in the series shows up in iCal (although some meetings show up for about 0.25 seconds during the calendar import, then immediately disappear! This post by MalcolmS provided the critical clue - it seems that for recurring events, the .ics file has all of the events in the series with the same UID. Previous versions of iCal didn't care, but v3 apparently does - and deletes all earlier versions of the event, leaving only the last one with that UID. I confirmed that is the case by opening the .ics file in Word, which clearly showed all of the recurring events, and all the events in a series (e.g. a weekly meeting for the year) had the same UID. After the import to iCal, only the last one is in the calendar (in the above example, the one meeting of the series occurring in the last week of December). Manually editing the UIDs of a recurring series in the .ics file (to make them actually unique) allows them to all show up in iCal after import.
    Since many of the events in my Outlook calendar are accepted invites for recurring appointments, re-creating them as individual calendar events in Outlook is not a viable option. The frequency of changes to my calendar means I usually export it once per day (or twice); thus, manually editing the .ics files is also not a viable option.
    Any suggestions on workarounds for this problem? Alternatively, any other suggestions for getting the calendar data from Outlook into iCal?
    Thanks in advance!

    Moot point, as direct iPhone access to the Exchange server is now supported by our IT department.

  • C# - How to have a collection of SPListItems each associated with a non-unique number?

    Hi there,
    I need to have a collection of multiple SPListItems - each associated with a number (non-unique). 
    I should be able to get all SPListItems for any specific number. E.g.
    (13, SPListItem1)
    (16, SPListItem2)
    (13, SPListItem3)
    (17, SPListItem4)
    (13, SPListItem1)
    Now - I should be able to get all SPListItems where number is 13 or whatever.
    What will be the fast and efficient way to do this in your opinion?
    Thanks.

    You could create a custom class that holds the SPListItem and the integer. Add the splistitems to a List using the type of class you created to hold the SPListItem and integer. Then use the List<T>.Sort method when you want to sort them.
    Have a look at the documentation here: http://msdn.microsoft.com/en-us/library/b0zbh7b6(v=vs.90).aspx
    Regards, Matthew
    MCPD | MCITP
    My Blog
    View
    Matthew Yarlett's profile
    See my webpart on the TechNet Gallery that allows administrative users to upload, crop and format user profile photos. Check it out here:
    Upload and Crop User Profile Photos

  • How to make the entry unique

    Hi guys,
    I have a table of people with the following fields:
    firstName
    lastName
    DOB
    email
    address
    group
    as you can see, nothing makes an entry unique. so say I would like to get some info about John Smith, I might found more than one entry for John Smith.
    Question: any idea how to make an entry unique? hashing???
    I'm using mySQL.
    Thanks for any help
    Peter

    You need to assign a primary key to your table ( a field that can't be reproduced). You can add a social security field and make it your primary key.
    Your mysql line might look like this (for a table with 2 fields):
    mysql> CREATE TABLE Info( Name varchar(64),
                                                         SSN varchar(64) primary key);

  • Managing Internet clients with non unique names

    I've got a wee complication which revolves around the fact the majority clients I am looking to deploy to are workgroup clients which have non-unique netbios/short names. 
    So when trying to manage said clients when looking at the Assets / Devices tab they for all intensive purposes appear identical - until I look at the properties of each item and look at the Resource Name - which will show the FQDN fo said machine.
    If I was able to select Resource name as a viewable field in the view this would fix my problem. Unfortunately all machines currently have the same Workgroup set so just displaying the "Domain" field will not suffice.
    Has anyone run into this issue and what can be done to work around it short of renaming all my intended clients? I've seen mention of creating your own Console custom nodes however this looks rather hairy.
    Any thoughts are greatly appreciated. Cheers.

    Also, I don't think that it will really help you, because the Devices
    node is build on the SMS_CombinedDeviceResources class and that WMI class simply doesn't contain the
    Resource Name property.
    In this case it would mean creating a whole new node in the console. Probably using a Query, or Report is the most simple and best workaround.
    My Blog: http://www.petervanderwoude.nl/
    Follow me on twitter: pvanderwoude

  • Testing BPEL Processes with non-unique activity names

    Hello,
    I intend to use Oracles BPEL Test Framework for testing a set of BPEL workflows. I created a test suite for one process but during the deployment of the test suite i got the message:
    [Error ORABPEL-20043]: Non-unique activity name.
    In the workflow set are a lot of activties with equal names, at least 100, so renaming is not an option. Is there any possibilty to use the Test Framework nevertheless?
    Thanks for your answers.

    Here the answer from Oracle:
    Even if there is little documentation surrounding the need to have unique activity names, this issue will be treated
    as an enhancement from Development point of view.
    Therefore, I was asked to create an Enhancement Request, so that this will be considered for
    implementation in a future release.
    It's not a bug, it's a feature...

  • Best Way to Enumerate a non-unique Array of String to Integers

    Hello,
    I am trying to find the best way to enumerate an array of strings to integers. This string array is thousands in number and contains non-unique values.
    I also don't know before run-time what those values are, so I have to dynamically determine the enumeration.
    For example a user reads in an array of colors (but we didnt know this before runtime) of "red", "green", "red", "blue", "white", "green", "black", "blue"
    I would like this to enumerate to 0, 1, 0, 2, 3, 1, 4, 2
    as zero based enumeration.
    Is there any suggested methods of doing this as efficiently on SPEED over MEMORY as possible?
    Thanks!
    Glenn

    I also don't know before run-time what those values are, so I have to dynamically determine the enumeration.Are you saying that you can't pre-define the universe of colors that a user could potentially enter? If so, how will you determine the equivalence of RED to 0, etc? That sounds suspicious, there is a finite number of colors!
    Anyway, for what it's worth, here's some code (that requires you know the color labels that could be entered.)
    enum Color
        RED(0), GREEN(1), BLUE(2), BLACK(3), WHITE(4);
        private final int colorValue;
        private Color(int colorValue)
            this.colorValue = colorValue;
        public int getColorValue()
            return colorValue;
    public class EnumTest
        public static void main(String[] args)
            System.out.println(Color.RED + " = " + Color.RED.getColorValue());
            System.out.println(Color.GREEN + " = " + Color.GREEN.getColorValue());
            System.out.println(Color.BLUE + " = " + Color.BLUE.getColorValue());
            System.out.println(Color.BLACK + " = " + Color.BLACK.getColorValue());
            System.out.println(Color.WHITE + " = " + Color.WHITE.getColorValue());
    }

Maybe you are looking for