- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Decimal to hexadecimal conversion vith Oracle
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 12:55 AM
тАО04-22-2004 12:55 AM
Decimal to hexadecimal conversion vith Oracle
Is there a way to convert decimal value to hexadecimal within an Oracle SQL request?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 01:15 AM
тАО04-22-2004 01:15 AM
Re: Decimal to hexadecimal conversion vith Oracle
If think there is no direct SQL function to do this.
Take a look at :
http://www.revealnet.com/pipelines/plsql/archives.htm#code27
Cheers
Nicolas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 05:56 PM
тАО04-22-2004 05:56 PM
Re: Decimal to hexadecimal conversion vith Oracle
You can get the hexadecimal value for a number by using the function TO_CHAR in SQLPLUS.
To convert a decimal number to hexadecimal For example, the number "123" will be converted to "7B".
SQL> select to_char(123,'XXX') from dual
output : 7B
You must ensure that your format string is as large as the biggest value you will need to convert, but this is a built-in feature.
Or you can write a PLSQL package to define your own function for the conversion. Eg:- below.
FUNCTION dec_to_hex (decin IN NUMBER) RETURN VARCHAR2 IS
v_decin NUMBER;
v_next_digit NUMBER;
v_result varchar(2000);
BEGIN
v_decin := decin;
WHILE v_decin > 0 LOOP
v_next_digit := mod(v_decin,16);
IF v_next_digit > 9 THEN
IF v_next_digit = 10 THEN v_result := 'A' || v_result;
ELSIF v_next_digit = 11 THEN v_result := 'B' || v_result;
ELSIF v_next_digit = 12 THEN v_result := 'C' || v_result;
ELSIF v_next_digit = 13 THEN v_result := 'D' || v_result;
ELSIF v_next_digit = 14 THEN v_result := 'E' || v_result;
ELSIF v_next_digit = 15 THEN v_result := 'F' || v_result;
ELSE raise_application_error(-20600,'Untrapped exception');
END IF;
ELSE
v_result := to_char(v_next_digit) || v_result;
END IF;
v_decin := floor(v_decin / 16);
END LOOP;
RETURN v_result;
END dec_to_hex;
v_return := v_return + TO_NUMBER(v_charval) * POWER(2,v_power);
I hope this helps.
Indira A
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 06:17 PM
тАО04-22-2004 06:17 PM
Re: Decimal to hexadecimal conversion vith Oracle
SQL> select rawtohex(job_id) from jobs;
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2004 11:02 PM
тАО04-22-2004 11:02 PM
Re: Decimal to hexadecimal conversion vith Oracle
In 8i (8.1) and up, it is simply:
select to_char( number, 'xxxxxxx' ) from t;
hope this helps too!
regards
Yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-23-2004 12:14 AM
тАО04-23-2004 12:14 AM
Re: Decimal to hexadecimal conversion vith Oracle
SQL> select ip_address, to_char(ip_address, 'XXXXX') from opc_node_names where node_name like 'cexi01%';
IP_ADDRESS TO_CHA
---------- ------
957054740 ######
SQL> select ip_address, rawtohex(ip_address) from opc_node_names where node_name like 'cexi01%';
IP_ADDRESS RAWTOHEX(IP_ADDRESS)
---------- --------------------------------------------
957054740 C50A3A063029
IP_ADDRESS's type is NUMBER(12)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-23-2004 12:33 AM
тАО04-23-2004 12:33 AM
Re: Decimal to hexadecimal conversion vith Oracle
select to_char(957054740,'XXXXXXXXX') from dual;
TO_CHAR(95
----------
390B7F14
Cheers
Nicolas