【问题标题】:Is there a function to replace part of string?是否有替换部分字符串的功能?
【发布时间】:2018-12-24 12:45:57
【问题描述】:
  • 我有一个列 Line_num

行号

06-ZB-A23-475004-SHT1

10-ZB-A23-4750041-SHT2

2.5-ZB-A23-4750-SHT3

06-ZB-A23-475004-5H6-SHT13

  • 我想要的结果是

行号

06-ZB-A23-475004

10-ZB-A23-4750041

2.5-ZB-A23-4750

06-ZB-A23-475004-5H6

我使用了下面的代码

更新文件名 SET line_num = REPLACE(line_num, '-SHT*', '') WHERE line_num like '%-SHT%';

但它不起作用。谁能帮我解决这个问题。

更新文件名 SET line_num = REPLACE(line_num, '-SHT*', '') WHERE line_num like '%-SHT%';

【问题讨论】:

  • * in replace 只是表示替换 * 而不是 T 之后的所有字符。您应该使用正则表达式。也许这篇文章可以帮助你:stackoverflow.com/questions/38877856/…。看来其实没有别的办法了。

标签: sqlite


【解决方案1】:

试试下面的查询

UPDATE Filename SET line_num = substr(line_num, 1, instr(line_num, '-SHT')-1) WHERE line_num like '%-SHT%';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-27
    • 2012-07-17
    • 1970-01-01
    • 2011-11-23
    • 2013-06-19
    • 2021-03-25
    相关资源
    最近更新 更多