Insert default value when null is inserted

后端 未结 5 1222
有刺的猬
有刺的猬 2021-02-13 21:07

I have an Oracle database, and a table with several not null columns, all with default values.

I would like to use one insert statement for any data I want to insert, a

5条回答
  •  迷失自我
    2021-02-13 21:25

    For those who reading it now:

    In Oracle 12c there is new feature: DEFAULT ON NULL. For example:

    CREATE TABLE tab1 (
      col1        NUMBER DEFAULT 5,
      col2        NUMBER DEFAULT ON NULL 7,
      description VARCHAR2(30)
    );
    

    So when you try to INSERT null in col2, this will automatically be 7.

提交回复
热议问题