How to create a temporary table in Oracle?
To create a temporary Oracle table, you can use the following syntax:
Create a global temporary table with the specified columns and data types, and choose to either delete rows or preserve rows on commit.
The table name is the name of the temporary table, while the column name and data type refer to the columns and their corresponding data types in the table.
The ON COMMIT clause is used to specify how to handle the data in a temporary table when a transaction is committed. The DELETE ROWS option means that all data in the temporary table will be deleted after the transaction is committed, while the PRESERVE ROWS option means that the data in the temporary table will be retained after the transaction is committed.
It should be noted that the structure of temporary tables will be automatically deleted after the session ends, however, if the data is preserved (using the PRESERVE ROWS option), the data will remain until the session ends, but the table structure will be deleted.
Here is an example of creating a temporary table in Oracle:
Create a temporary table called temp_table with columns id (number) and name (varchar2) that will be deleted after each commit.
This example creates a temporary table named temp_table with two columns, id and name, with data types NUMBER and VARCHAR2 respectively. The data in the temporary table will be deleted after the transaction is committed.