Oracle 12c allows to use sequence as default value for column value. This video shows the behavior in pre-12C & 12C version onwards.
-- Behaviour from 12c onwards ( USAGE OF SEQUENCE FOR DEFAULT VALUE )
drop table stu_details;
create sequence stu_id_seq;
CREATE TABLE stu_details (
stu_id NUMBER DEFAULT stu_id_seq.nextval,
stu_name VARCHAR2(30),
date_of_join DATE DEFAULT sysdate
);
insert into stu_details(stu_name,date_of_join) values('RAGU',sysdate);
insert into stu_details(stu_id,stu_name,date_of_join) values(201,'SCOTT',sysdate);
insert into stu_details(stu_id,stu_name,date_of_join) values(NULL,'SMITH',sysdate);
select *
from stu_details;
-- Behaviour from 12c onwards ( USAGE OF "DEFAULT ON NULL" )
drop table stu_details;
drop sequence stu_id_seq;
create sequence stu_id_seq;
CREATE TABLE stu_details (
stu_id NUMBER DEFAULT ON NULL stu_id_seq.nextval,
stu_name VARCHAR2(30),
date_of_join DATE DEFAULT sysdate
);
insert into stu_details(stu_name,date_of_join) values('RAGU',sysdate);
insert into stu_details(stu_id,stu_name,date_of_join) values(100,'SCOTT',sysdate);
insert into stu_details(stu_id,stu_name,date_of_join) values(NULL,'SMITH',sysdate);
select *
from stu_details;
I'm regularly following your youtube channel,your way of explanation very simple and effective manner and your examples are real time scenarios. Could you please upload ETL related videos.
ReplyDeleteThanks
Durga Kumar.