开发者

Want to insert timestamp through procedure in oracle

I have this procedure

PROCEDURE insertSample
  (
    return_code_out OUT VARCHAR2,
    return_msg_out OUT VARCHAR2,
    sample_id_in IN table1.sample_id%TYPE,
    name_in IN table1.name%TYPE,
    address_in IN table1.address%TYPE
  )
  IS

  BEGIN
    return_code_out := '0000';
    return_msg_out := 'OK';

    INSERT INTO tabl开发者_如何转开发e1
    sample_id, name, address)
    VALUES
    (sample_id_in, name_in, address_in);


  EXCEPTION
    WHEN OTHERS
    THEN
      return_code_out := SQLCODE;
      return_msg_out := SQLERRM;


  END insertSample;

I want to add 4th column in table1 like day_time and add current day timestamp in it.. ho can i do that in this procedure.. thank you


Assuming you you have (or add) a column to the table outside of the procedure, i.e.

ALTER TABLE table1
  ADD( insert_timestamp TIMESTAMP );

you could modify your INSERT statement to be

   INSERT INTO table1
    sample_id, name, address, insert_timestamp)
    VALUES
    (sample_id_in, name_in, address_in, systimestamp);

In general, however, I would strongly suggest that you not return error codes and error messages from procedures. If you cannot handle the error in your procedure, you should let the exception propagate up to the caller. That is a much more sustainable method of writing code than trying to ensure that every caller to every procedure always correctly checks the return code.


Using Sysdate can provide all sorts of manipulation including the current date, or future and past dates.

http://edwardawebb.com/database-tips/sysdate-determine-start-previous-month-year-oracle-sql


SYSDATE will give you the current data and time.

and if you add the column with a default value you can leave your procedure as it is

ALTER TABLE table1 ADD when_created DATE DEFAULT SYSDATE;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜