Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing a specific char in a MySQL string

Tags:

mysql

I have a table with a series of permissions, and I need to change every user's permission to Y in a given position p in the string, is there a SQL command I can use or do I have to write a program/script to do it?

like image 778
Guido Avatar asked Mar 21 '12 22:03

Guido


People also ask

How do I replace a character in a string in SQL?

SQL Server REPLACE() Function The REPLACE() function replaces all occurrences of a substring within a string, with a new substring. Note: The search is case-insensitive.

How do I remove a specific character from a string in MySQL?

Remove characters from string using TRIM() TRIM() function is used to remove any character/ whitespace from the start/ end or both from a string.

How do I select a part of a string in MySQL?

SUBSTRING() : function in MySQL is used to derive substring from any given string . It extracts a string with a specified length, starting from a given location in an input string. The purpose of substring is to return a specific portion of the string.


1 Answers

You can use a combination of concat and substring in MySQL:

mysql> select concat(substring('12345',1,3),'A',substring('12345',5));
+---------------------------------------------------------+
| concat(substring('12345',1,3),'A',substring('12345',5)) |
+---------------------------------------------------------+
| 123A5                                                   |
+---------------------------------------------------------+

You can replace '12345' with the name of your column.

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html

like image 132
GoldenNewby Avatar answered Sep 29 '22 22:09

GoldenNewby