所以我的回答是这样的。“恭喜!您在***.”*中赢得了松下音响系统。我们的呼叫中心将在*上与您联系。我需要的是只选择奖(在这种情况下松下音响系统“)作为输出。不同的奖项的字符不同。其他有许多字符,只有10个字符。我需要运行一个select语句,删除两个领先的”恭喜!你在**中赢得了“和尾随”。我们的呼叫中心将通过****.“与您联系。因此,还奖;让我们调用我的表条目,我的字段,其中有这个文本,我们称之为响应;我已经跑了SELECT SUBSTR(response,32) from entries; and I remove the leading characters before the prize.
当我运行这个,我得到“松下声音系统在****.";*。我们的呼叫中心会联系您在*。”
引线的字符长度为32,尾数为94。奖品不是固定不变的。
发布于 2012-08-23 09:32:43
在这里,索引可能很有用:
select
substring_index(
substring_index(
"Congratulations! You have won a Panasonic Sound System in the *. Our call centre will contact you on ***."," a ",-1)," in the ",1);发布于 2012-08-23 09:53:51
如果您确信尾随字符数和前导字符计数总是恒定的,则可以使用亚斯特尔氏用例:SUBSTR(str,pos,len).。
len可以通过从原始字符串的长度减去前导不想要的字符和跟踪不想要的字符来确定。
set @test_string = "Congratulations! You have won a Panasonic Sound System in the ************************. Our call centre will contact you on *************************";
set @leading = 32;
set @trailing = 94;
select substr(@test_string, @leading, length(@test_string) - @leading - @trailing);例:
mysql> select substr(@test_string, @trailing_chars, length(@test_string) - @leading_chars - @trailing_chars);
+------------------------------------------------------------------------------------------------+
| substr(@test_string, @trailing_chars, length(@test_string) - @leading_chars - @trailing_chars) |
+------------------------------------------------------------------------------------------------+
| Panasonic Sound System |
+------------------------------------------------------------------------------------------------+https://stackoverflow.com/questions/12088545
复制相似问题