PostgreSQL的10进制与16进制互转
2024-10-21 09:53:33
1.10进制转16进制
Postgres里面有一个内置的10进制转16进制的函数:to_hex(int)/to_hex(bigint)
[postgres@localhost ~]$ psql
Password:
psql (9.1.3)
Type "help" for help.
postgres=# select to_hex(9);
to_hex
--------
9
(1 row)
postgres=# select to_hex(17);
to_hex
--------
11
(1 row)
postgres=# select to_hex(31);
to_hex
--------
1f
(1 row)
postgres=# select to_hex(255);
to_hex
--------
ff
(1 row)
postgres=# select to_hex(256);
to_hex
--------
100
(1 row)
2.16进制转10进制
没有内置的,参考网上的一个例子
postgres=# CREATE FUNCTION
hex_to_dec(in_hex TEXT)
RETURNS INT
IMMUTABLE STRICT LANGUAGE sql AS
$body$
SELECT CAST(CAST(('x' || CAST($1 AS text)) AS bit(8)) AS INT);
$body$;
CREATE FUNCTION
postgres=# select hex_to_dec('1f');
hex_to_dec
------------
31
(1 row)
postgres=# select hex_to_dec('ff');
hex_to_dec
------------
255
(1 row)
postgres=# select hex_to_dec('fe');
hex_to_dec
------------
254
(1 row)
postgres=# select hex_to_dec('09');
hex_to_dec
------------
9
(1 row)
postgres=# select hex_to_dec('11');
hex_to_dec
------------
17
(1 row)
最新文章
- css3 linear-gradient实现页面加载进度条效果
- PL/SQL 循环结构
- [BTS] BizTalk host BizTalkServerApplication throttled because DatabaseSize exceeded the configured throttling limit.
- Shopping(SPFA+DFS HDU3768)
- 2016年10月21日 星期五 --出埃及记 Exodus 19:5
- eclipse提交hadoop集群跑程序
- 十、装饰(Decorator)模式 --结构模式(Structural Pattern)
- http概览
- redux三个基本原则
- Haoop MapReduce 的Partition和reduce端的二次排序
- 在Kubernetes集群中使用calico做网络驱动的配置方法
- Python源码剖析之准备工作
- python 使用 PIL 和 matplotlib 获取图片像素点处理之后再写入
- 在香港用什么软件可以唱歌?香港K歌app推荐
- eclipse 假死
- Android 异步加载数据 AsyncTask异步更新界面
- 删除 AP 发票相关脚本
- rman 中遇到 ORA-01861
- 读《我是IT小小鸟》有感
- 【codeforces 528D】 Fuzzy Search