postgresql 截取函数
PostgreSQL 提供了多种截取函数用于截取字符串,包括:
- substring(string from start for length)
该函数从字符串的开始位置 start 处截取长度为 length 的子串。
例如:
SELECT substring('hello world' from 2 for 5); -- 输出 "ello "
- substring(string from start)
该函数从字符串的开始位置 start 处截取到字符串末尾。
例如:
SELECT substring('hello world' from 2); -- 输出 "ello world"
- left(string, length)
该函数从字符串的开始位置截取长度为 length 的子串。
例如:
SELECT left('hello world', 5); -- 输出 "hello"
- right(string, length)
该函数从字符串的末尾位置截取长度为 length 的子串。
例如:
SELECT right('hello world', 5); -- 输出 "world"
- trim(string)
该函数删除字符串首尾的空格。
例如:
SELECT trim(' hello world '); -- 输出 "hello world"
- ltrim(string)
该函数删除字符串开头的空格。
例如:
SELECT ltrim(' hello world '); -- 输出 "hello world "
- rtrim(string)
该函数删除字符串末尾的空格。
例如:
SELECT rtrim(' hello world '); -- 输出 " hello world"
原文地址: https://www.cveoy.top/t/topic/yz7 著作权归作者所有。请勿转载和采集!