PostgreSQL pg中的截取补齐lpad函数怎么用?

PostgreSQL pg中的截取补齐lpad函数怎么用?

1 左边填充,右边截取

PostgreSQL中的lpad()函数有两个功能:

  1. 如果长度不够指定的长度,就在左边填充字符串
  2. 如果长度超出了指定的长度,就把右边截掉。

The PostgreSQL lpad() function is used to fill up a string of specific length by a substring. If the length of the substring is equal to the remaining length of main string it will fill up properly, if less than the remaining length, the substring will repeat until it is not filling up, if longer than the remaining length or specified length it will be truncated on the right.

语法格式为

lpad(string,length[,fill_text])

2 图解lpad函数

在这里插入图片描述

3 举几个例子

SELECT lpad('esource', 10, 'w3r');
--  w3resource
SELECT lpad('esource', 13, 'w3r');
--  w3rw3resource
SELECT lpad('w3resource', 8, 'lpad');
--  w3resour

文章参考

PostgreSQL LPAD() function

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值