lightdb 的 nvl 函数支持 nvl(null::number, ‘0‘)

lightdb 的 nvl 函数支持 nvl(null::number,‘0’)

背景

在业务产品中,存在 oracle 移植过来的 sql 语句。它们使用 nvl(null::number,‘0’)。lightdb 23.4 版本 oracle 模式对此进行了支持。

lightdb 关于 nvl(null::number,‘0’)

lightdb 23.4 版本之前 nvl(null::number, # ) 参数 # 仅支持数字类型,使用其它类型时将会报错。

lightdb 23.4 版本之后 nvl(null::number, # ) 扩充了使用场景。在 oracle 模式函数 nvl 中参数 # 支持使用任意类型。如果可以正常转换成数字类型将不会报错。

nvl(null::数值类型, unknown) 示例
SELECT nvl(null::numeric, '-025');
 nvl 
-----
 -25
(1 row)

SELECT nvl(null::integer, ' +023');
 nvl 
-----
  23
(1 row)

SELECT nvl(null:: double precision, ' .011');
  nvl  
-------
 0.011
(1 row)
nvl(null::数值类型, varchar) 示例
-- CREATE TABLE
CREATE TABLE stadium (
    id INT PRIMARY KEY,
    name VARCHAR(255),
    capacity INTEGER,
    location VARCHAR(255),
    mark VARCHAR(255),
    construct_year INTEGER
);


-- INSERT INTO
INSERT INTO stadium (id, name, capacity, location, mark, construct_year)
VALUES (1, 'huaicheng', 50000, '39.123, 33.234', '0.', 2000);
INSERT INTO stadium (id, name, capacity, location, mark, construct_year)
VALUES (2, 'huaicheng', 60000, '39.123, 33.234', '.0', 2005);
INSERT INTO stadium (id, name, capacity, location, mark, construct_year)
VALUES (3, 'huaicheng', 70000, '39.123, 33.234', '+1', 2010);
INSERT INTO stadium (id, name, capacity, location, mark, construct_year)
VALUES (4, 'huaicheng', 80000, '39.123, 33.234', '-1', 2015);
INSERT INTO stadium (id, name, capacity, location, mark, construct_year)
VALUES (5, 'huaicheng', 90000, '39.123, 33.234', '0', 2020);
INSERT INTO stadium (id, name, capacity, location, mark, construct_year)
VALUES (6, 'huaicheng', 40000, '39.123, 33.234', '1', 2020);


-- TEST SELECT VARCHAR
SELECT nvl(null::numeric, mark) FROM stadium;
 nvl 
-----
   0
 0.0
   1
  -1
   0
   1
(6 rows)

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值