相关疑难解决方法(0)

首次出现字符后剪切字符串

我有像'keepme:cutme'或'string-without-separator'这样的字符串,它们应分别成为'keepme'和'string-without-separator'.这可以在PostgreSQL中完成吗?我试过了:

select substring('first:last' from '.+:')
Run Code Online (Sandbox Code Playgroud)

:如果:字符串中没有,则会离开,并且将无法工作.

sql string postgresql pattern-matching delimiter

7
推荐指数
1
解决办法
9663
查看次数

在第一个反斜杠后删除所有内容

如果我有一个字符串,如:

one\two\three\four\five\six\
two\three\four\five\six\one\
three\four\five\six\one\two\
four
five\six
Run Code Online (Sandbox Code Playgroud)

我该如何修剪它以便我最终得到它

one
two
three
four
five
Run Code Online (Sandbox Code Playgroud)

我试过了

LEFT(column_name_goes_here, CHARINDEX('\', column_name_goes_here) - 1)
Run Code Online (Sandbox Code Playgroud)

根据SQL Server替换的答案,删除所有特定字符后的所有内容

但它给了我以下错误消息:

Msg 537, Level 16, State 3, Procedure stored_procedure_one, Line 107
Invalid length parameter passed to the LEFT or SUBSTRING function.
Run Code Online (Sandbox Code Playgroud)

sql t-sql sql-server sql-server-2012

1
推荐指数
1
解决办法
176
查看次数