我需要在 @,即''。然后,我需要制作第一个符号鞋面 - 'Marie.sue'。 initcap做到了这一点:“玛丽·索”。我该如何实现?
I need to exchage a part of email before @, i.e. 'MARIE.SUE' from '[email protected]'. Then i need to make first symbol UPPER - 'Marie.sue'. Initcap makes this: 'Marie.Sue'. How can i achieve this?
使用 split_part 和 initcap
split_part
initcap
SELECT INITCAP(split_part('[email protected] ','@',1))||'@' || split_part(' | ?柱子? | | :-------------------------- | |
SELECT INITCAP(split_part('[email protected] ','@',1))||'@' || split_part('
| ?柱子? | | :-------------------------- | |
选择initcap(split_part(' | ?柱子? | | :-------------------------- | | Email 
选择initcap(split_part('
| ?柱子? | | :-------------------------- | | Email 
db<>>
With split_part and INITCAP
INITCAP
SELECT INITCAP(split_part('[email protected]','@',1)) ||'@' || split_part('[email protected]','@',2) | ?column? | | :-------------------- | | [email protected] |
SELECT INITCAP(split_part('[email protected]','@',1)) ||'@' || split_part('[email protected]','@',2)
| ?column? | | :-------------------- | | [email protected] |
SELECT INITCAP(split_part('[email protected],uk','@',1)) ||'@' || split_part('[email protected]','@',2) | ?column? | | :--------------------- | | [email protected] |
SELECT INITCAP(split_part('[email protected],uk','@',1)) ||'@' || split_part('[email protected]','@',2)
| ?column? | | :--------------------- | | [email protected] |
db<>fiddle here
使用PostgreSQL 9.6(或更高)尝试使用 REGEXP_SPLIT_TO_ARRAY(),因为支持了积极的lookBehind:
REGEXP_SPLIT_TO_ARRAY()
WITH S AS (SELECT REGEXP_SPLIT_TO_ARRAY('[email protected]', '(?<=^.|@)') AS ARR) SELECT CONCAT(UPPER(ARR[1]),LOWER(ARR[2]),ARR[3]) FROM S
请参阅在线 demo 。
这将是:
模式(?字面的“@”。
(?字面的“@”。
注意:,如果您不希望从'@' - 开始的子字符串,请尝试:
WITH S AS (SELECT REGEXP_SPLIT_TO_ARRAY('[email protected]', '(?<=^.)|@.*') AS ARR) SELECT CONCAT(UPPER(ARR[1]),LOWER(ARR[2])) FROM S
或,不 REGEX():
REGEX()
WITH S AS (SELECT LOWER(SPLIT_PART('[email protected]', '@', 1)) AS X) SELECT UPPER(LEFT(X,1))||SUBSTRING(X,2) FROM S
请参阅在线 demo
With PostgreSQL 9.6 (or above) try to utilize REGEXP_SPLIT_TO_ARRAY() since a positive lookbehind is supported:
REGEXP_SPLIT_TO_ARRAY()
See an online demo.
This would:
The pattern (?<=^.|@) means to match any position preceded by the start of the string and any character or by an literal '@'.
(?<=^.|@)
Note: In case you don't want the substring from '@'-onwards, try:
Or, without REGEX():
REGEX()
See an online demo
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(2)
使用
split_part
和initcap
db&lt;&gt;&gt;
With
split_part
andINITCAP
db<>fiddle here
使用PostgreSQL 9.6(或更高)尝试使用
REGEXP_SPLIT_TO_ARRAY()
,因为支持了积极的lookBehind:请参阅在线 demo 。
这将是:
模式
(?字面的“@”。
注意:,如果您不希望从'@' - 开始的子字符串,请尝试:
或,不
REGEX()
:请参阅在线 demo
With PostgreSQL 9.6 (or above) try to utilize
REGEXP_SPLIT_TO_ARRAY()
since a positive lookbehind is supported:See an online demo.
This would:
The pattern
(?<=^.|@)
means to match any position preceded by the start of the string and any character or by an literal '@'.Note: In case you don't want the substring from '@'-onwards, try:
Or, without
REGEX()
:See an online demo