db2存储过程相信大家都比较了解了,下面就为您介绍一些db2存储过程常用语句,如果您对此方面感兴趣的话,不妨一看。
----定义
DECLARE CC VARCHAR(4000);
DECLARE SQLSTR VARCHAR(4000);
DECLARE st STATEMENT;
DECLARE CUR CURSOR WITH RETURN TO CLIENT FOR CC;
----执行动态SQL不返回
PREPARE st FROM SQLSTR;
EXECUTE st;
----执行动态SQL返回
PREPARE CC FROM SQLSTR;
OPEN CUR;
----判断是否为空,使用值替代
COALESCE(判断对象,替代值)
----定义临时表
DECLARE GLOBAL TEMPORARY TABLE SESSION.TempResultTable
(
Organization int,
OrganizationName varchar(100),
AnimalTypeName varchar(20),
ProcessType int,
OperatorName varchar(100),
OperateCount int
)
WITH REPLACE -- 如果存在此临时表,则替换
NOT LOGGED;
----字符串函数
Substr
----隐形游标迭代
for 游标名 as select....... do
使用 游标名.字段名
内容区块
end for;
----直接返回值或变量
declare rs1 cursor with return to caller for select 0 from sysibm.sysdummy1;
----判断表是否存在
select count(*) into @exists from syscat.tables where tabschema = current schema and tabname='ZY_PROCESSLOG';
----取前面N条记录
FETCH FIRST N ROWS ONLY
----定义返回值
declare rs0 cursor with return to caller for select 0 from sysibm.sysdummy1;
declare rs1 cursor with return to caller for select 1 from sysibm.sysdummy1;
----得到插入的自增长列最大值
VALUES IDENTITY_VAL_LOCAL() INTO 变量