1 Star 0 Fork 20

邓德城/MYSQL常用内置函数

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
吕宇鹏.sql 2.08 KB
一键复制 编辑 原始数据 按行查看 历史
吕宇鹏 提交于 2021-09-02 12:37 . 1
/*
Navicat MySQL Data Transfer
Source Server : wps
Source Server Version : 50730
Source Host : 127.0.0.1:3306
Source Database : nice
Target Server Type : MYSQL
Target Server Version : 50730
File Encoding : 65001
Date: 2021-09-02 17:19:58
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for b
-- ----------------------------
DROP TABLE IF EXISTS `b`;
CREATE TABLE `b` (
`name` varchar(255) DEFAULT NULL,
`age` varchar(255) DEFAULT NULL,
`phone` int(11) DEFAULT NULL,
`address` varchar(255) DEFAULT NULL,
`zhuangtai` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of b
-- ----------------------------
INSERT INTO `b` VALUES ('大牛', '17', '12312314', '岛国天安门', null);
INSERT INTO `b` VALUES ('小牛', '18', '12312415', '岛国南天门', null);
INSERT INTO `b` VALUES ('铁牛', '22', '12315464', '岛国下水道', null);
-- 字节长度
select name,LENGTH(name) from b;
select CHAR_LENGTH('1234a中国');
-- 替换
select replace('123123',2,'abc');
select insert('123412',2,3,'ab');
-- 截取
select left('123123',3);
select right('123113',2);
select SUBSTRING('12312312',3,2);
select SUBSTRING('1123123',-5,2);
-- 拼接
select concat('a','b','123');
-- 逆序
select REVERSE('1234');
-- 大小写转换
select UPPER('ab');
select LOWER('AB');
-- 去空格
-- 头尾
select TRIM(' 12 3 ')
-- 左边
select LTRIM(' 123 ')
-- 右边
select RTRIM(' 12 3 ')
-- 替换去除
select REPLACE(' 12 3 ',' ','');
-- 时间
select NOW();
-- 流程控制
-- IF
select*,if(age>=18,'成年','未成年')是否成年 from b;
select*,(
case
when age>=18 then
'成年'
else
'未成年'
END
)是否成年
from b;
-- 多重选项
select*,(
case age
when 17 then
'能办身份证'
when 18 then
'起飞了'
when 22 then
'结婚喽'
else
'我不懂'
END
)年龄状态
from b;
-- 替换空值
select*,IFNULL(zhuangtai,0)状态 from b;
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/deng-decheng/mysql_lesson3.git
git@gitee.com:deng-decheng/mysql_lesson3.git
deng-decheng
mysql_lesson3
MYSQL常用内置函数
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385