SQL在某个字符之后选择所有内容

时间:2022-03-26 09:27:22

I need to extract everything after the last '=' (http://www.domain.com?query=blablabla - > blablabla) but this query returns the entire strings. Where did I go wrong in here:

我需要在最后一个“=”之后提取所有东西(http://www.domain.com/)。但是这个查询返回整个字符串。我在这里哪里做错了:

SELECT RIGHT(supplier_reference, CHAR_LENGTH(supplier_reference) - SUBSTRING('=', supplier_reference)) 
FROM ps_product

5 个解决方案

#1


38  

select SUBSTRING_INDEX(supplier_reference,'=',-1) from ps_product;

Please use http://www.w3resource.com/mysql/string-functions/mysql-substring_index-function.php for further reference.

请使用http://www.w3resource.com/mysql/string-functions/mysql-substring_index-function.php进一步参考。

#2


7  

Try this (it should work if there are multiple '=' characters in the string):

试试这个(如果字符串中有多个'='字符,应该可以):

SELECT RIGHT(supplier_reference, (CHARINDEX('=',REVERSE(supplier_reference),0))-1) FROM ps_product

#3


4  

Try this in MySQL.

在MySQL试试这个。

right(field,((CHAR_LENGTH(field))-(InStr(field,','))))

#4


1  

In MySQL, this works if there are multiple '=' characters in the string

在MySQL中,如果字符串中有多个'='字符,则此操作有效

SUBSTRING(supplier_reference FROM (LOCATE('=',supplier_reference)+1))

It return the substring after(+1) having found the the first =

它在(+1)找到第一个=后返回子字符串

#5


0  

For SQL Management studio I used a variation of BWS' answer. This gets the data to the right of '=', or NULL if the symbol doesn't exist:

对于SQL Management studio,我使用了不同的BWS答案。如果该符号不存在,则将数据获取到“=”或NULL的右边:

   CASE WHEN (RIGHT(supplier_reference, CASE WHEN (CHARINDEX('=',supplier_reference,0)) = 0 THEN
    0 ELSE CHARINDEX('=', supplier_reference) -1 END)) <> '' THEN (RIGHT(supplier_reference, CASE WHEN (CHARINDEX('=',supplier_reference,0)) = 0 THEN
    0 ELSE CHARINDEX('=', supplier_reference) -1 END)) ELSE NULL END

#1


38  

select SUBSTRING_INDEX(supplier_reference,'=',-1) from ps_product;

Please use http://www.w3resource.com/mysql/string-functions/mysql-substring_index-function.php for further reference.

请使用http://www.w3resource.com/mysql/string-functions/mysql-substring_index-function.php进一步参考。

#2


7  

Try this (it should work if there are multiple '=' characters in the string):

试试这个(如果字符串中有多个'='字符,应该可以):

SELECT RIGHT(supplier_reference, (CHARINDEX('=',REVERSE(supplier_reference),0))-1) FROM ps_product

#3


4  

Try this in MySQL.

在MySQL试试这个。

right(field,((CHAR_LENGTH(field))-(InStr(field,','))))

#4


1  

In MySQL, this works if there are multiple '=' characters in the string

在MySQL中,如果字符串中有多个'='字符,则此操作有效

SUBSTRING(supplier_reference FROM (LOCATE('=',supplier_reference)+1))

It return the substring after(+1) having found the the first =

它在(+1)找到第一个=后返回子字符串

#5


0  

For SQL Management studio I used a variation of BWS' answer. This gets the data to the right of '=', or NULL if the symbol doesn't exist:

对于SQL Management studio,我使用了不同的BWS答案。如果该符号不存在,则将数据获取到“=”或NULL的右边:

   CASE WHEN (RIGHT(supplier_reference, CASE WHEN (CHARINDEX('=',supplier_reference,0)) = 0 THEN
    0 ELSE CHARINDEX('=', supplier_reference) -1 END)) <> '' THEN (RIGHT(supplier_reference, CASE WHEN (CHARINDEX('=',supplier_reference,0)) = 0 THEN
    0 ELSE CHARINDEX('=', supplier_reference) -1 END)) ELSE NULL END