在查询数据的时候可以使用函数对数据操作, 如
- 字符串函数
-- 查询英文名的前3个字符
select *, substring(uname_en, 1, 2) from cattle_user;
- 时间函数
select now(), sysdate();
- 流程函数
-- if 函数, 等于java中的if else
select *, if(market_value > 200, '高', '低') as '市值' from cattle_user;
• <img src="https://gitee.com/GreenLittleApple/MyImages/raw/master/img/20210805125023.png" style="zoom:50%;" />
-- nullif 函数, 如果value1等于value2, 返回null; 不等于, 返回1
select nullif(1, 2), nullif(1, 1) from dual;
-- case 函数, 替换原有数据中的值
select *,
case uid
when 1 then 'one'
when 2 then'two'
else 'other'
end '英文uid'
from cattle_user;
- 查看数据库函数
-- 查看当前使用数据库, 用户, 数据库版本
select database(), user(), version();