Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get a Timestamp value from an inserted record?

Status
Not open for further replies.

mperemsky

Programmer
Apr 9, 2010
2
0
0
US
I have a procedure that inserts a record into a table and I need to return the timestamp from the insertion back to the calling java program. As I am relatively new to DB2 I am not sure how to do this. I have search the web for any info on this but, have not had any success.

SQL:
CREATE PROCEDURE "ATS"."MVP_ASC_INSERT" ( 
	IN "P_SM_ACCOUNT_ID" VARCHAR(8),
        IN "P_USER_ID" VARCHAR(30),
	OUT "P_CREATED_TIMESTAMP" TIMESTAMP
)
  LANGUAGE SQL
  MODIFIES SQL DATA
  CALLED ON NULL INPUT
  INHERIT SPECIAL REGISTERS
BEGIN

  INSERT INTO ATS_SYSTEM_CONTACTS
     (ACCOUNT_ID, USER_ID, CREATED_TIMESTAMP)
  VALUES 
     (P_SM_ACCOUNT_ID, P_USER_ID, CURRENT TIMESTAMP);

END;
 
Possibly, read the newly created row retrieving the timestamp to return to the calling program.
 
Select the current timestamp into p_created_timestamp (is that some kind of Hungarian notation?). Then use p_created_timestamp in the value clause of the insert instead of current_timestamp.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top