1.常量
例1:输出字符串‘张三’、单引号、双引号、换行符、反斜杠、数字5689、当前时间;
select '张三'; select '\''; select '\"'; select '\\'; select '\n'; select '5689'; select Now();
2.变量(转自:http://c.biancheng.net/view/7840.html)
(1)定义用户变量
set @变量名=值
set @x=10; select @x;
同时定义多个变量并赋值
set @x=10,@y=15,@z='mary'; select @x,@y,@z;
例2:查询student表中姓名为“张三”的学生年龄并存储在变量age中。
set @age=(select stuAge from student where stuName='张三'); select @age;
例3:查询student表中年龄等于例2中变量age值的同学信息。
select * from student where stuAge=@age;
(2)系统变量
系统变量是MySQL的一些特定设置,在MySQL服务器启动时就被引入并初始化为默认值。
例4:获得当前MySQL的版本号、系统时间。
select @@version; select CURRENT_DATE;
4.内置函数(转自:https://blog.csdn.net/qq_45967533/article/details/126310993)
(1)日期函数
例5:使用日期函数获得当前的时间。
select current_time() as 时间;
(2)字符串函数
例6:获取student表中‘stuName’列的字符集及占用的字节数。
select charset(stuName) from student; select length(stuName) from student;
(3)数学函数
(4)控制流函数(转自:https://blog.csdn.net/weixin_62427168/article/details/125547991)
(5)加密与解密函数
(6)MySQL信息函数
(7)其他函数
参考文章:
https://blog.csdn.net/weixin_62427168/article/details/125547991
https://blog.csdn.net/qq_45967533/article/details/126310993