select * from user_tables where lower(table_name) = 'board';
select*from user_constraints where lower(table_name) = 'board';
create table board(
boardid number,
title varchar2(50),
content varchar2(2000),
regdate date
);
desc board;
--Oracle 11g부터 가상컬럼(조합 컬럼) 도입
-- 학생 성적 : 국어, 영어 , 수학 ,총점 컬럼이 있다.
--총점 컬럼은 설계할 때 굳이 필요가 없는데 자료조회를 빨리 하기 위해서 만들 수도 있다.
-- 국어, 영어, 수학 data가 insert되면 자동적으로 총점이 생성되게 하고 싶다.
create table vtable(
no1 number,
no2 number,
no3 number GENERATED ALWAYS as (no1 + no2) VIRTUAL
);
insert into vtable(no1,no2)
values (100,50);
insert into vtable(no1,no2)
values (80,60);
select * from vtable;
----no3 가상컬럼에 데이터를 직접 넣을 수 있나? --> INSERT operation disallowed on virtual columns ->> 안된다.
insert into vtable(no1,no2,no3)
values (100,50,200);
select COLUMN_NAME , DATA_TYPE , DATA_DEFAULT
from user_tab_columns where table_name = 'VTABLE';
--실무에 사용되는 형식의 코드
--제품정보 ( 입고일 ) 기준에 따라서 분기별로 데이터를 나누고 싶다.
--입고일 : 2018-03-02 >> 1분기 데이터
create table vtable2(
no number,
p_code char(4), --제품코드(A001)
p_date char(8), --입고일(20180302)
p_qty number, -- 수량
p_bungi number(1) GENERATED ALWAYS as (CASE WHEN substr(p_date,5,2) IN ('01','02','03') THEN 1
WHEN substr(p_date,5,2) IN ('04','05','06') THEN 2
WHEN substr(p_date,5,2) IN ('07','08','09') THEN 3
ELSE 4
END
) VIRTUAL -- 가상 컬럼
);
insert into vtable2(p_date) values('20180101');
insert into vtable2(p_date) values('20180126');
insert into vtable2(p_date) values('20180401');
insert into vtable2(p_date) values('20180601');
insert into vtable2(p_date) values('20181101');
select*from vtable2;