oracle default value for a column
You 开发者_如何转开发know how we could use:
dateStamp DATE DEFAULT sysdate
to assign a default value to a column in table_x. What if I want to assign a default function? Can I do that?
The function will have some values from "table_params" to run some formula including a column named : "base" in table_x.
I could possibly write a cursor to loop through and run an update statement, but I was just curious if this is possible. thanks in advance.
From Oracle documentation:
Restriction on Default Column Values
A DEFAULT expression cannot contain references to PL/SQL functions or to other columns, the pseudocolumns CURRVAL, NEXTVAL, LEVEL, PRIOR, and ROWNUM, or date constants that are not fully specified.
Either use a trigger (as was already mentioned) or run an UPDATE statement after your INSERT statement(s) (shouldn't be a problem if you keep your DML in PL/SQL).
You can write an INSERT trigger for the table that calls the function you want.
精彩评论