如何在oracle中增加十六进制值

时间:2017-10-24 07:52:02

标签: oracle hex increment

我试图在oracle表中增加一列,其id定义为raw:

ID    VALUE
----------
1    A14
2    B13 
3    C15
4    D16 

我需要

   ID    VALUE
----------
1    A24
2    B23 
3    C25
4    D26 

oracle中有任何函数如何递增? 感谢

1 个答案:

答案 0 :(得分:2)

使用格式为掩码TO_NUMBER的{​​{1}}和TO_CHAR作为十六进制数字:

SQL Fiddle

Oracle 11g R2架构设置

X

查询1

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' ), 'FMXXXX' );

<强> Results

SELECT * FROM table_name