PostgreSQL pg中的截取补齐lpad函数怎么用?
1 左边填充,右边截取
PostgreSQL中的lpad()
函数有两个功能:
- 如果长度不够指定的长度,就在左边填充字符串
- 如果长度超出了指定的长度,就把右边截掉。
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