[英]Delete on of the id in mysql varchar
I cannot find the way how i can delete one of the stored ids in varchar column. 我找不到删除varchar列中存储的ID之一的方法。
id fieldid
1 ,5,13,15,66,443,
how i can delete, lets say 15 from this field id? 我该如何删除,可以说这个字段ID为15?
The correct logic is: 正确的逻辑是:
UPDATE <your_table_name>
SET fieldid = REPLACE(fieldid, ',15,', ',')
---------------------------------------^----^ these commas a really important
WHERE id = 1;
However, storing list of numbers of strings is bad, bad, bad in SQL: 但是,在SQL中存储字符串数列表是不好的,不好的,不好的:
Sometimes, you are stuck with someone else's really, really, really bad design decisions. 有时,您会陷入别人的非常非常糟糕的设计决策中。
You gave give REPLACE
a shot though 您虽然给了REPLACE
一个机会
DECLARE @Test VARCHAR(50)
SET @Test = ',5,13,15,66,443,'
SELECT REPLACE(@Test,'15,','')
,5,13,66,443,
Check with ORACLE 用ORACLE检查
UPDATE <your_table_name>
SET fieldid = REPLACE(fieldid,',15','')
WHERE id = 1;
This will replace ',15' with empty string. 这将用空字符串替换',15'。 Like remove from string. 就像从字符串中删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.