Oracle DB Column in table  with default for the user

jknj72
jknj72 used Ask the Experts™
on
I have a column that I want defaulted to the current user doing the Insert into the table? I have SYSTIMESTAMP as my default for the CREATE_DATE column but now I want the CREATE_BY column defaulted to SYSUSER(I think that is for SQL Server)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David VanZandtOracle Database Administrator III

Commented:
Check any Oracle SQL reference for the syntax, but you're simply passing the parameter when you define or modify the column, such as column name default sysuser.
Most Valuable Expert 2012
Distinguished Expert 2018
Commented:
Check out USER:
create table tab1(col1 varchar2(20) default user, col2 char(1));

Author

Commented:
Looks like User will work for me. .
Most Valuable Expert 2012
Distinguished Expert 2018

Commented:
If you ever want anything else, you might need to step up to SYS_CONTEXT.  There are a LOT of things you get pull with that:
http://docs.oracle.com/cd/E11882_01/server.112/e41084/functions184.htm

Author

Commented:
Thanks Slight. Taking this a bit further so Im posting another question...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial