一 简介
嵌入式SQL:与主语言通信,比如:Java,C++
过程化SQL块主要有两种类型:匿名块和命名块。匿名块每次执行时都要进行编译,不能存储到数据库中,也不能在其他过程化SQL块中调用。过程和函数都是命名块,被编译后保存到数据库中,称为持久性存储模块,可以被反复调用,运行速度较快。
TSQL
PLSQL
MYSQL
二 存储过程
创建
create procedure a
as <过程化SQL块>
修改
alter
删除
drop
三 函数
函数的定义和存储过程也类似,不同之处是函数必须指定返回类型
create function a() returns类型
as <过程化SQL块>
call/select a(参数)
例子:
create function nextval(business_type varchar(32))
returns int
BEGIN
declare current int default 0;
select t.code into current from code_sequence t where business_type = business_type limit 1 for update;
update code_sequence t set t.code = t.code + 1 ;
set current = current + 1;
return current;
end;