简体   繁体   中英

IBM DB2 store the query results in a variable

I am trying to write a function and I need to store some table in a variable. I don't have the type 'Table' I tried to write something like this:

declare t table(a integer, b integer);
set t = (select A, B from MyTable);

It does not work.It says there is a syntax error and that there is no table type. What is the solution? Is there any other way to store the query results in a variable?

Use declared temporary table :

DECLARE GLOBAL TEMPORARY TABLE session.table_name (a integer, b integer) AS 
(select A, B from MyTable) WITH DATA

The declared temporary table description does not appear in the system catalog. It is not persistent and cannot be shared with other sessions. Each session that defines a declared global temporary table of the same name has its own unique description of the temporary table. When the session terminates, the rows of the table are deleted, and the description of the temporary table is dropped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM