1、运算符
算数运算符 + - * / %
赋值运算符 = += -= *= /=
条件运算符 == != > < >= <=
位、逻辑运算符 与& 或| 非~
流程控制
if 条件 then
SQL语句
else
SQL语句
end if;
case 表达式
when 值1 then SQL 语句1
when 值2 then SQL 语句2
................................................
when 值n then SQL 语句n
else SQL 语句n+1
end case;
while 条件 do
SQL语句
end while;
repeat
SQL语句
until 条件
end repeat;
loop
SQL语句
end loop;
2、变量
用户变量 set @变量名 = 值;
系统变量 @@系统变量名 @@version @@date
局部变量 declare 变量名 数据类型 default 值;
3、创建存储过程
create procedure 存储过程名([in| out| inout] 变量名 数据类型)
begin
.......................
......................
end
4、调用存储过程
call 存储过程名();
5、修改SQL语句结束符
delimiter 结束符;
6、删除存储过程
drop procedure 存储过程名;
7、创建游标
declare 游标名 cursor for 查询语句;
8、打开游标
open 游标名;
关闭游标
close 游标名;
9、使用游标
fetch 游标名 into 变量名;
10、开启事务
start transaction;
11、结束事务
提交 commit;
取消 rollback;
12、设置事务隔离级别
set session transaction isolation level 隔离级别;
13、查询事务隔离级别
select @@transaction_isolation;
14、事务隔离级别
read uncommitted 读未提交(脏读)
read committed 读提交(不可重复读)
repeatable read 可重复读(幻读)
serializable 可串行化