Oracle allows us to create temporary tables to hold data just for the duration of a session or for a particular transaction.
ON COMMIT DELETE ROWS [The ON COMMIT DELETE ROWS Clause indicates that the data should be deleted at the end of the transaction ,or end of the session]
======================
Example :
CREATE GLOBAL TEMPORARY TABLE my_test_tab
(
ID NUMBER,
description varchar2(10)
)
on commit delete rows;
SQL> insert into my_test_tab
2 values (1,'one');
1 row created.
SQL> select count(*) from my_test_tab;
COUNT(*)
----------
1
SQL> commit;
Commit complete.
SQL> select count(*) from my_test_tab;
COUNT(*)
----------
0
ON COMMIT PRESERVE ROWS [this clause indicates that rows should persist beyond the end of the transaction.they will be removed at the end of the transaction]
========================
CREATE GLOBAL TEMPORARY TABLE test_tab
(
ID NUMBER,
description varchar2(10)
)on commit preserve rows;
SQL> insert into test_tab values(1,'one');
1 row created.
SQL> select count(*) from test_tab;
COUNT(*)
----------
1
SQL> commit;
Commit complete.
SQL> select count(*) from test_tab;
COUNT(*)
----------
1
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@localhost ~]$ sqlplus rajiv/rajiv@testdb
[oracle@localhost ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Thu Mar 31 18:00:14 2016
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> conn rajiv/rajiv
Connected.
SQL> select count(*) from test_tab;
COUNT(*)
----------
0
ON COMMIT DELETE ROWS [The ON COMMIT DELETE ROWS Clause indicates that the data should be deleted at the end of the transaction ,or end of the session]
======================
Example :
CREATE GLOBAL TEMPORARY TABLE my_test_tab
(
ID NUMBER,
description varchar2(10)
)
on commit delete rows;
SQL> insert into my_test_tab
2 values (1,'one');
1 row created.
SQL> select count(*) from my_test_tab;
COUNT(*)
----------
1
SQL> commit;
Commit complete.
SQL> select count(*) from my_test_tab;
COUNT(*)
----------
0
ON COMMIT PRESERVE ROWS [this clause indicates that rows should persist beyond the end of the transaction.they will be removed at the end of the transaction]
========================
CREATE GLOBAL TEMPORARY TABLE test_tab
(
ID NUMBER,
description varchar2(10)
)on commit preserve rows;
SQL> insert into test_tab values(1,'one');
1 row created.
SQL> select count(*) from test_tab;
COUNT(*)
----------
1
SQL> commit;
Commit complete.
SQL> select count(*) from test_tab;
COUNT(*)
----------
1
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@localhost ~]$ sqlplus rajiv/rajiv@testdb
[oracle@localhost ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Thu Mar 31 18:00:14 2016
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> conn rajiv/rajiv
Connected.
SQL> select count(*) from test_tab;
COUNT(*)
----------
0