DB2存储过程3种赋值,字符串语句执行简单实例
SET SCHEMA = 'DB2ADMIN'; SET CURRENT PATH =
\DMIN\
CREATE PROCEDURE \ALUE\ DYNAMIC RESULT SETS 1 LANGUAGE SQL NOT DETERMINISTIC EXTERNAL ACTION MODIFIES SQL DATA OLD SAVEPOINT LEVEL BEGIN
DECLARE A,B,C VARCHAR(10); DECLARE C_SQL VARCHAR(1024);
DECLARE STMT STATEMENT; --存放过程定义 DECLARE CU1 CURSOR WITH RETURN FOR STMT; --提交游标定义 --定义临时表
DECLARE GLOBAL TEMPORARY TABLE SESSION.TMP_HY(
DM VARCHAR(10), MC VARCHAR(10) )
WITH REPLACE NOT LOGGED; --赋值3种方式 SET A='01';
VALUES '02' INTO B;
SELECT '03' INTO C FROM USER;
INSERT INTO SESSION.TMP_HY VALUES('1',A); INSERT INTO SESSION.TMP_HY VALUES('2',B); INSERT INTO SESSION.TMP_HY VALUES('3',C);
--字符串语句执行方式
SET C_SQL='update SESSION.TMP_HY set dm=''001'' '; PREPARE Stmtdg1 FROM C_SQL;--prepare EXECUTE Stmtdg1;
--字符串语句打开游标
SET C_SQL='select * from SESSION.TMP_HY'; PREPARE STMT FROM C_SQL;
open CU1; END;