java - Delete temporary table with 'ON COMMIT PRESERVE ROWS' option in oracle -


i use jdbc , oracle db. how can create global temporary table otion on commit preserve rows, , drop table statement ? code example shown in below.

queryofstatement1 = "create global temorary table my_table (id varchar(20 byte), name varchar(20 byte)) on commit preserve rows"; statement1.execute(); statement1.commit(); queryofstatement2 = "drop table my_table"; statement2.execute(); statement2.commit();

as stated in oracle official documentation: "temporary tables useful in applications result set buffered (temporarily persisted). during session, itinerary data private. @ end of session, optional itineraries dropped."

you can't alter table definition in same session either, must disconnect , connect in order alter or drop temporary table.

in example:

sql> show user user "z_test" sql>   sql> create global temporary table my_table   2  (   3    id varchar(20 byte),   4    name varchar(20 byte)   5  )   6  on commit preserve rows ;  table created.  sql> insert my_table values ('this id','this name') ;  1 row created.  sql> commit ;  commit complete.  sql>  /* alter table example */  sql>alter table     my_table     add    (col3 varchar2(100));  error @ line 1: ora-14450: attempt access transactional temp table in use  sql> drop table my_table ; drop table my_table            * error @ line 1: ora-14452: attempt create, alter or drop index on temporary table in use  sql>  sql> show user user "z_test" sql> select * my_table ;  id                   name -------------------- -------------------- id           name  sql>  /* disconnect session , connect again */ sql> conn z_test/welcome1 connected.  sql> show user user "z_test" sql> select * my_table ;  no rows selected  sql>  sql>  alter table     my_table     add    (col3 varchar2(100)) ;     table altered.  sql>  sql> drop table my_table ;  table dropped.  sql> 

it's important note when disconnect/connect find , "empty table", stated in beginning: "at end of session, optional itineraries dropped.". application design must consider expected behavior.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -