开发者

oracle default value for a column

开发者 https://www.devze.com 2023-03-30 16:04 出处:网络
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?

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.

0

精彩评论

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

关注公众号