又仔细看了一下Oracle 的函数,关于Format Models:

http://download-west.oracle.com/ ... lements4a.htm#34572

其中格式为“X”的部分:

XXXX / xxxx : Returns the hexadecimal value of the specified number of digits. If the specified number is not an integer, then Oracle rounds it to an integer.

Restrictions:

·This element accepts only positive values or 0. Negative values return an error.

·You can precede this element only with 0 (which returns leading zeroes) or FM. Any other elements return an error. If you specify neither 0 nor FM with X, then the return always has 1 leading blank.

又做了一些试验:

[PHP]

SQL> select to_char(3, 'XXXX') from dual;

TO_CHAR(3,'XXXX')

-----------------

3

SQL> select to_char(13, 'XXXX') from dual;

TO_CHAR(13,'XXXX')

------------------

D

SQL> select to_char(16, 'XXXX') from dual;

TO_CHAR(16,'XXXX')

------------------

10

SQL> select to_char(175, 'XXXX') from dual;

TO_CHAR(175,'XXXX')

-------------------

AF

SQL> select to_char(2380, 'XXXX') from dual;

TO_CHAR(2380,'XXXX')

--------------------

94C

SQL> select to_char(12500, 'XXXX') from dual;

TO_CHAR(12500,'XXXX')

---------------------

30D4

SQL> select to_number('3', 'XXXX') from dual;

TO_NUMBER('3','XXXX')

---------------------

3

SQL> select to_number('D', 'XXXX') from dual;

TO_NUMBER('D','XXXX')

---------------------

13

SQL> select to_number('10', 'XXXX') from dual;

TO_NUMBER('10','XXXX')

----------------------

16

SQL> select to_number('AF', 'XXXX') from dual;

TO_NUMBER('AF','XXXX')

----------------------

175

SQL> select to_number('94C', 'XXXX') from dual;

TO_NUMBER('94C','XXXX')

-----------------------

2380

SQL> select to_number('30D4', 'XXXX') from dual;

TO_NUMBER('30D4','XXXX')

------------------------

12500

SQL>

`

[/PHP]

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐