본문 바로가기
  • 노란색 세상은 어디에 있을까?
  • 봄이 오면 여기에 있겠지.
  • 잠시나마 유유자적 하겠네.
오라클/테이블(시스템관리)

[ 프로파일 ] 테이블 생성을 아래와 같이 진행합니다.

by 태백성 2024. 4. 12.

-- ------------------------------------------------------------------------------------------------
-- [ 시스템관리 ] 프로파일 테이블 생성
conn system/built123$@ndb;
-- ------------------------------------------------------------------------------------------------
-- 테이블 생성
drop   table bsys.sys_profile cascade constraints;
create table bsys.sys_profile
(
     corp_id                 number         not null
    ,profile_id              number         not null
    ,profile_cd              varchar2(50)   not null
    ,profile_name            varchar2(200)  not null
    ,profile_short_name      varchar2(100)  not null
    ,profile_value           varchar2(200)  not null
    ,start_date              date           default trunc(sysdate) not null
    ,end_date                date
    ,remark                  varchar2(4000)
    ,create_date             timestamp      default systimestamp
    ,create_by               varchar2(50)   default '-1'
    ,update_date             timestamp      default systimestamp
    ,update_by               varchar2(50)   default '-1'
);

-- 테이블 설명
comment on table  bsys.sys_profile                    is '[시스템관리] 프로파일';
comment on column bsys.sys_profile.corp_id            is '법인ID';
comment on column bsys.sys_profile.profile_id         is '프로파일ID';
comment on column bsys.sys_profile.profile_cd         is '프로파일코드';
comment on column bsys.sys_profile.profile_name       is '프로파일명';
comment on column bsys.sys_profile.profile_short_name is '프로파일명(약칭)';
comment on column bsys.sys_profile.profile_value      is '프로파일값';
comment on column bsys.sys_profile.start_date         is '시작일자';
comment on column bsys.sys_profile.end_date           is '종료일자';
comment on column bsys.sys_profile.remark             is '비고';

comment on column bsys.sys_profile.create_date        is '생성일시';
comment on column bsys.sys_profile.create_by          is '생성자';
comment on column bsys.sys_profile.update_date        is '수정일시';
comment on column bsys.sys_profile.update_by          is '수정자';

-- primary 인덱스
alter table bsys.sys_profile add constraint sys_profile_pk primary key (profile_id) using index tablespace bdb_idx;

-- unique 인덱스
create unique index bsys.sys_profile_uk on bsys.sys_profile (corp_id, profile_cd) tablespace bdb_idx;

-- 권한부여
grant select, insert, update, delete on bsys.sys_profile to bcom with grant option;
grant select, insert, update, delete on bsys.sys_profile to bhrm with grant option;

-- 트리거 생성
create or replace trigger bsys.sys_profile_trg
    before insert or update on bsys.sys_profile
    for each row
begin
    if :new.profile_id is null then
        :new.profile_id := sys_profile_s.nextval;
    end if;
        
    if inserting then
        :new.create_date := systimestamp;
        :new.create_by   := nvl(wwv_flow.g_user, user);
    end if;    
    
    :new.update_date := systimestamp;
    :new.update_by   := nvl(wwv_flow.g_user, user);
end;
/

-- 시노님 생성
conn bcom/1234@ndb;
create or replace synonym sys_profile for bsys.sys_profile;

conn bhrm/1234@ndb;
create or replace synonym sys_profile for bsys.sys_profile;