我以前用过这个...
UPDATE whatever_table SET whatever_col = SUBSTRING(MD5(RAND()) FROM 1 FOR 12)
... 将随机字符串添加到 mysql 表。
现在,类似地,我希望向表中的所有记录添加一个字母数字“PIN”(永远只有几百条记录。)“PIN”应该是字母数字,但应该排除“1”、“0'、'O'、'l' 等
谁能告诉我如何更新上面的查询以排除这些不明确的字符?
TIA
最佳答案
除了 N.B. 的评论,逻辑在 PL/SQL 中是有意义的,但在 (My)SQL 中却不是。
REPLACE(str,from_str,to_str)
Returns the string str with all occurrences of the string from_str replaced by the string to_str.
REPLACE()
performs a case-sensitive match when searching for from_str.
mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww');
-> 'WwWwWw.mysql.com'
This function is multi-byte safe.
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace
关于mysql 用字母数字 'PIN' 更新记录,不包括不明确的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18847805/