I'm looking for a way to insert records into a 'black hole'; i.e. execute a query for a certain table successfully, but make the records disappear. Something like INSERT INTO NULL
, if you will. MySQL has the BLACKHOLE engine, can Oracle do something similar?
The only thing I could come up with was:
- creating a view with
SELECT NULL FROM DUAL
- creating a trigger with
INSTEAD OF INSERT
andBEGIN NULL; END;
Is this okay?
Obviously, the optimal way is not to execute the insert statement, but I have no control over this - I have to fix this in the DB.
What's the best way to handle this? (the solution with the least impact on performance)
1 Answer 1
One way you could do something like this on Oracle is to use a temporary table
with ON COMMIT DELETE ROWS
. The rows will "disappear" at the end of the transaction. If you're using a host environment such as JDBC with autocommit, this will make it look like what you describe. If performance is important, this approach will be much faster than the "discarding trigger" approach.
Syntax:
CREATE GLOBAL TEMPORARY TABLE my_table (
column1 INTEGER,
column2 VARCHAR2(100),
...
)
ON COMMIT DELETE ROWS;
Documentation: http://docs.oracle.com/cd/B28359_01/server.111/b28310/tables003.htm#ADMIN11633
-
Unfortunately, the table needs to be persistent...Vincent Van Den Berghe– Vincent Van Den Berghe2014年05月14日 12:31:44 +00:00Commented May 14, 2014 at 12:31
-
Oracle temporary tables are persistent! It's just the contents that are temporary.Colin 't Hart– Colin 't Hart2014年05月14日 12:32:43 +00:00Commented May 14, 2014 at 12:32
-
If the structures are persistent, this is most definitely a very elegant solution :) What happens if you don't commit?Vincent Van Den Berghe– Vincent Van Den Berghe2014年05月15日 07:30:43 +00:00Commented May 15, 2014 at 7:30
-
The records will remain visible until
commit
orrollback
-- but only to your session, not to any others. Records in temporary tables are never visible to other sessions -- even withon commit preserve rows
(then the rows "disappear" on logout). Like I said, this may or may not work for you, but would be the way I would try to solve the problem, if possible. NB records are stored (ie: temporarily) in the default temporary tablespace of the user, or you can explicitly assign a tablespace at table creation time.Colin 't Hart– Colin 't Hart2014年05月15日 07:44:35 +00:00Commented May 15, 2014 at 7:44
dual
table. Just create a dummy table instead.