简体   繁体   中英

Remove part of string in table

I have a table where one field named "version" contains the string "MyProgram nnnnnn". I now wish to replace these strings so that they are only "nnnnnn", thereby remove the prepending "MyProgram ".

Is this possible, and if so, how would I do this?

If the pattern is "MyProgram nnnnnn" maning string like VB 1.3, Mysql 5.6, PHP 5.4 etc then you can do the following

update tablename 
set col = substring_index(col,' ',-1)

Use Replace function,

SELECT VERSION,  
REPLACE(VERSION,'MyProgram nnnnnn','nnnnnn')   
FROM FROM tablename 

您可以对MySQL使用Replace()函数

update table set columnname = REPLACE(columnname, 'MyProgram ', '');

Check this Manual

SELECT REPLACE(VERSION, 'MyProgram ', '')
FROM tablename

You want:

I now wish to replace these strings so that they are only "nnnnnn"

Shortest solution:

SELECT 'nnnnnn'


Specify your pattern of the content of this column!

SELECT VERSION,
REPLACE(VERSION,'MyProgram nnnnnn','nnnnnn')
FROM FROM tablename

Regards, Praveen Nelge

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM