ORACLE表字段默认值表达式

给一个表的字段B默认值设为一个表达式,这个表达式的作用是把这个表的A字段的值装换一下给B,就比如说有条记录,字段A值为20171212,我要字段B的值为字段A转换的date类型值2017/12/12这个可以实现么,触发器应该是可以实现的

是得用触发器,创建表:

create table test
(a varchar2(20),
b date);

创建触发器:

create or replace trigger t_test
before insert on test
for each row
  declare
begin
 :new.b:=to_date(:new.a,'yyyy-mm-dd');
end;

测试:

insert into test (a) values ('20171225');
commit;

测试结果:

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答