📣
TiDB Cloud Premium 开放公测中。为企业级工作负载提供无限扩展、即时弹性伸缩和高级安全保障。此页面由 AI 自动翻译,英文原文请见此处。

INSERT



返回字符串 str,其中从位置 pos 开始、长度为 len 的子字符串被字符串 newstr 替换。如果 pos 不在字符串长度范围内,则返回原始字符串。如果 len 不在剩余字符串的长度范围内,则从位置 pos 开始替换该位置之后的其余字符串。如果任一参数为 NULL,则返回 NULL。

语法

INSERT(<str>, <pos>, <len>, <newstr>)

参数

参数描述
<str>字符串。
<pos>位置。
<len>长度。
<newstr>新字符串。

返回类型

VARCHAR

示例

SELECT INSERT('Quadratic', 3, 4, 'What'); +-----------------------------------+ | INSERT('Quadratic', 3, 4, 'What') | +-----------------------------------+ | QuWhattic | +-----------------------------------+ SELECT INSERT('Quadratic', -1, 4, 'What'); +---------------------------------------+ | INSERT('Quadratic', (- 1), 4, 'What') | +---------------------------------------+ | Quadratic | +---------------------------------------+ SELECT INSERT('Quadratic', 3, 100, 'What'); +-------------------------------------+ | INSERT('Quadratic', 3, 100, 'What') | +-------------------------------------+ | QuWhat | +-------------------------------------+ +--------------------------------------------+--------+ | INSERT('123456789', number, number, 'aaa') | number | +--------------------------------------------+--------+ | 123456789 | 0 | | aaa23456789 | 1 | | 1aaa456789 | 2 | | 12aaa6789 | 3 | | 123aaa89 | 4 | | 1234aaa | 5 | | 12345aaa | 6 | | 123456aaa | 7 | | 1234567aaa | 8 | | 12345678aaa | 9 | | 123456789 | 10 | | 123456789 | 11 | | 123456789 | 12 | +--------------------------------------------+--------+

文档内容是否有帮助?