Value in Oracle

How to Increment Hex Value in Oracle

 

Use TO_NUMBER and TO_CHAR with the format mask X for a hexadecimal digit:

SQL Fiddle

Oracle 11g R2 Schema Setup:

CREATE TABLE TABLE_NAME (
  ID    INTEGER,
  VALUE VARCHAR2(20)
);

INSERT INTO TABLE_NAME
SELECT 1, 'A14' FROM DUAL UNION ALL
SELECT 2, 'B13' FROM DUAL UNION ALL
SELECT 3, 'C15' FROM DUAL UNION ALL
SELECT 4, 'D16' FROM DUAL UNION ALL
SELECT 5, 'FFF' FROM DUAL;

UPDATE table_name
SET value = TO_CHAR( TO_NUMBER( value, 'XXXX' ) + TO_NUMBER( '10', 'XX' ), 'XXXX' );

Query 1:

SELECT * FROM table_name

Results:

| ID | VALUE |
|----|-------|
|  1 |   A24 |
|  2 |   B23 |
|  3 |   C25 |
|  4 |   D26 |
|  5 |  100F |

LEAVE A REPLY

Please enter your comment!
Please enter your name here