1.查看MySQL内置函数
select now();
2.查看存储过程变量
select @a;
- mysql > SELECT 'Hello World' into @x;
- mysql > SELECT @x;
- +-------------+
- | @x |
- +-------------+
- | Hello World |
- +-------------+
- mysql > SET @y='Goodbye Cruel World';
- mysql > SELECT @y;
- +---------------------+
- | @y |
- +---------------------+
- | Goodbye Cruel World |
- +---------------------+
- mysql > SET @z=1+2+3;
- mysql > SELECT @z;
- +------+
- | @z |
- +------+
- | 6 |
- +------+
注意 :
① 用户变量名一般以 @ 开头
② 滥用用户变量会导致程序难以理解及管理
2.添加标识字段和初值
select 1 flag;
3.通过动态标识来选择
select * from user where true; 返回所有
select * from user where false; 返回空
实战 根据用户是否有所有project权限来取出所有project
select * from project where (select is_all_project from user where use_id =13)