Default value of column can use a sequence.nextval
在以往ORACLE 9i ,10g,11g 建sequence 都要建一個Trigger 將Seqence 作改變
參考Create table with default sequence
Creating a Table with a DEFAULT ON NULL Column Value: Example
The following statement creates a table
myemp
, which can be used to store employee data. The department_id
column is defined with a DEFAULT
ON
NULL
column value of 50. Therefore, if a subsequent INSERT
statement attempts to assign a NULL value to department_id
, then the value of 50 will be assigned instead.CREATE TABLE myemp (employee_id number, last_name varchar2(25), department_id NUMBER DEFAULT ON NULL 50 NOT NULL);
以上官網的範例 以下我作個實際範例
create table example (
production varchar2(100),
productioserial number default on null 1 not null);
insert into example(production) values('item2');
commit;
insert into example(production) values('item2');
commit;
select * from example;
Results : 看樣子是會帶DEFAULT 值出 ,可是這不是我要的自動增加 PRODUCTION PRODUCTIOSERIAL ---------------------------------------------------------------- item1 1 item2 1
CREATE TABLE example2 (productname varchar2(100),serial NUMBER GENERATED BY DEFAULT AS IDENTITY (START WITH 1 INCREMENT BY 1));
insert into example2(productname) values ('itema');
insert into example2(productname) values ('itemb');
PRODUCTNAME SERIAL
--------------------------------
itema 1
itemb 2