Solved

INSERT_DATE

Posted on 2013-12-17
7
456 Views
Last Modified: 2013-12-17
Hi,
I have a trigger as follow:
BEGIN
    INSERT INTO BCP_ENTRY (BCP_ENTRY_UNIQUE_NO, BCP_ENTRY_SAD_HEADER_ID, SAD_REPL_COU) VALUES ( BCP_ENTRY_SEQ.nextval, :new.SAD_ID, :new.SAD_REPL_COU);
END;

In the table BCP_ENTRY I need to update field INSERT_DATE with timestamp (when inserting was performed)

BEGIN
    INSERT INTO BCP_ENTRY (BCP_ENTRY_UNIQUE_NO, BCP_ENTRY_SAD_HEADER_ID, SAD_REPL_COU, INSERT_DATE) VALUES ( BCP_ENTRY_SEQ.nextval, :new.SAD_ID, :new.SAD_REPL_COU, :new.INSERT_DATE :=TIMESTAMP);
END;

I'm receiving error...
Thank you
0
Comment
Question by:andrejaTJ
  • 3
  • 2
  • 2
7 Comments
 
LVL 8

Assisted Solution

by:Surrano
Surrano earned 50 total points
ID: 39723856
Can you please elaborate on what error you receive?
What is the exact trigger definition and table definition?
Have you tried like this?

BEGIN
    new.INSERT_DATE := TIMESTAMP;
    INSERT INTO BCP_ENTRY (BCP_ENTRY_UNIQUE_NO, BCP_ENTRY_SAD_HEADER_ID, SAD_REPL_COU, INSERT_DATE) 
    VALUES ( BCP_ENTRY_SEQ.nextval, :new.SAD_ID, :new.SAD_REPL_COU, :new.INSERT_DATE);
END;

Open in new window


or simply

BEGIN
    INSERT INTO BCP_ENTRY (BCP_ENTRY_UNIQUE_NO, BCP_ENTRY_SAD_HEADER_ID, SAD_REPL_COU, INSERT_DATE) 
    VALUES ( BCP_ENTRY_SEQ.nextval, :new.SAD_ID, :new.SAD_REPL_COU, TIMESTAMP);
END;

Open in new window

0
 

Author Comment

by:andrejaTJ
ID: 39723865
Thank you for your reply, but I'm getting error ORA-24344: success with compilation error :(
0
 
LVL 34

Accepted Solution

by:
johnsone earned 100 total points
ID: 39723874
What are you trying to put into the INSERT_DATE field?  If you are looking for the current time, then it would be:

BEGIN
    INSERT INTO BCP_ENTRY (BCP_ENTRY_UNIQUE_NO, BCP_ENTRY_SAD_HEADER_ID, SAD_REPL_COU, INSERT_DATE) VALUES ( BCP_ENTRY_SEQ.nextval, :new.SAD_ID, :new.SAD_REPL_COU, SYSTIMESTAMP);
END;

The full code of the trigger and what you are trying to accomplish would be a lot more helpful than one line.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:andrejaTJ
ID: 39723895
Johnsone, Surrano,
This trigger is working without problem:

create or replace
TRIGGER "TADEC_AF"."SAD_HEADER_TRIGGER" AFTER INSERT ON "TADEC_AF"."SAD_HEADER" REFERENCING OLD AS "OLD" NEW AS "NEW" FOR EACH ROW BEGIN
    INSERT INTO BCP_ENTRY (BCP_ENTRY_UNIQUE_NO, BCP_ENTRY_SAD_HEADER_ID, SAD_REPL_COU)
    VALUES ( BCP_ENTRY_SEQ.nextval, :new.SAD_ID, :new.SAD_REPL_COU);
END;

When I'm trying to add SYSDATE to the fiels INSERT_DATE... Error.
Simply, I have DATE field (7) in the table BCP_ENTRY where is required to add TIMESTAMP or SYSDATE.... Like now()
0
 
LVL 34

Assisted Solution

by:johnsone
johnsone earned 100 total points
ID: 39723912
Then what I posted should work.  Have you tried it?  That would put the current timestamp in there.  Oracle should automatically convert it to DATE if that is the data type of INSERT_DATE (or you can change SYSTIMESTAMP to SYSDATE.
0
 
LVL 8

Expert Comment

by:Surrano
ID: 39724021
what an oversight indeed, I should've noticed it was TIMESTAMP instead of SYSTIMESTAMP ;)
0
 

Author Comment

by:andrejaTJ
ID: 39724036
Thank you both... All the best!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question