Remove part of string in table

2019-08-29 10:32发布

问题:

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?

回答1:

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)


回答2:

Use Replace function,

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


回答3:

Check this Manual

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


回答4:

You can use the Replace() function for MySQL

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


回答5:

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!



回答6:

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

Regards, Praveen Nelge