Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->create table TEST
(
ID VARCHAR2(64),
A VARCHAR2(3) default '0',
NAME VARCHAR2(100)
);
SQL> insert into test(a,name) values(null,'test');
1 row inserted
SQL> select * from test;
A NAME
--- --------------------------------------------------------------------------------
test
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->SQL> insert into test(a,name) values(default,'test');
1 row inserted
SQL> select * from test;
A NAME
--- --------------------------------------------------------------------------------
0 test
列A终于有了默认值0。
再看第二种方式,
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->SQL> insert into test2(name) values('test');
1 row inserted
SQL> select * from test2;
A NAME
--- --------------------------------------------------------------------------------
0 test
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->create table TEST
(
ID VARCHAR2(64),
A VARCHAR2(3) default '0',
NAME VARCHAR2(100)
);
create sequence seq_test;
create or replace trigger tri_test
before insert on test for each row
begin
if :new.id is null then
select seq_test.nextval into :new.id from dual;
end if;
end;
/
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->alter table TEST modify ID default sys_guid()
SQL> insert into test2(name) values('张三');
1 row inserted
SQL> select * from test2;
ID A NAME
---------------------------------------------------------------- --- --------------------------------------------------------------------------------
7CDB1AF556F6474FABA74FA7A60F0822 0 张三