Insert a user id automatically in table [message #454805] |
Fri, 07 May 2010 10:33 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
rkhatiwala
Messages: 178 Registered: April 2007
|
Senior Member |
|
|
Hi all,
I have a table with table_ID, date_created, user_id.
I have sequence, and a BEFORE INSERT trigger, which uses the seq to increment the table_ID by 1, everytime the webpage is saved.
ques:
(1).If i have date_creted defaulted to sysdate in the table, do I need to have it in the trigger?
-- Update create_date field to current system date
:NEW.DATE_CREATED := sysdate;
(2).How can I insert the user_id in the table, each time user SAVE the page ? web page procedure is getting the user info at the beginning. can i add it in the trigger
DECLARE
v_username varchar2(10);
BEGIN
-- Find username of person performing INSERT into table
SELECT user INTO v_username
FROM dual;
-- Update created_by field to the username of the person performing the INSERT
:new.USER_ID:= v_username;
END;
|
|
|
Re: Insert a user id automatically in table [message #454809 is a reply to message #454805] |
Fri, 07 May 2010 10:59 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) |
![](http://www.orafaq.com/forum/images/custom_avatars/102589.gif) |
Michel Cadot
Messages: 68675 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
(1) No. But the meaning is different; a default value is the value when none is given, a value in a trigger overwrite the given (possibly) value. In the former, you can have any value, in the later, you can have only the value set by the trigger
(2) Which web server? Which language? What is the meaning of "the user SAVE the page"?
Regards
Michel
|
|
|