Forum Stats

  • 3,855,318 Users
  • 2,264,499 Discussions
  • 7,905,968 Comments

Discussions

Insert Statement Updated by

User_7C1YX
User_7C1YX Member Posts: 9 Green Ribbon
edited May 27, 2022 7:53AM in SQL Developer

Hi All,

I am trying to insert records into a table as below

INSERT INTO table2 (Emp_ID, Emp_Name, Sal, update_by)

SELECT Emp_ID, Emp_Name, Sal,? FROM table1.

For Updated_By I need some function or wild character that automatically insert Users who is executing the Insert statement.


Kindly advise.

Answers

  • thatJeffSmith-Oracle
    thatJeffSmith-Oracle Distinguished Product Manager Posts: 8,777 Employee

    your 'function' could be a TRIGGER, that fires on an INSERT or UPDATE, that sets the :NEW value to your :current_user doing the INSERT or UPDATE


    This is best asked on the General or SQL forums, and this problem has been solved many times, search on 'trigger' and 'journal table'

  • User_7C1YX
    User_7C1YX Member Posts: 9 Green Ribbon

    Hi @thatJeffSmith-Oracle ,


    Thanks for response, but this is not what I want exactly need, trigger is not an option.

    Suppose I was to inserted updated Timestamp also I would have used sysdate, similarly for updated by i need something in Insert statement that Inserts the USER ID everytime query is executed

  • thatJeffSmith-Oracle
    thatJeffSmith-Oracle Distinguished Product Manager Posts: 8,777 Employee

    I think what you're doing is probably not a great design, but we don't know enough to know. I'm going to close the thread and advise you ask the full question with all details/requirements/needs to the general forum.

This discussion has been closed.