When inserting values into TARGET_TABLE with below INSERT..SELECT statement, the column default for the column lastupdate seems to be prioritized over the value resulting from the SELECT statement.
Even though there is always a value for this column in the SOURCE_TABLE.
Example:
SOURCE_TABLE contains lastupdate = 16.08.12 15:41:44
After executing the statement, lastupdate in TARGET_TABLE gets set to SYSDATE, e.g. 16.08.12 15:49:14:
INSERT INTO TARGET_TABLE (A, B, C, D, LASTUPDATE, F)
SELECT A, B, C, D, LASTUPDATE, F
FROM SOURCE_TABLE
WHERE B = 'some_value';
CREATE TABLE TARGET_TABLE
(
ID NUMBER NOT NULL,
A VARCHAR2(255 CHAR) NOT NULL,
B VARCHAR2(255 CHAR) NOT NULL,
C CLOB NOT NULL,
D VARCHAR2(255 CHAR),
LASTUPDATE DATE DEFAULT SYSDATE,
E DATE DEFAULT SYSDATE
)
Oracle version: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 – 64bit Production
I would like the value to be copied from SOURCE_TABLE to TARGET_TABLE and not to be set to SYSDATE.
What am I missing here? Thank you.
Can you copy and paste from a SQL*Plus session showing this behavior? It doesn’t reproduce on my 11.2 database and it’s not something that I’ve ever personally seen happen.
I had to change your
INSERTintoSOURCE_TABLEto specify the columnErather thanFsince theCREATE TABLEstatement only had a columnE.I also had to change your
INSERTintoTARGET_TABLEto add theIDcolumn since that has aNOT NULLconstraint. I’m assuming that in your actual example this is probably getting populated by a trigger onTARGET_TABLEthat is selecting the data from a sequence. Is it possible that this trigger (or some other trigger) is setting theLASTUPDATEvalue as well?