日期:2014-05-16  浏览次数:20442 次

[简单]oracle char设置默认值

?????? 最近工作中同事把时间字段设置为char(10),格式为yyyy-mm-dd,就想这怎么设置char默认值为2099-12-31,一开始这样写的

??????

-- Create table
create table tsql_test_chardef
(
  t_id   number(4)    not null,
  start_date char(10),
  end_date varchar2(10)
);

-- Add/modify columns 
alter table TSQL_TEST_CHARDEF modify start_date default 2099-12-31;
alter table TSQL_TEST_CHARDEF modify end_date default 2099-12-31;

??? 结果为

???

???

????

???? 正确方法是

????

-- Add/modify columns 
alter table TSQL_TEST_CHARDEF modify start_date default '2099-12-31';
alter table TSQL_TEST_CHARDEF modify end_date default '2099-12-31';

?

??? 结果为

???

??

?? 或者

????

-- Add/modify columns 
alter table TSQL_TEST_CHARDEF modify start_date default to_char('2099-12-31');
alter table TSQL_TEST_CHARDEF modify end_date default to_char('2099-12-31');

??

?

??? 同理,设置date默认值方法为

???

-- Add/modify columns 
alter table TSQL_TEST_CHARDEF modify done_date default to_date('2099-12-31','yyyy-mm-dd');

???

??? 全文完。

?