OVERLAY
适用于 ✅ 开源版 ✅ 专业版 ✅ 企业版
OVERLAY() 函数接受一个字符串,并“将其覆盖在另一个字符串之上”。
SELECT overlay('abcdefg', 'xxx', 2);
create.select(overlay(val("abcdefg"), "xxx", 2)).fetch();
结果是
+---------+ | overlay | +---------+ | axxxefg | +---------+
有关此函数的二进制版本,请参阅OVERLAY(二进制)。
方言支持
此示例使用 jOOQ
overlay(val("abcdefg"), "xxx", 2)
翻译成以下特定方言的表达式
访问
(mid(
'abcdefg',
1,
(2 - 1)
) & 'xxx' & mid(
'abcdefg',
(2 + len('xxx'))
))
ASE
(substring(
'abcdefg',
1,
(2 - 1)
) || 'xxx' || substring(
'abcdefg',
(2 + char_length('xxx')),
2147483647
))
Aurora MySQL, Exasol, H2, MariaDB, MySQL
insert(
'abcdefg',
2,
char_length('xxx'),
'xxx'
)
Aurora Postgres, CockroachDB, Databricks, Firebird, Postgres, Vertica, YugabyteDB
overlay('abcdefg' PLACING 'xxx' FROM 2)
BigQuery, HSQLDB, Redshift
(substring(
'abcdefg',
1,
(2 - 1)
) || 'xxx' || substring(
'abcdefg',
(2 + char_length('xxx'))
))
ClickHouse, DuckDB, Hana, Sybase, Trino
(substring(
'abcdefg',
1,
(2 - 1)
) || 'xxx' || substring(
'abcdefg',
(2 + length('xxx'))
))
DB2
overlay('abcdefg' PLACING 'xxx' FROM 2 FOR length('xxx'))
Derby, Oracle, SQLite
(substr(
'abcdefg',
1,
(2 - 1)
) || 'xxx' || substr(
'abcdefg',
(2 + length('xxx'))
))
Informix
(substr(
'abcdefg',
1,
(2 - 1)
) || 'xxx' || substr(
'abcdefg',
(2 + char_length('xxx'))
))
MemSQL
concat(
substring(
'abcdefg',
1,
(2 - 1)
),
'xxx',
substring(
'abcdefg',
(2 + char_length('xxx'))
)
)
Snowflake
insert(
'abcdefg',
2,
length('xxx'),
'xxx'
)
SQLDataWarehouse, SQLServer
(substring(
'abcdefg',
1,
(2 - 1)
) + 'xxx' + substring(
'abcdefg',
(2 + len('xxx')),
2147483647
))
Teradata
(substring('abcdefg' FROM 1 FOR (2 - 1)) || 'xxx' || substring('abcdefg' FROM (2 + length('xxx'))))
使用 jOOQ 3.21 生成。早期 jOOQ 版本的支持可能有所不同。 在我们的网站上翻译您自己的 SQL
反馈
您对此页面有任何反馈吗?我们很乐意听取您的意见!