Generate native oracle database alphanumeric sequence

43 views Asked by At

Can anyone give me some idea to generate native oracle database alphanumeric sequence with column length 4, like 000A,000B and so on. I need 200k or more records of this sequence.

Any ideas/solutions are highly appreciated.

Thanks in advance

1

There are 1 answers

0
MT0 On

If you want a SELECT statement to generate hexadecimal values then:

SELECT TO_CHAR(LEVEL, 'FM0000X')
FROM DUAL
CONNECT BY LEVEL <= 200000;

If you want a SEQUENCE then they only generate numeric values; however, you can wrap its output in the same TO_CHAR function:

CREATE SEQUENCE table_name__id__seq;

CREATE TABLE table_name (
  id VARCHAR2(5)
);

INSERT INTO table_name (id)
VALUES (TO_CHAR(table_name__id__seq.NEXTVAL, 'FM0000X'));

SELECT * FROM table_name;

Outputs:

ID
00001

db<>fiddle here