使用到的函數
- CONCAT(str1,str2):字符連接函數
- UPPER(str):將字符串改為大寫字母
- LOWER(str):將字符串改為小寫字母
- LENGTH(str):判定字符串長度
- SUBSTRING(str,a,b):提取字段中的一段,從字符串str的第a位開始提取,提取b個字符
- LEFT(str,n):提取字符串最左邊的n個字符
- RIGHT(str,n):提取字符串最右邊的n個字符(該例未用到)
分別舉例如下:
添加前綴:
update `ecs_goods` set goods_name=concat('新中式',goods_name) where cat_id =4;
添加后綴:
update `ecs_goods` set goods_name=concat(goods_name,'新中式') where cat_id =4;
去掉首字母
update `ecs_goods`set goods_name=right(goods_name,length(goods_name)-1) where cat_id =4;
替換 update 表名 set 字段名=REPLACE (字段名,'原來的值','要修改的值')
生成刪除表的語句
SELECT CONCAT('delete from ',TABLE_NAME,';') AS a FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '數據庫名' ;