1 Star 0 Fork 23

张福川/MYSQL常用内置函数

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
9.2.txt 1.06 KB
Copy Edit Raw Blame History
方桂龙 authored 2021-09-06 10:10 +08:00 . 方桂龙
create database shop
use shop;
drop table if EXISTS `user`;
create table user (
name varchar(20),
moneny FLOAT
)
-- 字节长度
SELECT name,length(name) from user;
select length('123ab中国c'),OCTET_LENGTH('123ab中国c');
select CHAR_LENGTH('123ab中国c');
-- 替换
select replace('1234526','2','ABC');
select insert ('1234526',2,3,'ABC');
-- 截取
select left('123456789','3');
select right('123456789','3');
select substring('123456789',-5,3);
-- 拼接
select concat('abc','efg','123');
-- 逆序
select reverse('123456789');
-- 大小写转换
select upper('中国abc123');
select lower('中国ABC132');
-- 去空格
select trim(' 123 '); -- 两边都没有空格
select ltrim('123 '); -- 左边没有空格
select rtrim(' 123'); -- 右边没有空格
select replace(' 12 3 ',' ',''); -- 替换掉空格
-- 时间函数
selec now();
select unix_timestamp(now());
select from_unixtime(123456);
-- 流程控制
select *,if (money>=0,'正常','异常')资金状态 from user;
select *,(
case
when money>=0
then '正常'
else '异常'
end
)资金状态 from user;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangfuchuang/mysql_lesson3.git
git@gitee.com:zhangfuchuang/mysql_lesson3.git
zhangfuchuang
mysql_lesson3
MYSQL常用内置函数
master

Search