The following code is used to create a auto increment in oracle using unique and non-unique column values:
DROP TABLE TEST;
CREATE TABLE TEST(
DESCRIPTION VARCHAR(10),
someidentifier NUMBER
);
INSERT INTO TEST (DESCRIPTION, SOMEIDENTIFIER) VALUES ('A', 1);
INSERT INTO TEST (DESCRIPTION, SOMEIDENTIFIER) VALUES ('B',2);
INSERT INTO TEST (DESCRIPTION, SOMEIDENTIFIER) VALUES ('C', 5);
INSERT INTO TEST (DESCRIPTION, SOMEIDENTIFIER) VALUES ('C', 6);
SELECT
DESCRIPTION, (
SELECT COUNT(1) FROM TEST B WHERE A.DESCRIPTION >= B.DESCRIPTION AND A.SOMEIDENTIFIER >= B.SOMEIDENTIFIER
) as autoincrement
FROM
TEST A
order by description, SOMEIDENTIFIER;
DROP TABLE TEST;
CREATE TABLE TEST(
DESCRIPTION VARCHAR(10),
someidentifier NUMBER
);
INSERT INTO TEST (DESCRIPTION, SOMEIDENTIFIER) VALUES ('A', 1);
INSERT INTO TEST (DESCRIPTION, SOMEIDENTIFIER) VALUES ('B',2);
INSERT INTO TEST (DESCRIPTION, SOMEIDENTIFIER) VALUES ('C', 5);
INSERT INTO TEST (DESCRIPTION, SOMEIDENTIFIER) VALUES ('C', 6);
SELECT
DESCRIPTION, (
SELECT COUNT(1) FROM TEST B WHERE A.DESCRIPTION >= B.DESCRIPTION AND A.SOMEIDENTIFIER >= B.SOMEIDENTIFIER
) as autoincrement
FROM
TEST A
order by description, SOMEIDENTIFIER;