Oracle中表級列的預設值控制

來源:互聯網
上載者:User

1、 指令碼及測試步驟

--1、建測試表
create table tab_default(id varchar2(2),default_sysdate date,default_char_date varchar2(8),default_guid varchar2(100));
--2、添加預設值束縛
alter table tab_default modify default_sysdate date default sysdate;
alter table tab_default modify default_char_date VARCHAR2(100) default to_char(sysdate,'YYYYMMDD');
alter table tab_default modify default_guid VARCHAR2(100) default sys_guid();
--3、測試資料插入
insert into tab_default(id)
select '1' from dual;
commit;
insert into tab_default(id)
select '2' from dual;
commit;
insert into tab_default(id)
select '3' from dual;
commit;
--4、結果查看
select * from tab_default;

2、 注意事項

--1、預設值取值方法
--不可以如下
insert into tab_default(id, default_sysdate)
  select '1', null from dual;
--只可以如下(即,在資料插入的時候,只需要將要插入的欄位列出,需要預設值的欄位不管就可以了)
insert into tab_default(id)
  select '1' from dual;
--2、也可以在建表的時候直接賦預設值
drop table tab_default;
CREATE TABLE tab_default(col_date date DEFAULT sysdate);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.