SQL Temporary Table Issue

南楼画角 提交于 2020-12-13 13:09:48

问题


I've created a temporary table DETAILS and follow the same syntax of creating and inserting in it. But I have not received any result set However, the CREATE and INSERT statements ran successfully and the Row was also affected in the INSERT statement . But the result set was empty when I ran the last SELECT statement to view the record .

DROP TABLE DETAILS ;
CREATE GLOBAL TEMPORARY TABLE DETAILS AS (
SELECT ins_id , firstname , pages FROM 
INSTRUCTOR)DEFINITION ONLY;

INSERT INTO DETAILS
SELECT ins_id , firstname , pages 
FROM INSTRUCTOR WHERE ins_id = '1';

SELECT * FROM DETAILS ;

回答1:


If you want to preserve rows in CGTT after commit, you have to specify ON COMMIT PRESERVE ROWS option of the CREATE GLOBAL TEMPORARY TABLE statement.
ON COMMIT DELETE ROWS option is in effect otherwise, and such a table is cleared on commit.



来源:https://stackoverflow.com/questions/62209833/sql-temporary-table-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!