PostgreSQL Tutorial PostgreSQL Advanced PostgreSQL Database Account Management PostgreSQL References
PostgreSQL Tutorial PostgreSQL Advanced PostgreSQL Database Account Management PostgreSQL References

PostgreSQL TO_HEX() Function



The PostgreSQL TO_HEX() function returns a string containing hexadecimal representation of an integer value.

Syntax

TO_HEX(num)

Parameters

num Required. Specify an integer value to convert to a hexadecimal representation.

Return Value

Returns the hexadecimal representation of an integer value.

Example 1:

The example below shows the usage of TO_HEX() function.

SELECT TO_HEX(20);
Result: '14'

SELECT TO_HEX(100);
Result: '64'

SELECT TO_HEX(500);
Result: '1f4'

SELECT TO_HEX(1000);
Result: '3e8'

Example 2:

Consider a database table called Sample with the following records:

Datax
Data 110
Data 220
Data 330
Data 440
Data 550

The statement given below can be used to get the hexadecimal representation of values of column x.

SELECT *, TO_HEX(x) AS TO_HEX_Value FROM Sample;

This will produce the result as shown below:

DataxTO_HEX_Value
Data 110a
Data 22014
Data 3301e
Data 44028
Data 55032

❮ PostgreSQL Functions