达梦的存储过程中执行DDL语句需要用动态SQL
CREATE OR REPLACE PROCEDURE "TEST".proc_TempTable(UserID in varchar(50))
AS
--定义变量
sqlstr TEXT;
BEGIN
--达梦的存储过程中执行DDL语句需要用动态SQL
--创建临时表
execute IMMEDIATE '
CREATE GLOBAL TEMPORARY TABLE TempTable(
id int,
name varchar(100)
)ON COMMIT DELETE ROWS;';
--操作临时表
execute IMMEDIATE 'insert into TempTable(id, name) values(1, ''abc'');';
--查询临时表
set sqlstr = 'select * from TempTable;';
execute IMMEDIATE sqlstr;
--删除临时表
execute IMMEDIATE 'drop table TempTable;';
END;
执行存储过程: