-------------------------------------------------------
-- Export file for user HAI                          --
-- Created by administrator on 3/7/2017, 10:26:32 AM --
-------------------------------------------------------

spool Export User Objects 20170307.log

prompt
prompt Creating table BTTDC_DM_THUOCTINH_HS
prompt ====================================
prompt
create table HAI.BTTDC_DM_THUOCTINH_HS
(
  MA_THUOC_TINH      NVARCHAR2(200) not null,
  TEN_THUOC_TINH     NVARCHAR2(200) not null,
  GIA_TRI_THUOC_TINH NVARCHAR2(200),
  TRANG_THAI         INTEGER default 0 not null,
  STT_THUOC_TINH     INTEGER default 100 not null,
  MA_LINH_VUC        NVARCHAR2(200) not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.BTTDC_DM_THUOCTINH_HS
  add primary key (MA_THUOC_TINH)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table BTTDC_DM_VB_TIEP_NHAN
prompt ====================================
prompt
create table HAI.BTTDC_DM_VB_TIEP_NHAN
(
  MA_VB_TIEP_NHAN  NVARCHAR2(200) not null,
  TEN_VB_TIEP_NHAN NVARCHAR2(200) not null,
  TT_VB_TIEP_NHAN  INTEGER default 0 not null,
  STT_VB_TIEP_NHAN INTEGER default 100 not null,
  MA_HINH_THUC     NVARCHAR2(200) not null,
  TT_GIA_TRI       INTEGER default 0
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.BTTDC_DM_VB_TIEP_NHAN
  add primary key (MA_VB_TIEP_NHAN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.BTTDC_DM_VB_TIEP_NHAN
  add unique (TEN_VB_TIEP_NHAN)
  disable;

prompt
prompt Creating table BTTDC_GT_THUOCTINH_HS
prompt ====================================
prompt
create table HAI.BTTDC_GT_THUOCTINH_HS
(
  MA_THUOC_TINH      NVARCHAR2(200) not null,
  TEN_THUOC_TINH     NVARCHAR2(200) not null,
  GIA_TRI_THUOC_TINH NVARCHAR2(200),
  TRANG_THAI         INTEGER default 0 not null,
  STT_THUOC_TINH     INTEGER default 100 not null,
  MA_LINH_VUC        NVARCHAR2(200) not null,
  MA_HO_SO           NVARCHAR2(200) not null,
  MA_THUOC_TINH_DM   NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.BTTDC_GT_THUOCTINH_HS
  add primary key (MA_THUOC_TINH)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table BTTDC_HINH_THUC
prompt ==============================
prompt
create table HAI.BTTDC_HINH_THUC
(
  MA_HINH_THUC  NVARCHAR2(200) not null,
  TEN_HINH_THUC NVARCHAR2(200) not null,
  TRANG_THAI    INTEGER default 0 not null,
  STT_HINH_THUC INTEGER default 100 not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.BTTDC_HINH_THUC
  add primary key (MA_HINH_THUC)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.BTTDC_HINH_THUC
  add unique (TEN_HINH_THUC)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table BTTDC_HO_SO2
prompt ===========================
prompt
create table HAI.BTTDC_HO_SO2
(
  MA_HO_SO2      NVARCHAR2(200) not null,
  KHHS           NVARCHAR2(200) not null,
  TEN_HO_SO      NVARCHAR2(500) not null,
  TEN_CONG_TRINH NVARCHAR2(500) not null,
  MA_HUYEN       NVARCHAR2(200),
  MA_QUOC_TICH   NVARCHAR2(200),
  MA_HINH_THUC   NVARCHAR2(200),
  NGAY_LAP_HO_SO DATE,
  TRANG_THAI     INTEGER default 0 not null,
  STT            INTEGER default 100 not null,
  TTSTNMT        NVARCHAR2(200),
  QDUBND         NVARCHAR2(200),
  TTSTC          NVARCHAR2(200),
  NGUOI_NOP      NVARCHAR2(200),
  TTSTNMTSH      NVARCHAR2(200),
  QDUBNDSH       NVARCHAR2(200),
  TTSTCSH        NVARCHAR2(200),
  TEN_DON_VI     NVARCHAR2(200),
  LINH_VUC       NVARCHAR2(200),
  HT_TRA_TIEN    NVARCHAR2(200),
  LOAI_DAT_GIAO  NVARCHAR2(200),
  GIA_GIAO       NVARCHAR2(200),
  KPTD           NVARCHAR2(200),
  TT_KPTD        INTEGER,
  GIA_THUE       NVARCHAR2(200),
  LOAI_DAT_THUE  NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.BTTDC_HO_SO2
  add primary key (MA_HO_SO2)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.BTTDC_HO_SO2
  add unique (KHHS)
  disable;
alter table HAI.BTTDC_HO_SO2
  add unique (TEN_HO_SO)
  disable;
alter table HAI.BTTDC_HO_SO2
  add unique (TEN_CONG_TRINH)
  disable;

prompt
prompt Creating table DM_TINH_THANH
prompt ============================
prompt
create table HAI.DM_TINH_THANH
(
  MA_TINH_THANH  NVARCHAR2(200) not null,
  TEN_TINH_THANH NVARCHAR2(200) not null,
  STT_TINH_THANH NUMBER default 100 not null,
  TRANG_THAI     NUMBER default 0 not null,
  NGUOI_CAP_NHAT NUMBER,
  NGAY_CAP_NHAT  DATE
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_TINH_THANH
  add primary key (MA_TINH_THANH)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DM_QUAN_HUYEN
prompt ============================
prompt
create table HAI.DM_QUAN_HUYEN
(
  MA_QUAN_HUYEN  NVARCHAR2(200) not null,
  TEN_QUAN_HUYEN NVARCHAR2(200) not null,
  STT_QUAN_HUYEN NUMBER default 100 not null,
  TRANG_THAI     NUMBER default 0 not null,
  MA_TINH_THANH  NVARCHAR2(200) not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_QUAN_HUYEN
  add primary key (MA_QUAN_HUYEN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_QUAN_HUYEN
  add foreign key (MA_TINH_THANH)
  references HAI.DM_TINH_THANH (MA_TINH_THANH);

prompt
prompt Creating table BTTDC_PHIEU_TIEP_NHAN
prompt ====================================
prompt
create table HAI.BTTDC_PHIEU_TIEP_NHAN
(
  MA_PHIEU_TIEP_NHAN  NVARCHAR2(200) not null,
  TEN_DON_VI          NVARCHAR2(200) not null,
  TEN_CONG_TRINH      NVARCHAR2(200) not null,
  NGUOI_GIAO          NVARCHAR2(200) not null,
  NGUOI_GIAO_BO_SUNG  NVARCHAR2(200),
  CB_NHAN             INTEGER not null,
  CB_NHAN_BO_SUNG     INTEGER,
  NGAY_GIAO           DATE,
  NGAY_HEN_BO_SUNG    DATE,
  GHI_CHU             NVARCHAR2(200),
  TT_PHIEU_TIEP_NHAN  INTEGER default 100 not null,
  STT_PHIEU_TIEP_NHAN INTEGER default 0 not null,
  MA_HINH_THUC        NVARCHAR2(200) not null,
  MA_QUAN_HUYEN       NVARCHAR2(200) not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.BTTDC_PHIEU_TIEP_NHAN
  add primary key (MA_PHIEU_TIEP_NHAN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.BTTDC_PHIEU_TIEP_NHAN
  add constraint QUANHUYEN foreign key (MA_QUAN_HUYEN)
  references HAI.DM_QUAN_HUYEN (MA_QUAN_HUYEN);
alter table HAI.BTTDC_PHIEU_TIEP_NHAN
  add constraint VBTIEPNHAN foreign key (MA_PHIEU_TIEP_NHAN)
  references HAI.BTTDC_PHIEU_TIEP_NHAN (MA_PHIEU_TIEP_NHAN);

prompt
prompt Creating table BTTDC_THUVIENPHAPLUAT
prompt ====================================
prompt
create table HAI.BTTDC_THUVIENPHAPLUAT
(
  MA_VB         NVARCHAR2(200) not null,
  TRICH_YEU     NVARCHAR2(200) not null,
  SO_HIEU       NVARCHAR2(200),
  TRANG_THAI    INTEGER default 0 not null,
  STT           INTEGER default 100 not null,
  CQ_BAN_HANH   NVARCHAR2(200) not null,
  NGAY_BAN_HANH DATE not null,
  FILE_PATH     NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 16K
    next 8K
    minextents 1
    maxextents unlimited
  );
alter table HAI.BTTDC_THUVIENPHAPLUAT
  add primary key (MA_VB)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 16K
    next 8K
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table BTTDC_VB_TIEP_NHAN
prompt =================================
prompt
create table HAI.BTTDC_VB_TIEP_NHAN
(
  MA_VB_TIEP_NHAN    NVARCHAR2(200) not null,
  TEN_VB_TIEP_NHAN   NVARCHAR2(200) not null,
  TRANG_THAI         INTEGER default 0 not null,
  STT                INTEGER default 100 not null,
  GIA_TRI            INTEGER default 0,
  FILE_PATH          NVARCHAR2(200),
  MA_PHIEU_TIEP_NHAN NVARCHAR2(200),
  MA_HO_SO           NVARCHAR2(200),
  MA_VB_TIEP_NHAN_DM NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.BTTDC_VB_TIEP_NHAN
  add primary key (MA_VB_TIEP_NHAN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.BTTDC_VB_TIEP_NHAN
  add constraint PHIEUTIEPNHAN foreign key (MA_PHIEU_TIEP_NHAN)
  references HAI.BTTDC_PHIEU_TIEP_NHAN (MA_PHIEU_TIEP_NHAN);

prompt
prompt Creating table CB_LOAI_CO_QUAN
prompt ==============================
prompt
create table HAI.CB_LOAI_CO_QUAN
(
  MA_LOAI_CO_QUAN  NVARCHAR2(200) not null,
  TEN_LOAI_CO_QUAN NVARCHAR2(200) not null,
  STT_LOAI_CO_QUAN NUMBER default 100 not null,
  TRANG_THAI       NUMBER default 0 not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.CB_LOAI_CO_QUAN
  add primary key (MA_LOAI_CO_QUAN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table CB_CO_QUAN
prompt =========================
prompt
create table HAI.CB_CO_QUAN
(
  MA_CO_QUAN         NVARCHAR2(200) not null,
  TEN_CO_QUAN        NVARCHAR2(200) not null,
  MA_TAT_CO_QUAN     NVARCHAR2(200) not null,
  MA_LOAI_CO_QUAN    NVARCHAR2(200) not null,
  MA_QUAN_HUYEN      NVARCHAR2(200) not null,
  STT_CO_QUAN        NUMBER default 100 not null,
  TRANG_THAI         NUMBER default 0 not null,
  APPS               NVARCHAR2(200),
  MAX_STT_HS         NUMBER,
  DIA_CHI_CO_QUAN    NVARCHAR2(300),
  DIEN_THOAI_CO_QUAN NVARCHAR2(20),
  LOGO               NVARCHAR2(200),
  HEN_LUI_1_BUOI     NUMBER default 0 not null,
  HIEN_THI_GIO_HEN   NUMBER default 1 not null,
  EMAIL              NVARCHAR2(30),
  FAX                NVARCHAR2(200),
  WEBSITE            NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.CB_CO_QUAN
  add primary key (MA_CO_QUAN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.CB_CO_QUAN
  add foreign key (MA_LOAI_CO_QUAN)
  references HAI.CB_LOAI_CO_QUAN (MA_LOAI_CO_QUAN);

prompt
prompt Creating table DM_PHUONG_XA
prompt ===========================
prompt
create table HAI.DM_PHUONG_XA
(
  MA_PHUONG_XA      NVARCHAR2(200) not null,
  TEN_PHUONG_XA     NVARCHAR2(200) not null,
  STT_PHUONG_XA     NUMBER default 100 not null,
  TRANG_THAI        NUMBER default 0 not null,
  NGUOI_CAP_NHAT    NUMBER,
  NGAY_CAP_NHAT     DATE,
  MA_TAT            NVARCHAR2(5),
  SO_HO_SO_HIEN_TAI NUMBER default 0,
  MA_QUAN_HUYEN     NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_PHUONG_XA
  add primary key (MA_PHUONG_XA)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_PHUONG_XA
  add foreign key (MA_QUAN_HUYEN)
  references HAI.DM_QUAN_HUYEN (MA_QUAN_HUYEN);

prompt
prompt Creating table CB_CAN_BO
prompt ========================
prompt
create table HAI.CB_CAN_BO
(
  MA_CAN_BO              NUMBER not null,
  TEN_CAN_BO             NVARCHAR2(200) not null,
  TAI_KHOAN              NVARCHAR2(50) not null,
  MAT_KHAU               NVARCHAR2(200),
  CMND                   NVARCHAR2(10),
  NGAY_CAP               DATE,
  NOI_CAP                NVARCHAR2(200),
  DIA_CHI                NVARCHAR2(200),
  DI_DONG                NVARCHAR2(15),
  HINH_ANH               NVARCHAR2(200),
  MA_QUYEN_LOAD_DAU_TIEN NVARCHAR2(200),
  STT_CAN_BO             NUMBER default 100 not null,
  TRANG_THAI             NUMBER default 0 not null,
  NGUOI_CAP_NHAT         NUMBER,
  NGAY_CAP_NHAT          DATE,
  DANG_KY_NHAC_VIEC      NUMBER default 0 not null,
  GIOI_TINH              NUMBER default 0 not null,
  NGAY_SINH              NVARCHAR2(30),
  MA_CO_QUAN             NVARCHAR2(200),
  MA_PHUONG_XA           NVARCHAR2(200),
  MA_CAN_BO_LIEN_THONG   NUMBER,
  NGAY_DANG_KY_OTP       DATE
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.CB_CAN_BO
  add primary key (MA_CAN_BO)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.CB_CAN_BO
  add foreign key (MA_CO_QUAN)
  references HAI.CB_CO_QUAN (MA_CO_QUAN);
alter table HAI.CB_CAN_BO
  add foreign key (MA_PHUONG_XA)
  references HAI.DM_PHUONG_XA (MA_PHUONG_XA);

prompt
prompt Creating table CB_DON_VI
prompt ========================
prompt
create table HAI.CB_DON_VI
(
  MA_DON_VI            NVARCHAR2(200) not null,
  TEN_DON_VI           NVARCHAR2(200) not null,
  MA_LOAI_DON_VI       NVARCHAR2(200) not null,
  MA_PHUONG_XA         NVARCHAR2(200),
  STT_DON_VI           NUMBER default 100 not null,
  TRANG_THAI           NUMBER default 0 not null,
  NGUOI_CAP_NHAT       NUMBER,
  NGAY_CAP_NHAT        DATE,
  MA_DON_VI_CHU_QUAN   NVARCHAR2(200),
  TEN_DON_VI_KHONG_DAU NVARCHAR2(200),
  MA_TAT               NVARCHAR2(200) not null,
  SO_HO_SO_HIEN_TAI    NUMBER default 0 not null,
  MA_CO_QUAN           NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.CB_DON_VI
  add primary key (MA_DON_VI)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.CB_DON_VI
  add unique (TEN_DON_VI)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.CB_DON_VI
  add foreign key (MA_CO_QUAN)
  references HAI.CB_CO_QUAN (MA_CO_QUAN);

prompt
prompt Creating table CB_LOAI_DON_VI
prompt =============================
prompt
create table HAI.CB_LOAI_DON_VI
(
  MA_LOAI_DON_VI   NVARCHAR2(200) not null,
  TEN_LOAI_DON_VI  NVARCHAR2(200) not null,
  DON_VI_CAP_HUYEN NUMBER default 0 not null,
  STT_LOAI_DON_VI  NUMBER default 100 not null,
  TRANG_THAI       NUMBER default 0 not null,
  NGUOI_CAP_NHAT   NUMBER,
  NGAY_CAP_NHAT    DATE,
  MA_LOAI_CO_QUAN  NVARCHAR2(200),
  MA_CO_QUAN       NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.CB_LOAI_DON_VI
  add primary key (MA_LOAI_DON_VI)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.CB_LOAI_DON_VI
  add foreign key (MA_LOAI_CO_QUAN)
  references HAI.CB_LOAI_CO_QUAN (MA_LOAI_CO_QUAN);
alter table HAI.CB_LOAI_DON_VI
  add foreign key (MA_CO_QUAN)
  references HAI.CB_CO_QUAN (MA_CO_QUAN);

prompt
prompt Creating table CB_LOAI_NHOM_NSD
prompt ===============================
prompt
create table HAI.CB_LOAI_NHOM_NSD
(
  MA_LOAI_NHOM_NSD  NVARCHAR2(200) not null,
  TEN_LOAI_NHOM_NSD NVARCHAR2(200) not null,
  MA_LOAI_DON_VI    NVARCHAR2(200) not null,
  STT_LOAI_NHOM_NSD NUMBER default 100 not null,
  TRANG_THAI        NUMBER default 0 not null,
  NGUOI_CAP_NHAT    NUMBER,
  NGAY_CAP_NHAT     DATE
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.CB_LOAI_NHOM_NSD
  add primary key (MA_LOAI_NHOM_NSD)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.CB_LOAI_NHOM_NSD
  add foreign key (MA_LOAI_DON_VI)
  references HAI.CB_LOAI_DON_VI (MA_LOAI_DON_VI);

prompt
prompt Creating table CB_TO_CHUYEN_MON
prompt ===============================
prompt
create table HAI.CB_TO_CHUYEN_MON
(
  MA_TO_CHUYEN_MON  NUMBER not null,
  TEN_TO_CHUYEN_MON NVARCHAR2(200) not null,
  MA_DON_VI         NVARCHAR2(200) not null,
  MA_LOAI_NHOM_NSD  NVARCHAR2(200) not null,
  STT_TO_CHUYEN_MON NUMBER default 100 not null,
  TRANG_THAI        NUMBER default 0 not null,
  NGUOI_CAP_NHAT    NUMBER,
  NGAY_CAP_NHAT     DATE
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.CB_TO_CHUYEN_MON
  add primary key (MA_TO_CHUYEN_MON)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.CB_TO_CHUYEN_MON
  add foreign key (MA_DON_VI)
  references HAI.CB_DON_VI (MA_DON_VI);
alter table HAI.CB_TO_CHUYEN_MON
  add foreign key (MA_LOAI_NHOM_NSD)
  references HAI.CB_LOAI_NHOM_NSD (MA_LOAI_NHOM_NSD);

prompt
prompt Creating table DM_CHUC_VU
prompt =========================
prompt
create table HAI.DM_CHUC_VU
(
  MA_CHUC_VU  NVARCHAR2(200) not null,
  TEN_CHUC_VU NVARCHAR2(200) not null,
  STT_CHUC_VU INTEGER default 100 not null,
  TT_CHUC_VU  INTEGER default 0 not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_CHUC_VU
  add primary key (MA_CHUC_VU)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_CHUC_VU
  add unique (TEN_CHUC_VU)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table CB_THUOC_TO_CHUYEN_MON
prompt =====================================
prompt
create table HAI.CB_THUOC_TO_CHUYEN_MON
(
  MA_CAN_BO                      NUMBER not null,
  MA_TO_CHUYEN_MON               NUMBER not null,
  MA_CHUC_VU                     NVARCHAR2(200) not null,
  KIEM_NHIEM                     NUMBER default 0 not null,
  DUOC_PHAN_CONG_THU_LY          NUMBER default 0 not null,
  DUOC_DUYET_HO_SO               NUMBER default 0 not null,
  TRANG_THAI_THUOC_TO_CHUYEN_MON NUMBER default 0 not null,
  TU_NGAY                        DATE not null,
  DEN_NGAY                       DATE,
  STT_THUOC_TO_CHUYEN_MON        NUMBER default 100 not null,
  TRANG_THAI                     NUMBER default 0 not null,
  NGUOI_CAP_NHAT                 NUMBER,
  NGAY_CAP_NHAT                  DATE
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.CB_THUOC_TO_CHUYEN_MON
  add primary key (MA_CAN_BO, MA_TO_CHUYEN_MON, TU_NGAY)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.CB_THUOC_TO_CHUYEN_MON
  add foreign key (MA_TO_CHUYEN_MON)
  references HAI.CB_TO_CHUYEN_MON (MA_TO_CHUYEN_MON);
alter table HAI.CB_THUOC_TO_CHUYEN_MON
  add foreign key (MA_CHUC_VU)
  references HAI.DM_CHUC_VU (MA_CHUC_VU);

prompt
prompt Creating table DC_BIEN_DONG
prompt ===========================
prompt
create table HAI.DC_BIEN_DONG
(
  ID_DONG       NUMBER not null,
  TEN_BIEN_DONG NVARCHAR2(500) not null,
  LOAI          NVARCHAR2(200),
  TRANG_THAI    INTEGER
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_BIEN_DONG
  add primary key (ID_DONG)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DC_CAP_QUAN_LY
prompt =============================
prompt
create table HAI.DC_CAP_QUAN_LY
(
  MA_CAP_QUAN_LY  INTEGER not null,
  TEN_CAP_QUAN_LY NVARCHAR2(200) not null,
  TRANG_THAI      INTEGER
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_CAP_QUAN_LY
  add primary key (MA_CAP_QUAN_LY)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DC_CHUYEN_DICH_LOAI_DAT
prompt ======================================
prompt
create table HAI.DC_CHUYEN_DICH_LOAI_DAT
(
  MA_CD_DAT        INTEGER not null,
  MA_QUAN_HUYEN    NVARCHAR2(200) not null,
  MA_LOAI_DAT      NVARCHAR2(200) not null,
  NAM_CAP_NHAT     DATE not null,
  C_THUA_DAT_KK    INTEGER not null,
  C_THUA_DAT_KK_LT INTEGER not null,
  S_THUA_DAT_KK    FLOAT not null,
  S_THUA_DAT_KK_LT FLOAT not null,
  C_THUA_DAT_XD    INTEGER not null,
  C_THUA_DAT_XD_LT INTEGER not null,
  S_THUA_DAT_XD    FLOAT not null,
  S_THUA_DAT_XD_LT FLOAT not null,
  GHI_CHU_B3       NVARCHAR2(250),
  S_CAN_CAP        FLOAT,
  S_CAN_CAP_TC     FLOAT,
  S_CAN_CAP_CN     FLOAT,
  C_GCN            INTEGER not null,
  C_GCN_LT         INTEGER not null,
  C_GCN_TC         INTEGER not null,
  C_GCN_TC_LT      INTEGER not null,
  C_GCN_CN         INTEGER not null,
  C_GCN_CN_LT      INTEGER not null,
  S_GCN            INTEGER not null,
  S_GCN_LT         INTEGER not null,
  S_GCN_TC         INTEGER not null,
  S_GCN_TC_LT      INTEGER not null,
  S_GCN_CN         INTEGER not null,
  S_GCN_CN_LT      INTEGER not null,
  C_GCN_NGUOI      INTEGER not null,
  GHI_CHU_B2       NVARCHAR2(250)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_CHUYEN_DICH_LOAI_DAT
  add primary key (MA_CD_DAT)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DC_CHUYEN_DICH_MUC_DICH_SD_DAT
prompt =============================================
prompt
create table HAI.DC_CHUYEN_DICH_MUC_DICH_SD_DAT
(
  MA_CD_MUC_DICH  NVARCHAR2(200) not null,
  TEN_CD_MUC_DICH NVARCHAR2(500) not null,
  LA_NOI_BO       INTEGER not null,
  STT_CD_MUC_DICH INTEGER not null,
  TT_CD_MUC_DICH  INTEGER not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_CHUYEN_DICH_MUC_DICH_SD_DAT
  add primary key (MA_CD_MUC_DICH)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DC_CSDL_DAT
prompt ==========================
prompt
create table HAI.DC_CSDL_DAT
(
  MA_CSDL_DAT  NVARCHAR2(200) not null,
  TEN_CSDL_DAT NVARCHAR2(200) not null,
  STT_CSDL_DAT INTEGER not null,
  TT_CSDL_DAT  INTEGER not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_CSDL_DAT
  add primary key (MA_CSDL_DAT)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DC_DAT_HUYEN
prompt ===========================
prompt
create table HAI.DC_DAT_HUYEN
(
  MA_DAT_HUYEN       NUMBER not null,
  NAM_CAP_NHAT       DATE not null,
  DIEN_TICH_TU_NHIEN FLOAT not null,
  DIEN_TICH_DO_DAC   FLOAT not null,
  MA_QUAN_HUYEN      NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_DAT_HUYEN
  add primary key (MA_DAT_HUYEN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_DAT_HUYEN
  add constraint FK_DAT_HUYEN_QUAN_HUYEN foreign key (MA_QUAN_HUYEN)
  references HAI.DM_QUAN_HUYEN (MA_QUAN_HUYEN);

prompt
prompt Creating table DC_DOI_TUONG
prompt ===========================
prompt
create table HAI.DC_DOI_TUONG
(
  MA_DOI_TUONG  INTEGER not null,
  TEN_DOI_TUONG NVARCHAR2(200) not null,
  TRANG_THAI    INTEGER,
  MA            NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_DOI_TUONG
  add primary key (MA_DOI_TUONG)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DC_GIAO_DICH
prompt ===========================
prompt
create table HAI.DC_GIAO_DICH
(
  MA_GIAO_DICH  NVARCHAR2(250) not null,
  TEN_GIAO_DICH NVARCHAR2(250) not null,
  STT_GIAO_DICH INTEGER not null,
  TT_GIAO_DICH  INTEGER not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_GIAO_DICH
  add primary key (MA_GIAO_DICH)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DC_HINH_THUC
prompt ===========================
prompt
create table HAI.DC_HINH_THUC
(
  MA_HINH_THUC  NVARCHAR2(200) not null,
  TEN_HINH_THUC NVARCHAR2(750) not null,
  STT_HINH_THUC INTEGER not null,
  TT_HINH_THUC  INTEGER not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_HINH_THUC
  add primary key (MA_HINH_THUC)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DC_HO_SO_DAT
prompt ===========================
prompt
create table HAI.DC_HO_SO_DAT
(
  MA_HS_DAT               NUMBER not null,
  TEN_DON_VI              NVARCHAR2(500) not null,
  DIEN_TICH_SD            FLOAT,
  PHUONG_THUC_THANH_TOAN  NVARCHAR2(150),
  MA_MUC_DICH_SU_DUNG_DAT NVARCHAR2(200),
  THUOC_TO_CHUC           INTEGER not null,
  MA_QUOC_TICH            NVARCHAR2(200) not null,
  MA_THUA                 NUMBER,
  SDT                     NVARCHAR2(20),
  GHI_CHU                 NVARCHAR2(150),
  MA_HINH_THUC            NVARCHAR2(200),
  DAU_GIA                 INTEGER,
  TIEN_DAU_GIA            FLOAT,
  TRANG_THAI              NVARCHAR2(20),
  MA_QUAN_HUYEN           NVARCHAR2(200),
  ID_DONG                 NUMBER,
  TIEN_THUE               FLOAT,
  LY_DO                   NVARCHAR2(500),
  MA_DOI_TUONG            INTEGER,
  DON_VI_TO_CHUC_DAU_GIA  NVARCHAR2(500)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_HO_SO_DAT
  add primary key (MA_HS_DAT)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DC_LOAI_DAT
prompt ==========================
prompt
create table HAI.DC_LOAI_DAT
(
  MA_LOAI_DAT        NVARCHAR2(200) not null,
  TEN_LOAI_DAT       NVARCHAR2(250) not null,
  LA_DAT_NONG_NGHIEP INTEGER not null,
  STT_LOAI_DAT       INTEGER not null,
  TT_LOAI_DAT        INTEGER not null,
  MA                 NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_LOAI_DAT
  add primary key (MA_LOAI_DAT)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DC_LOAI_LUY_TIEN
prompt ===============================
prompt
create table HAI.DC_LOAI_LUY_TIEN
(
  MA_LOAI_LUY_TIEN  NVARCHAR2(200) not null,
  TEN_LOAI_LUY_TIEN NVARCHAR2(200) not null,
  STT_LOAI_LUY_TIEN INTEGER not null,
  TT_LOAI_LUY_TIEN  INTEGER not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_LOAI_LUY_TIEN
  add primary key (MA_LOAI_LUY_TIEN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DC_LOAI_VAN_BAN
prompt ==============================
prompt
create table HAI.DC_LOAI_VAN_BAN
(
  MA_LOAI_VAN_BAN  NVARCHAR2(200) not null,
  TEN_LOAI_VAN_BAN NVARCHAR2(200) not null,
  STT_LOAI_VAN_BAN INTEGER not null,
  TT_LOAI_VAN_BAN  INTEGER not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_LOAI_VAN_BAN
  add primary key (MA_LOAI_VAN_BAN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DC_LOG
prompt =====================
prompt
create table HAI.DC_LOG
(
  MA_LOG    INTEGER not null,
  MA_CAN_BO NUMBER,
  THAO_TAC  NVARCHAR2(500),
  THOI_GIAN DATE
)
tablespace USERS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_LOG
  add primary key (MA_LOG)
  using index 
  tablespace USERS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DC_THUADAT
prompt =========================
prompt
create table HAI.DC_THUADAT
(
  MA_THUA                 NUMBER not null,
  SO_THUA                 NVARCHAR2(500) not null,
  SO_THUA_GOC             NVARCHAR2(200) not null,
  MA_LOAI_DAT             NVARCHAR2(200) not null,
  MA_PHUONG_XA            NVARCHAR2(200) not null,
  ID_DONG                 NUMBER,
  TRANG_THAI_SD           INTEGER,
  MA_MUC_DICH_SU_DUNG_DAT NVARCHAR2(200),
  MA_HINH_THUC            NVARCHAR2(200),
  HINH_ANH                NVARCHAR2(500)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_THUADAT
  add primary key (MA_THUA)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_THUADAT
  add constraint FK_THUA_DAT_LOAI_DAT foreign key (MA_LOAI_DAT)
  references HAI.DC_LOAI_DAT (MA_LOAI_DAT);
alter table HAI.DC_THUADAT
  add constraint FK_THUA_DAT_PHUONG_XA foreign key (MA_PHUONG_XA)
  references HAI.DM_PHUONG_XA (MA_PHUONG_XA);

prompt
prompt Creating table DC_LUY_TIEN
prompt ==========================
prompt
create table HAI.DC_LUY_TIEN
(
  MA_LUY_TIEN      NUMBER not null,
  NAM_CAP_PHAT     DATE not null,
  DIEN_TICH_THUA   FLOAT,
  TOA_DO           NVARCHAR2(50),
  LA_DAT_CONG      INTEGER,
  TO_BAN_DO        NVARCHAR2(20),
  LA_THUOC_TO_CHUC NVARCHAR2(50),
  SO_GCN_DAT       NVARCHAR2(50),
  KET_QUA_XD       NVARCHAR2(50),
  MA_THUA          INTEGER not null,
  MA_LOAI_LUY_TIEN NVARCHAR2(200) not null,
  DK_KE_KHAI       INTEGER not null,
  VI_TRI           NVARCHAR2(500),
  NGUOI_DUNG       NVARCHAR2(500),
  THOI_HAN         NVARCHAR2(200),
  TG_BK            DATE,
  TG_KT            DATE,
  SU_DUNG          INTEGER,
  MA_CAP_QUAN_LY   INTEGER
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_LUY_TIEN
  add primary key (MA_LUY_TIEN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_LUY_TIEN
  add constraint FK_LUY_TIEN_LOAI_LUY_TIEN foreign key (MA_LOAI_LUY_TIEN)
  references HAI.DC_LOAI_LUY_TIEN (MA_LOAI_LUY_TIEN);
alter table HAI.DC_LUY_TIEN
  add constraint FK_LUY_TIEN_THUA_DAT foreign key (MA_THUA)
  references HAI.DC_THUADAT (MA_THUA);

prompt
prompt Creating table DC_MUC_DICH_SU_DUNG_DAT
prompt ======================================
prompt
create table HAI.DC_MUC_DICH_SU_DUNG_DAT
(
  MA_MUC_DICH_SU_DUNG_DAT  NVARCHAR2(200) not null,
  TEN_MUC_DICH_SU_DUNG_DAT NVARCHAR2(500) not null,
  LOAI_MUC_DICH_MUC_DICH   INTEGER not null,
  STT_MUC_DICH_SU_DUNG_DAT INTEGER not null,
  TT_MUC_DICH_SU_DUNG_DAT  INTEGER not null,
  CHUYEN_MUC_DICH          NVARCHAR2(200),
  MA                       NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_MUC_DICH_SU_DUNG_DAT
  add primary key (MA_MUC_DICH_SU_DUNG_DAT)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DC_PHAN_QUYEN
prompt ============================
prompt
create table HAI.DC_PHAN_QUYEN
(
  MA_PHAN_QUYEN   INTEGER not null,
  TEN_PHAN_QUYEN  NVARCHAR2(200),
  LOAI_PHAN_QUYEN NVARCHAR2(200),
  MA_CAN_BO       INTEGER,
  TEN_QUYEN       NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_PHAN_QUYEN
  add primary key (MA_PHAN_QUYEN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DC_QH_CSDL
prompt =========================
prompt
create table HAI.DC_QH_CSDL
(
  MA_QH_CSDL   NVARCHAR2(200) not null,
  NAMCAPNHAT   DATE not null,
  MA_PHUONG_XA NVARCHAR2(200) not null,
  MA_CSDL_DAT  NVARCHAR2(200) not null,
  TRANG_THAI   INTEGER not null,
  SO_THUA      INTEGER
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_QH_CSDL
  add primary key (MA_QH_CSDL)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_QH_CSDL
  add constraint FK_QH_CSDL_CSDL_DAT foreign key (MA_CSDL_DAT)
  references HAI.DC_CSDL_DAT (MA_CSDL_DAT);
alter table HAI.DC_QH_CSDL
  add constraint FK_QH_CSDL_XA foreign key (MA_PHUONG_XA)
  references HAI.DM_PHUONG_XA (MA_PHUONG_XA);

prompt
prompt Creating table DC_QH_MUC_DICH_SD
prompt ================================
prompt
create table HAI.DC_QH_MUC_DICH_SD
(
  MA_QH_MUC_DICH_SD NVARCHAR2(200) not null,
  NAM_CAP_NHAT      DATE not null,
  MA_CD_MUC_DICH    NVARCHAR2(200) not null,
  DIEN_TICH         FLOAT not null,
  MA_QUAN_HUYEN     NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_QH_MUC_DICH_SD
  add primary key (MA_QH_MUC_DICH_SD)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_QH_MUC_DICH_SD
  add constraint FK_CD_SD_DAT_DC_QH_MUC_DICH_SD foreign key (MA_CD_MUC_DICH)
  references HAI.DC_CHUYEN_DICH_MUC_DICH_SD_DAT (MA_CD_MUC_DICH);
alter table HAI.DC_QH_MUC_DICH_SD
  add constraint FK_THUA_DAT_QH_MUC_DICH_SD foreign key (MA_QUAN_HUYEN)
  references HAI.DM_QUAN_HUYEN (MA_QUAN_HUYEN);

prompt
prompt Creating table DC_SU_DUNG_DAT
prompt =============================
prompt
create table HAI.DC_SU_DUNG_DAT
(
  MA_SU_DUNG_DAT NUMBER not null,
  NGAY_SD_DAT    DATE,
  GHI_CHU_HSD    NVARCHAR2(500),
  THANH_TIEN_SDD FLOAT,
  MA_HS_DAT      NUMBER not null,
  MA_GIAO_DICH   NVARCHAR2(250),
  DON_GIA        FLOAT
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_SU_DUNG_DAT
  add primary key (MA_SU_DUNG_DAT)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_SU_DUNG_DAT
  add constraint FK_SU_DUNG_DAT_GIAO_DICH foreign key (MA_GIAO_DICH)
  references HAI.DC_GIAO_DICH (MA_GIAO_DICH);

prompt
prompt Creating table DC_VANBAN_SDD
prompt ============================
prompt
create table HAI.DC_VANBAN_SDD
(
  MA_HS            NUMBER not null,
  TIEU_DE_HS       NVARCHAR2(500) not null,
  TOM_TAT_HS       NVARCHAR2(100),
  FILE_HS          NVARCHAR2(350),
  NGAY_BAN_HANH    DATE,
  CO_QUAN_BAN_HANH NVARCHAR2(500),
  MA_LOAI_VAN_BAN  NVARCHAR2(200),
  MA_HS_DAT        NUMBER,
  NGAY_UP          DATE,
  NGUOI_UP         NVARCHAR2(100),
  SO_KY_HIEU       NVARCHAR2(100),
  SO_TRANG         INTEGER,
  TT_VAN_BAN       INTEGER
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_VANBAN_SDD
  add primary key (MA_HS)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DC_VANBAN_SDD
  add constraint FK_VLOAI_VB_VAN_BAN foreign key (MA_LOAI_VAN_BAN)
  references HAI.DC_LOAI_VAN_BAN (MA_LOAI_VAN_BAN);

prompt
prompt Creating table DM_DAN_TOC
prompt =========================
prompt
create table HAI.DM_DAN_TOC
(
  MA_DAN_TOC  NVARCHAR2(200) not null,
  TEN_DAN_TOC NVARCHAR2(200) not null,
  STT_DAN_TOC INTEGER default 100 not null,
  TT_DAN_TOC  INTEGER default 0 not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_DAN_TOC
  add primary key (MA_DAN_TOC)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_DAN_TOC
  add unique (TEN_DAN_TOC)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DM_HUONG_GIAI_QUYET
prompt ==================================
prompt
create table HAI.DM_HUONG_GIAI_QUYET
(
  MA_HUONG_GIAI_QUYET  NVARCHAR2(200) not null,
  TEN_HUONG_GIAI_QUYET NVARCHAR2(200) not null,
  STT_HUONG_GIAI_QUYET INTEGER default 100 not null,
  TT_HUONG_GIAI_QUYET  INTEGER default 0 not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_HUONG_GIAI_QUYET
  add primary key (MA_HUONG_GIAI_QUYET)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_HUONG_GIAI_QUYET
  add unique (TEN_HUONG_GIAI_QUYET)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DM_LINH_VUC_KNTC
prompt ===============================
prompt
create table HAI.DM_LINH_VUC_KNTC
(
  MA_LINH_VUC_KNTC  NVARCHAR2(200) not null,
  TEN_LINH_VUC_KNTC NVARCHAR2(200) not null,
  STT_LINH_VUC_KNTC INTEGER default 100 not null,
  TT_LINH_VUC_KNTC  INTEGER default 0 not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_LINH_VUC_KNTC
  add primary key (MA_LINH_VUC_KNTC)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_LINH_VUC_KNTC
  add unique (TEN_LINH_VUC_KNTC)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DM_LOAI_DTBKNTC
prompt ==============================
prompt
create table HAI.DM_LOAI_DTBKNTC
(
  MA_LOAI_DTBKNTC  NVARCHAR2(200) not null,
  TEN_LOAI_DTBKNTC NVARCHAR2(200) not null,
  STT_LOAI_DTBKNTC INTEGER default 100 not null,
  TT_LOAI_DTBKNTC  INTEGER default 0 not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_LOAI_DTBKNTC
  add primary key (MA_LOAI_DTBKNTC)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_LOAI_DTBKNTC
  add unique (TEN_LOAI_DTBKNTC)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DM_LOAI_DTKNTC
prompt =============================
prompt
create table HAI.DM_LOAI_DTKNTC
(
  MA_LOAI_DTKNTC  NVARCHAR2(200) not null,
  TEN_LOAI_DTKNTC NVARCHAR2(200) not null,
  STT_LOAI_DTKNTC INTEGER default 100 not null,
  TT_LOAI_DTKNTC  INTEGER default 0 not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_LOAI_DTKNTC
  add primary key (MA_LOAI_DTKNTC)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_LOAI_DTKNTC
  add unique (TEN_LOAI_DTKNTC)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DM_LOAI_KET_QUA
prompt ==============================
prompt
create table HAI.DM_LOAI_KET_QUA
(
  MA_LOAI_KET_QUA  NVARCHAR2(200) not null,
  TEN_LOAI_KET_QUA NVARCHAR2(200) not null,
  STT_LOAI_KET_QUA INTEGER default 100 not null,
  TT_LOAI_KET_QUA  INTEGER default 0 not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_LOAI_KET_QUA
  add primary key (MA_LOAI_KET_QUA)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_LOAI_KET_QUA
  add unique (TEN_LOAI_KET_QUA)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DM_LOAI_KNTC
prompt ===========================
prompt
create table HAI.DM_LOAI_KNTC
(
  MA_LOAI_KNTC  NVARCHAR2(200) not null,
  TEN_LOAI_KNTC NVARCHAR2(200) not null,
  STT_LOAI_KNTC INTEGER default 100 not null,
  TT_LOAI_KNTC  INTEGER default 0 not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_LOAI_KNTC
  add primary key (MA_LOAI_KNTC)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_LOAI_KNTC
  add unique (TEN_LOAI_KNTC)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DM_LOAI_VAN_BAN
prompt ==============================
prompt
create table HAI.DM_LOAI_VAN_BAN
(
  MA_LOAI_VAN_BAN  NVARCHAR2(200) not null,
  TEN_LOAI_VAN_BAN NVARCHAR2(200) not null,
  STT_LOAI_VAN_BAN INTEGER default 100 not null,
  TT_LOAI_VAN_BAN  INTEGER default 0 not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_LOAI_VAN_BAN
  add primary key (MA_LOAI_VAN_BAN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_LOAI_VAN_BAN
  add unique (TEN_LOAI_VAN_BAN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DM_LOP_TAP_HUAN
prompt ==============================
prompt
create table HAI.DM_LOP_TAP_HUAN
(
  MA_LOP_TAP_HUAN  INTEGER not null,
  TEN_LOP_TAP_HUAN NVARCHAR2(2000),
  NGAY_LAP         NVARCHAR2(200),
  MA_CO_QUAN       NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_LOP_TAP_HUAN
  add primary key (MA_LOP_TAP_HUAN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_LOP_TAP_HUAN
  add foreign key (MA_CO_QUAN)
  references HAI.CB_CO_QUAN (MA_CO_QUAN);

prompt
prompt Creating table DM_MUC_DICH_VAN_BAN
prompt ==================================
prompt
create table HAI.DM_MUC_DICH_VAN_BAN
(
  MA_MUC_DICH_VAN_BAN  NVARCHAR2(200) not null,
  TEN_MUC_DICH_VAN_BAN NVARCHAR2(200) not null,
  STT_MUC_DICH_VAN_BAN INTEGER default 100 not null,
  TT_MUC_DICH_VAN_BAN  INTEGER default 0 not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_MUC_DICH_VAN_BAN
  add primary key (MA_MUC_DICH_VAN_BAN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_MUC_DICH_VAN_BAN
  add unique (TEN_MUC_DICH_VAN_BAN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DM_NGUON_DON_DEN
prompt ===============================
prompt
create table HAI.DM_NGUON_DON_DEN
(
  MA_NGUON_DON_DEN  NVARCHAR2(200) not null,
  TEN_NGUON_DON_DEN NVARCHAR2(200) not null,
  STT_NGUON_DON_DEN INTEGER default 100 not null,
  TT_NGUON_DON_DEN  INTEGER default 0 not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_NGUON_DON_DEN
  add primary key (MA_NGUON_DON_DEN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_NGUON_DON_DEN
  add unique (TEN_NGUON_DON_DEN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DM_QUOC_TICH
prompt ===========================
prompt
create table HAI.DM_QUOC_TICH
(
  MA_QUOC_TICH  NVARCHAR2(200) not null,
  TEN_QUOC_TICH NVARCHAR2(200) not null,
  STT_QUOC_TICH INTEGER default 100 not null,
  TT_QUOC_TICH  INTEGER default 0 not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_QUOC_TICH
  add primary key (MA_QUOC_TICH)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_QUOC_TICH
  add unique (TEN_QUOC_TICH)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DM_THAM_QUYEN
prompt ============================
prompt
create table HAI.DM_THAM_QUYEN
(
  MA_THAM_QUYEN  NVARCHAR2(200) not null,
  TEN_THAM_QUYEN NVARCHAR2(200) not null,
  STT_THAM_QUYEN INTEGER default 100 not null,
  TT_THAM_QUYEN  INTEGER default 0 not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_THAM_QUYEN
  add primary key (MA_THAM_QUYEN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_THAM_QUYEN
  add unique (TEN_THAM_QUYEN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DM_TON_GIAO
prompt ==========================
prompt
create table HAI.DM_TON_GIAO
(
  MA_TON_GIAO  NVARCHAR2(200) not null,
  TEN_TON_GIAO NVARCHAR2(200) not null,
  STT_TON_GIAO INTEGER default 100 not null,
  TT_TON_GIAO  INTEGER default 0 not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_TON_GIAO
  add primary key (MA_TON_GIAO)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_TON_GIAO
  add unique (TEN_TON_GIAO)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table DM_TRANG_THAI_GIAI_QUYET
prompt =======================================
prompt
create table HAI.DM_TRANG_THAI_GIAI_QUYET
(
  MA_TRANG_THAI_GIAI_QUYET  NVARCHAR2(200) not null,
  TEN_TRANG_THAI_GIAI_QUYET NVARCHAR2(200) not null,
  STT_TRANG_THAI_GIAI_QUYET INTEGER default 100 not null,
  TT_TRANG_THAI_GIAI_QUYET  INTEGER default 0 not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_TRANG_THAI_GIAI_QUYET
  add primary key (MA_TRANG_THAI_GIAI_QUYET)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.DM_TRANG_THAI_GIAI_QUYET
  add unique (TEN_TRANG_THAI_GIAI_QUYET)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table KNTC_HO_SO
prompt =========================
prompt
create table HAI.KNTC_HO_SO
(
  MA_HO_SO_KNTC            INTEGER not null,
  SO_HO_SO_KNTC            INTEGER not null,
  NGAY_NHAP                DATE not null,
  NGAY_TIEP_DAN            NVARCHAR2(30) not null,
  VU_VIEC_MOI              INTEGER default 1 not null,
  NOI_DUNG_TIEP_DAN        NVARCHAR2(2000),
  YEU_CAU_GAP_LD           INTEGER default 0 not null,
  MA_LD_TIEP_DAN           INTEGER,
  Y_KIEN_LD                NVARCHAR2(2000),
  MA_CAN_BO_TIEP_DAN       INTEGER not null,
  MA_CO_QUAN_TIEP_DAN      NVARCHAR2(200) not null,
  MA_LINH_VUC_KNTC         NVARCHAR2(200) not null,
  MA_LOAI_KNTC             NVARCHAR2(200) not null,
  KNTC_MA_LOAI_DT          NVARCHAR2(200) not null,
  KNTC_CMND                NVARCHAR2(200),
  KNTC_HO_VA_TEN           NVARCHAR2(200) not null,
  KNTC_MA_PHUONG_XA        NVARCHAR2(200) not null,
  KNTC_SO_NHA              NVARCHAR2(200),
  KNTC_TEN_CQTC            NVARCHAR2(200),
  KNTC_DIA_CHI_CQTC        NVARCHAR2(200),
  KNTC_SO_NGUOI_DAI_DIEN   INTEGER default 1 not null,
  KNTC_TEN_NHUNG_NGUOI_DD  NVARCHAR2(200),
  BKNTC_MA_LOAI_DT         NVARCHAR2(200) default 'CN' not null,
  BKNTC_HO_VA_TEN          NVARCHAR2(200),
  BKNTC_DIA_CHI            NVARCHAR2(200),
  BKNTC_TEN_CQTC           NVARCHAR2(200),
  BKNTC_DIA_CHI_CQTC       NVARCHAR2(200),
  MA_NGUON_DON_DEN         NVARCHAR2(200),
  MA_DON_VI_XU_LY_CHINH    NVARCHAR2(200) not null,
  MA_CAN_BO_XU_LY_CHINH    INTEGER,
  MA_HUONG_GIAI_QUYET      NVARCHAR2(200),
  MA_CO_QUAN_CHUYEN_DON    NVARCHAR2(200),
  ND_HUONG_DAN_TRA_DON     NVARCHAR2(2000),
  NOI_DUNG_GHI_TREN_DON    NVARCHAR2(2000),
  LY_DO_KHONG_DU_DKXL      NVARCHAR2(2000),
  TT_TIEP_DAN              INTEGER default 0 not null,
  MA_TRANG_THAI_GIAI_QUYET NVARCHAR2(200) default 'CGQ' not null,
  NGAY_GIAI_QUYET          NVARCHAR2(30),
  MA_HO_SO_KNTC_GOC        INTEGER,
  NGAY_YCGLD               NVARCHAR2(30)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
comment on column HAI.KNTC_HO_SO.MA_NGUON_DON_DEN
  is 'not null thì là có đơn thư';
alter table HAI.KNTC_HO_SO
  add primary key (MA_HO_SO_KNTC)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.KNTC_HO_SO
  add unique (SO_HO_SO_KNTC)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.KNTC_HO_SO
  add foreign key (MA_LD_TIEP_DAN)
  references HAI.CB_CAN_BO (MA_CAN_BO);
alter table HAI.KNTC_HO_SO
  add foreign key (MA_CAN_BO_TIEP_DAN)
  references HAI.CB_CAN_BO (MA_CAN_BO);
alter table HAI.KNTC_HO_SO
  add foreign key (MA_CO_QUAN_TIEP_DAN)
  references HAI.CB_CO_QUAN (MA_CO_QUAN);
alter table HAI.KNTC_HO_SO
  add foreign key (MA_LINH_VUC_KNTC)
  references HAI.DM_LINH_VUC_KNTC (MA_LINH_VUC_KNTC);
alter table HAI.KNTC_HO_SO
  add foreign key (MA_LOAI_KNTC)
  references HAI.DM_LOAI_KNTC (MA_LOAI_KNTC);
alter table HAI.KNTC_HO_SO
  add foreign key (KNTC_MA_LOAI_DT)
  references HAI.DM_LOAI_DTKNTC (MA_LOAI_DTKNTC);
alter table HAI.KNTC_HO_SO
  add foreign key (KNTC_MA_PHUONG_XA)
  references HAI.DM_PHUONG_XA (MA_PHUONG_XA);
alter table HAI.KNTC_HO_SO
  add foreign key (BKNTC_MA_LOAI_DT)
  references HAI.DM_LOAI_DTBKNTC (MA_LOAI_DTBKNTC);
alter table HAI.KNTC_HO_SO
  add foreign key (MA_NGUON_DON_DEN)
  references HAI.DM_NGUON_DON_DEN (MA_NGUON_DON_DEN);
alter table HAI.KNTC_HO_SO
  add foreign key (MA_DON_VI_XU_LY_CHINH)
  references HAI.CB_DON_VI (MA_DON_VI);
alter table HAI.KNTC_HO_SO
  add foreign key (MA_CAN_BO_XU_LY_CHINH)
  references HAI.CB_CAN_BO (MA_CAN_BO);
alter table HAI.KNTC_HO_SO
  add foreign key (MA_HUONG_GIAI_QUYET)
  references HAI.DM_HUONG_GIAI_QUYET (MA_HUONG_GIAI_QUYET);
alter table HAI.KNTC_HO_SO
  add foreign key (MA_CO_QUAN_CHUYEN_DON)
  references HAI.CB_CO_QUAN (MA_CO_QUAN);
alter table HAI.KNTC_HO_SO
  add foreign key (MA_TRANG_THAI_GIAI_QUYET)
  references HAI.DM_TRANG_THAI_GIAI_QUYET (MA_TRANG_THAI_GIAI_QUYET);
alter table HAI.KNTC_HO_SO
  add foreign key (MA_HO_SO_KNTC_GOC)
  references HAI.KNTC_HO_SO (MA_HO_SO_KNTC);

prompt
prompt Creating table KNTC_GIAI_QUYET
prompt ==============================
prompt
create table HAI.KNTC_GIAI_QUYET
(
  MA_GIAI_QUYET          INTEGER not null,
  MA_HO_SO_KNTC          INTEGER not null,
  MA_CAN_BO              INTEGER not null,
  NGAY_GIAI_QUYET        NVARCHAR2(30),
  MA_HUONG_GIAI_QUYET    NVARCHAR2(200) not null,
  NOI_DUNG_GIAI_QUYET    NVARCHAR2(2000),
  FILE_VAN_BAN           NVARCHAR2(200),
  SO_KY_HIEU             NVARCHAR2(50),
  TRICH_YEU              NVARCHAR2(500),
  CO_QUAN_BAN_HANH       NVARCHAR2(200),
  SO_BUT_LUC             NVARCHAR2(30),
  SO_TRANG               NVARCHAR2(30),
  NGAY_TRINH_LANH_DAO_KY NVARCHAR2(30),
  NGAY_LANH_DAO_KY       NVARCHAR2(30),
  NGAY_CHUYEN_VAN_BAN    NVARCHAR2(30),
  MA_LANH_DAO_KY         INTEGER,
  LAN_GIAI_QUYET         INTEGER not null,
  LA_LAN_SAU_CUNG        INTEGER default 0 not null,
  TIEN_DO_XU_LY          NVARCHAR2(2000),
  DIEU_KIEN_XU_LY        INTEGER,
  THAM_QUYEN_GIAI_QUYET  INTEGER
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.KNTC_GIAI_QUYET
  add primary key (MA_GIAI_QUYET)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.KNTC_GIAI_QUYET
  add unique (MA_GIAI_QUYET, LAN_GIAI_QUYET)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.KNTC_GIAI_QUYET
  add foreign key (MA_HO_SO_KNTC)
  references HAI.KNTC_HO_SO (MA_HO_SO_KNTC);
alter table HAI.KNTC_GIAI_QUYET
  add foreign key (MA_CAN_BO)
  references HAI.CB_CAN_BO (MA_CAN_BO);
alter table HAI.KNTC_GIAI_QUYET
  add foreign key (MA_HUONG_GIAI_QUYET)
  references HAI.DM_HUONG_GIAI_QUYET (MA_HUONG_GIAI_QUYET);

prompt
prompt Creating table LICH_CONG_TAC
prompt ============================
prompt
create table HAI.LICH_CONG_TAC
(
  MA_CAN_BO          NUMBER,
  NGAY_CONG_TAC      NVARCHAR2(30),
  VAN_TAT            NVARCHAR2(50),
  NOI_DUNG_CONG_VIEC NVARCHAR2(1000),
  BUOI               INTEGER,
  NGAY_KET_THUC      NVARCHAR2(30),
  STT                NUMBER not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.LICH_CONG_TAC
  add primary key (STT)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.LICH_CONG_TAC
  add foreign key (MA_CAN_BO)
  references HAI.CB_CAN_BO (MA_CAN_BO);

prompt
prompt Creating table LICH_TRINH_PHE_DUYET
prompt ===================================
prompt
create table HAI.LICH_TRINH_PHE_DUYET
(
  NGAY_DU_KIEN   NVARCHAR2(30),
  NGAY_PHE_DUYET NVARCHAR2(30),
  MA_CAN_BO      NUMBER not null,
  MA_HO_SO_KNTC  INTEGER not null,
  TRANG_THAI     INTEGER
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255;
alter table HAI.LICH_TRINH_PHE_DUYET
  add primary key (MA_CAN_BO, MA_HO_SO_KNTC)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255;
alter table HAI.LICH_TRINH_PHE_DUYET
  add foreign key (MA_CAN_BO)
  references HAI.CB_CAN_BO (MA_CAN_BO);
alter table HAI.LICH_TRINH_PHE_DUYET
  add foreign key (MA_HO_SO_KNTC)
  references HAI.KNTC_HO_SO (MA_HO_SO_KNTC);

prompt
prompt Creating table PQ_CB_MENU
prompt =========================
prompt
create table HAI.PQ_CB_MENU
(
  MA_CB_MN  INTEGER not null,
  MA_CAN_BO NUMBER,
  MA_MENU   NVARCHAR2(200),
  THEM      INTEGER,
  SUA       INTEGER,
  XOA       INTEGER,
  XEM       INTEGER
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.PQ_CB_MENU
  add primary key (MA_CB_MN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table PQ_NHOM_QUYEN
prompt ============================
prompt
create table HAI.PQ_NHOM_QUYEN
(
  MA_NHOM_QUYEN  NVARCHAR2(200) not null,
  TEN_NHOM_QUYEN NVARCHAR2(200) not null,
  STT_NHOM_QUYEN NUMBER default 100 not null,
  TRANG_THAI     NUMBER default 0 not null,
  NGUOI_CAP_NHAT NUMBER,
  NGAY_CAP_NHAT  DATE,
  MA_CO_QUAN     NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.PQ_NHOM_QUYEN
  add primary key (MA_NHOM_QUYEN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.PQ_NHOM_QUYEN
  add foreign key (MA_CO_QUAN)
  references HAI.CB_CO_QUAN (MA_CO_QUAN);

prompt
prompt Creating table PQ_CO_NHOM_QUYEN
prompt ===============================
prompt
create table HAI.PQ_CO_NHOM_QUYEN
(
  MA_CAN_BO         NUMBER not null,
  MA_NHOM_QUYEN     NVARCHAR2(200) not null,
  STT_CO_NHOM_QUYEN NUMBER default 100 not null,
  TRANG_THAI        NUMBER default 0 not null,
  NGUOI_CAP_NHAT    NUMBER,
  NGAY_CAP_NHAT     DATE
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.PQ_CO_NHOM_QUYEN
  add primary key (MA_CAN_BO, MA_NHOM_QUYEN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.PQ_CO_NHOM_QUYEN
  add foreign key (MA_CAN_BO)
  references HAI.CB_CAN_BO (MA_CAN_BO);
alter table HAI.PQ_CO_NHOM_QUYEN
  add foreign key (MA_NHOM_QUYEN)
  references HAI.PQ_NHOM_QUYEN (MA_NHOM_QUYEN);

prompt
prompt Creating table PQ_MENU
prompt ======================
prompt
create table HAI.PQ_MENU
(
  MA_MENU        NVARCHAR2(200) not null,
  TEN_MENU       NVARCHAR2(200) not null,
  STT_MENU       NUMBER default 100 not null,
  TRANG_THAI     NUMBER default 0 not null,
  NGUOI_CAP_NHAT NUMBER,
  NGAY_CAP_NHAT  DATE,
  ICON_CLASS     NVARCHAR2(100)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.PQ_MENU
  add primary key (MA_MENU)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table PQ_QUYEN
prompt =======================
prompt
create table HAI.PQ_QUYEN
(
  MA_QUYEN           NVARCHAR2(200) not null,
  TEN_QUYEN          NVARCHAR2(200) not null,
  MA_MENU            NVARCHAR2(200) not null,
  APPS               NVARCHAR2(200) not null,
  MODULES            NVARCHAR2(200) not null,
  HIEN_THI_TREN_MENU NUMBER default 0 not null,
  STT_QUYEN          NUMBER default 100 not null,
  TRANG_THAI         NUMBER default 0 not null,
  NGUOI_CAP_NHAT     NUMBER,
  NGAY_CAP_NHAT      DATE,
  MA_CO_QUAN         NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.PQ_QUYEN
  add primary key (MA_QUYEN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.PQ_QUYEN
  add unique (APPS, MODULES)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.PQ_QUYEN
  add foreign key (MA_MENU)
  references HAI.PQ_MENU (MA_MENU);
alter table HAI.PQ_QUYEN
  add foreign key (MA_CO_QUAN)
  references HAI.CB_CO_QUAN (MA_CO_QUAN);

prompt
prompt Creating table PQ_CO_QUYEN
prompt ==========================
prompt
create table HAI.PQ_CO_QUYEN
(
  MA_NHOM_QUYEN      NVARCHAR2(200) not null,
  MA_QUYEN           NVARCHAR2(200) not null,
  STT_CO_QUYEN       NUMBER default 100 not null,
  TRANG_THAI         NUMBER default 0 not null,
  NGUOI_CAP_NHAT     NUMBER,
  NGAY_CAP_NHAT      DATE,
  TEN_QUYEN          NVARCHAR2(200),
  MA_MENU            NVARCHAR2(200),
  MODULES            NVARCHAR2(200),
  HIEN_THI_TREN_MENU NUMBER,
  STT_QUYEN          NUMBER,
  APPS               NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.PQ_CO_QUYEN
  add primary key (MA_NHOM_QUYEN, MA_QUYEN)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.PQ_CO_QUYEN
  add foreign key (MA_NHOM_QUYEN)
  references HAI.PQ_NHOM_QUYEN (MA_NHOM_QUYEN);
alter table HAI.PQ_CO_QUYEN
  add foreign key (MA_QUYEN)
  references HAI.PQ_QUYEN (MA_QUYEN);

prompt
prompt Creating table TT_CHUC_DANH
prompt ===========================
prompt
create table HAI.TT_CHUC_DANH
(
  MA_CHUC_DANH  NVARCHAR2(100) not null,
  TEN_CHUC_DANH NVARCHAR2(200),
  NGAY_CAP_NHAT NVARCHAR2(200),
  STT_HIEN_THI  INTEGER default 100,
  TRANG_THAI    INTEGER default 0
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_CHUC_DANH
  add primary key (MA_CHUC_DANH)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating table TT_LINH_VUC_THANH_TRA
prompt ====================================
prompt
create table HAI.TT_LINH_VUC_THANH_TRA
(
  MA_LINH_VUC_THANH_TRA  NVARCHAR2(200) not null,
  TEN_LINH_VUC_THANH_TRA NVARCHAR2(200),
  TRANG_THAI             INTEGER default 0,
  MA_CO_QUAN             NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_LINH_VUC_THANH_TRA
  add primary key (MA_LINH_VUC_THANH_TRA)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_LINH_VUC_THANH_TRA
  add foreign key (MA_CO_QUAN)
  references HAI.CB_CO_QUAN (MA_CO_QUAN);

prompt
prompt Creating table TT_DANG_VI_PHAM
prompt ==============================
prompt
create table HAI.TT_DANG_VI_PHAM
(
  MA_DANG_VI_PHAM       INTEGER not null,
  TEN_DANG_VI_PHAM      NVARCHAR2(1000),
  MA_LINH_VUC_THANH_TRA NVARCHAR2(200),
  MA_CO_QUAN            NVARCHAR2(200),
  STT_HIEN_THI          INTEGER
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_DANG_VI_PHAM
  add primary key (MA_DANG_VI_PHAM)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_DANG_VI_PHAM
  add foreign key (MA_LINH_VUC_THANH_TRA)
  references HAI.TT_LINH_VUC_THANH_TRA (MA_LINH_VUC_THANH_TRA);
alter table HAI.TT_DANG_VI_PHAM
  add foreign key (MA_CO_QUAN)
  references HAI.CB_CO_QUAN (MA_CO_QUAN);

prompt
prompt Creating table TT_DOAN_THANH_TRA
prompt ================================
prompt
create table HAI.TT_DOAN_THANH_TRA
(
  MA_DOAN_TT         INTEGER not null,
  TEN_DOAN_TT        NVARCHAR2(500),
  MUC_DICH_THANH_LAP NVARCHAR2(2000),
  NGAY_THANH_LAP     NVARCHAR2(200),
  NGAY_HET_HAN       NVARCHAR2(200),
  NGAY_GIA_HAN       NVARCHAR2(200),
  TRANG_THAI         INTEGER default 0,
  MA_CO_QUAN         NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_DOAN_THANH_TRA
  add primary key (MA_DOAN_TT)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_DOAN_THANH_TRA
  add constraint FK_MCQ foreign key (MA_CO_QUAN)
  references HAI.CB_CO_QUAN (MA_CO_QUAN);

prompt
prompt Creating table TT_DOAN_TT_CO_CAN_BO
prompt ===================================
prompt
create table HAI.TT_DOAN_TT_CO_CAN_BO
(
  MA_DOAN_TT    INTEGER not null,
  MA_CAN_BO     NUMBER not null,
  MA_CHUC_DANH  NVARCHAR2(100),
  NGAY_CAP_NHAT NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_DOAN_TT_CO_CAN_BO
  add primary key (MA_DOAN_TT, MA_CAN_BO)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_DOAN_TT_CO_CAN_BO
  add foreign key (MA_CHUC_DANH)
  references HAI.TT_CHUC_DANH (MA_CHUC_DANH);

prompt
prompt Creating table TT_QUYET_DINH
prompt ============================
prompt
create table HAI.TT_QUYET_DINH
(
  MA_QUYET_DINH  INTEGER not null,
  TEN_QUYET_DINH NVARCHAR2(200) not null,
  NOI_DUNG       NVARCHAR2(2000),
  FILE_DINH_KEM  NVARCHAR2(200),
  NGUOI_CAP_NHAT INTEGER default 0,
  NGAY_CAP_NHAT  NVARCHAR2(200),
  TRANG_THAI     INTEGER default 0,
  MA_CO_QUAN     NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_QUYET_DINH
  add primary key (MA_QUYET_DINH)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_QUYET_DINH
  add foreign key (MA_CO_QUAN)
  references HAI.CB_CO_QUAN (MA_CO_QUAN);

prompt
prompt Creating table TT_KE_HOACH_THANH_TRA
prompt ====================================
prompt
create table HAI.TT_KE_HOACH_THANH_TRA
(
  MA_KE_HOACH_TT    INTEGER not null,
  TEN_KE_HOACH_TT   NVARCHAR2(200),
  NGAY_LAP_KE_HOACH NVARCHAR2(200),
  FILE_DINH_KEM     NVARCHAR2(200),
  NGAY_CAP_NHAT     NVARCHAR2(200),
  TRANG_THAI        INTEGER default 0,
  MA_QUYET_DINH     INTEGER not null,
  MA_CO_QUAN        NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_KE_HOACH_THANH_TRA
  add primary key (MA_KE_HOACH_TT)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_KE_HOACH_THANH_TRA
  add constraint FK_QD foreign key (MA_QUYET_DINH)
  references HAI.TT_QUYET_DINH (MA_QUYET_DINH);
alter table HAI.TT_KE_HOACH_THANH_TRA
  add foreign key (MA_CO_QUAN)
  references HAI.CB_CO_QUAN (MA_CO_QUAN);

prompt
prompt Creating table TT_LOP_TAP_HUAN
prompt ==============================
prompt
create table HAI.TT_LOP_TAP_HUAN
(
  MA_LOP_TAP_HUAN INTEGER not null,
  NGAY_MO_LOP     NVARCHAR2(200) not null,
  SO_LUONG        INTEGER,
  SO_LUONG_DI_HOC INTEGER,
  GHI_CHU         NVARCHAR2(2000),
  TRANG_THAI      INTEGER default 0
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_LOP_TAP_HUAN
  add primary key (MA_LOP_TAP_HUAN, NGAY_MO_LOP)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_LOP_TAP_HUAN
  add foreign key (MA_LOP_TAP_HUAN)
  references HAI.DM_LOP_TAP_HUAN (MA_LOP_TAP_HUAN);

prompt
prompt Creating table TT_LY_DO_THANH_TRA_LAI
prompt =====================================
prompt
create table HAI.TT_LY_DO_THANH_TRA_LAI
(
  MA_LY_DO_TTL INTEGER,
  LY_DO_TTL    NVARCHAR2(2000),
  MA_CO_QUAN   NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_LY_DO_THANH_TRA_LAI
  add foreign key (MA_CO_QUAN)
  references HAI.CB_CO_QUAN (MA_CO_QUAN);

prompt
prompt Creating table TT_THANH_TRA
prompt ===========================
prompt
create table HAI.TT_THANH_TRA
(
  STT_THANH_TRA           INTEGER,
  SO_THANH_TRA            NVARCHAR2(50) not null,
  MA_KE_HOACH_TT          INTEGER,
  MA_DOAN_TT              INTEGER,
  NGAY_BD_THANH_TRA       NVARCHAR2(200),
  NGAY_KT_THANH_TRA       NVARCHAR2(200),
  NOI_DUNG_THANH_TRA      NVARCHAR2(2000),
  TEN_TO_CHUC_CA_NHAN     NVARCHAR2(200),
  DIA_CHI_TO_CHUC_CA_NHAN NVARCHAR2(500),
  KET_QUA_THANH_TRA       NVARCHAR2(2000),
  LY_DO_XU_PHAT           NVARCHAR2(2000),
  TAI_SAN_TICH_THU        NVARCHAR2(2000),
  SO_TIEN_TICH_THU        FLOAT,
  SO_TIEN_XU_PHAT         FLOAT,
  LOAI_HINH_DOANH_NGHIEP  INTEGER default 0,
  TAI_SAN_TIEU_HUY        NVARCHAR2(2000),
  SO_TIEN_TIEU_HUY        FLOAT,
  LOAI_HINH_THANH_TRA     NVARCHAR2(10),
  HINH_THUC_XU_PHAT       INTEGER,
  MA_CO_QUAN              NVARCHAR2(200),
  FILE_QUYET_DINH         NVARCHAR2(1000),
  NGAY_KY_QUYET_DINH      NVARCHAR2(200),
  FILE_NOI_DUNG_THANH_TRA NVARCHAR2(1000),
  SO_BIEN_BAN_VI_PHAM_HC  NVARCHAR2(200),
  NGAY_LAP_BIEN_BAN       NVARCHAR2(200),
  FILE_BIEN_BAN_VI_PHAM   NVARCHAR2(1000),
  SO_QUYET_DINH_XU_PHAT   NVARCHAR2(200),
  TRANG_THAI_NOP_PHAT     INTEGER
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_THANH_TRA
  add primary key (SO_THANH_TRA)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_THANH_TRA
  add foreign key (MA_KE_HOACH_TT)
  references HAI.TT_KE_HOACH_THANH_TRA (MA_KE_HOACH_TT);
alter table HAI.TT_THANH_TRA
  add foreign key (MA_DOAN_TT)
  references HAI.TT_DOAN_THANH_TRA (MA_DOAN_TT);
alter table HAI.TT_THANH_TRA
  add foreign key (MA_CO_QUAN)
  references HAI.CB_CO_QUAN (MA_CO_QUAN);

prompt
prompt Creating table TT_THANH_TRA_LINH_VUC
prompt ====================================
prompt
create table HAI.TT_THANH_TRA_LINH_VUC
(
  STT_THANH_TRA              INTEGER,
  SO_THANH_TRA               NVARCHAR2(50) not null,
  LOAI_HINH_THANH_TRA        NVARCHAR2(10),
  MA_KE_HOACH_TT             INTEGER,
  MA_DOAN_TT                 INTEGER,
  NGAY_BD_THANH_TRA          NVARCHAR2(200),
  NGAY_KT_THANH_TRA          NVARCHAR2(200),
  NOI_DUNG_THANH_TRA         NVARCHAR2(2000),
  TEN_TO_CHUC_CA_NHAN        NVARCHAR2(200),
  LOAI_HINH_DOANH_NGHIEP     INTEGER default 0,
  DIA_CHI_TO_CHUC_CA_NHAN    NVARCHAR2(500),
  MA_LINH_VUC_THANH_TRA      NVARCHAR2(200),
  KET_QUA_THANH_TRA          NVARCHAR2(2000),
  KIEN_NGHI_XU_LY            INTEGER,
  NOI_DUNG_XU_LY             NVARCHAR2(2000),
  KIEN_NGHI_THU_HOI          NVARCHAR2(2000),
  SO_TIEN_THU_HOI            FLOAT,
  KIEN_NGHI_KHAC             NVARCHAR2(2000),
  SO_TIEN_KHAC               FLOAT,
  MA_CO_QUAN                 NVARCHAR2(200),
  NOI_DUNG_KIEN_NGHI_XU_LY   NVARCHAR2(2000),
  KET_QUA_XU_LY              INTEGER,
  DAT_PHAI_THU               FLOAT,
  SO_TIEN_PHAI_THU           FLOAT,
  DAT_DA_THU                 FLOAT,
  SO_TIEN_DA_THU             FLOAT,
  NOI_DUNG_KIEN_NGHI_THU_HOI NVARCHAR2(2000),
  NOI_DUNG_KIEN_NGHI_KHAC    NVARCHAR2(2000),
  SO_TIEN_THAM_NHUNG         FLOAT,
  TAI_SAN_THAM_NHUNG         NVARCHAR2(2000),
  TS_QUY_DOI_THANH_TIEN      FLOAT,
  DAT_THAM_NHUNG             FLOAT,
  SO_NGUOI_LIEN_QUAN         INTEGER,
  FILE_QUYET_DINH            NVARCHAR2(1000),
  FILE_NOI_DUNG_THANH_TRA    NVARCHAR2(1000),
  NGAY_KY_QUYET_DINH         NVARCHAR2(200)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_THANH_TRA_LINH_VUC
  add primary key (SO_THANH_TRA)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_THANH_TRA_LINH_VUC
  add foreign key (MA_KE_HOACH_TT)
  references HAI.TT_KE_HOACH_THANH_TRA (MA_KE_HOACH_TT);
alter table HAI.TT_THANH_TRA_LINH_VUC
  add foreign key (MA_DOAN_TT)
  references HAI.TT_DOAN_THANH_TRA (MA_DOAN_TT);
alter table HAI.TT_THANH_TRA_LINH_VUC
  add foreign key (MA_LINH_VUC_THANH_TRA)
  references HAI.TT_LINH_VUC_THANH_TRA (MA_LINH_VUC_THANH_TRA);
alter table HAI.TT_THANH_TRA_LINH_VUC
  add foreign key (MA_CO_QUAN)
  references HAI.CB_CO_QUAN (MA_CO_QUAN);

prompt
prompt Creating table TT_THANH_TRA_CO_DANG_VI_PHAM
prompt ===========================================
prompt
create table HAI.TT_THANH_TRA_CO_DANG_VI_PHAM
(
  MA_DANG_VI_PHAM INTEGER not null,
  SO_THANH_TRA    NVARCHAR2(50) not null,
  VI_PHAM         FLOAT,
  GHI_CHU         NVARCHAR2(2000)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_THANH_TRA_CO_DANG_VI_PHAM
  add primary key (MA_DANG_VI_PHAM, SO_THANH_TRA)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_THANH_TRA_CO_DANG_VI_PHAM
  add foreign key (MA_DANG_VI_PHAM)
  references HAI.TT_DANG_VI_PHAM (MA_DANG_VI_PHAM);
alter table HAI.TT_THANH_TRA_CO_DANG_VI_PHAM
  add foreign key (SO_THANH_TRA)
  references HAI.TT_THANH_TRA_LINH_VUC (SO_THANH_TRA);

prompt
prompt Creating table TT_THANH_TRA_LAI
prompt ===============================
prompt
create table HAI.TT_THANH_TRA_LAI
(
  SO_THANH_TRA               NVARCHAR2(50) not null,
  NGAY_THANH_TRA_LAI         NVARCHAR2(200),
  LAN_THANH_TRA_LAI          INTEGER not null,
  LY_DO_THANH_TRA_LAI        NVARCHAR2(1000),
  KET_QUA_THANH_TRA_LAI      NVARCHAR2(2000),
  KIEN_NGHI_XU_LY            INTEGER,
  NOI_DUNG_KIEN_NGHI_XU_LY   NVARCHAR2(2000),
  NOI_DUNG_KIEN_NGHI_THU_HOI NVARCHAR2(2000),
  KIEN_NGHI_THU_HOI          NVARCHAR2(2000),
  SO_TIEN_THU_HOI            FLOAT,
  NOI_DUNG_KIEN_NGHI_KHAC    NVARCHAR2(2000),
  KIEN_NGHI_KHAC             NVARCHAR2(2000),
  SO_TIEN_KHAC               FLOAT,
  KET_QUA_XU_LY              INTEGER,
  NOI_DUNG_XU_LY             NVARCHAR2(2000),
  DAT_DA_THU                 FLOAT,
  SO_TIEN_DA_THU             FLOAT,
  NOI_DUNG_VI_PHAM_KINH_TE   NVARCHAR2(2000),
  DAT_VI_PHAM                INTEGER,
  SO_TIEN_VI_PHAM            FLOAT,
  SO_TIEN_THAM_NHUNG         FLOAT,
  TAI_SAN_THAM_NHUNG         NVARCHAR2(2000),
  TS_QUY_DOI_THANH_TIEN      FLOAT,
  DAT_THAM_NHUNG             FLOAT
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
alter table HAI.TT_THANH_TRA_LAI
  add primary key (SO_THANH_TRA, LAN_THANH_TRA_LAI)
  using index 
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );

prompt
prompt Creating sequence DC_BIEN_DONG_SEQ
prompt ==================================
prompt
create sequence HAI.DC_BIEN_DONG_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 61
increment by 1
cache 20;

prompt
prompt Creating sequence DC_CAP_QUAN_LY_SEQ
prompt ====================================
prompt
create sequence HAI.DC_CAP_QUAN_LY_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 21
increment by 1
cache 20;

prompt
prompt Creating sequence DC_CHUYEN_DICH_LOAI_DAT_SEQ
prompt =============================================
prompt
create sequence HAI.DC_CHUYEN_DICH_LOAI_DAT_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 61
increment by 1
cache 20;

prompt
prompt Creating sequence DC_DAT_HUYEN_SEQ
prompt ==================================
prompt
create sequence HAI.DC_DAT_HUYEN_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 121
increment by 1
cache 20;

prompt
prompt Creating sequence DC_DOI_TUONG_SEQ
prompt ==================================
prompt
create sequence HAI.DC_DOI_TUONG_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 21
increment by 1
cache 20;

prompt
prompt Creating sequence DC_GIAODICH_DAT_SEQ
prompt =====================================
prompt
create sequence HAI.DC_GIAODICH_DAT_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 281
increment by 1
cache 20;

prompt
prompt Creating sequence DC_HO_SO_DAT_SEQ
prompt ==================================
prompt
create sequence HAI.DC_HO_SO_DAT_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 701
increment by 1
cache 20;

prompt
prompt Creating sequence DC_LOAI_DAT_SEQ
prompt =================================
prompt
create sequence HAI.DC_LOAI_DAT_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 57
increment by 1
cache 20;

prompt
prompt Creating sequence DC_LOAI_LUY_TIEN_SEQ
prompt ======================================
prompt
create sequence HAI.DC_LOAI_LUY_TIEN_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 21
increment by 1
cache 20;

prompt
prompt Creating sequence DC_LOG_SEQ
prompt ============================
prompt
create sequence HAI.DC_LOG_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 81
increment by 1
cache 20;

prompt
prompt Creating sequence DC_LUY_TIEN_SEQ
prompt =================================
prompt
create sequence HAI.DC_LUY_TIEN_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 301
increment by 1
cache 20;

prompt
prompt Creating sequence DC_PHAN_QUYEN_SEQ
prompt ===================================
prompt
create sequence HAI.DC_PHAN_QUYEN_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 41
increment by 1
cache 20;

prompt
prompt Creating sequence DC_SU_DUNG_DAT_SEQ
prompt ====================================
prompt
create sequence HAI.DC_SU_DUNG_DAT_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 21
increment by 1
cache 20;

prompt
prompt Creating sequence DC_THUA_DAT_SEQ
prompt =================================
prompt
create sequence HAI.DC_THUA_DAT_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 261
increment by 1
cache 20;

prompt
prompt Creating sequence DC_VANBAN_SDD_SEQ
prompt ===================================
prompt
create sequence HAI.DC_VANBAN_SDD_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 321
increment by 1
cache 20;

prompt
prompt Creating sequence MA_GT_THUOC_TINH_SEQ
prompt ======================================
prompt
create sequence HAI.MA_GT_THUOC_TINH_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 861
increment by 1
cache 20;

prompt
prompt Creating sequence MA_HO_SO2_SEQ
prompt ===============================
prompt
create sequence HAI.MA_HO_SO2_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 921
increment by 1
cache 20;

prompt
prompt Creating sequence MA_HO_SO_SEQ
prompt ==============================
prompt
create sequence HAI.MA_HO_SO_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 201
increment by 1
cache 20;

prompt
prompt Creating sequence MA_HS2_SEQ
prompt ============================
prompt
create sequence HAI.MA_HS2_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 1
increment by 1
cache 20;

prompt
prompt Creating sequence MA_PHIEU_TIEP_NHAN_SEQ
prompt ========================================
prompt
create sequence HAI.MA_PHIEU_TIEP_NHAN_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 321
increment by 1
cache 20;

prompt
prompt Creating sequence MA_VBPL_SEQ
prompt =============================
prompt
create sequence HAI.MA_VBPL_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 101
increment by 1
cache 20;

prompt
prompt Creating sequence MA_VB_TIEP_NHAN_SEQ
prompt =====================================
prompt
create sequence HAI.MA_VB_TIEP_NHAN_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 2681
increment by 1
cache 20;

prompt
prompt Creating sequence PQ_CB_MENU_SEQ
prompt ================================
prompt
create sequence HAI.PQ_CB_MENU_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 41
increment by 1
cache 20;

prompt
prompt Creating sequence SEQ_CAN_BO
prompt ============================
prompt
create sequence HAI.SEQ_CAN_BO
minvalue 1
maxvalue 9999999999999999999999999999
start with 241
increment by 1
cache 20;

prompt
prompt Creating sequence SEQ_DM_LOP_TAP_HUAN
prompt =====================================
prompt
create sequence HAI.SEQ_DM_LOP_TAP_HUAN
minvalue 1
maxvalue 9999999999999999999999999999
start with 1
increment by 1
cache 20;

prompt
prompt Creating sequence SEQ_GIAI_QUYET
prompt ================================
prompt
create sequence HAI.SEQ_GIAI_QUYET
minvalue 1
maxvalue 9999999999999999999999999999
start with 221
increment by 1
cache 20;

prompt
prompt Creating sequence SEQ_KNTC_HO_SO
prompt ================================
prompt
create sequence HAI.SEQ_KNTC_HO_SO
minvalue 1
maxvalue 9999999999999999999999999999
start with 221
increment by 1
cache 20;

prompt
prompt Creating sequence SEQ_LICH_CONG_TAC
prompt ===================================
prompt
create sequence HAI.SEQ_LICH_CONG_TAC
minvalue 1
maxvalue 9999999999999999999999999999
start with 21
increment by 1
cache 20;

prompt
prompt Creating sequence SEQ_TO_CHUYEN_MON
prompt ===================================
prompt
create sequence HAI.SEQ_TO_CHUYEN_MON
minvalue 1
maxvalue 9999999999999999999999999999
start with 61
increment by 1
cache 20;

prompt
prompt Creating sequence SEQ_TT_DOAN_THANH_TRA
prompt =======================================
prompt
create sequence HAI.SEQ_TT_DOAN_THANH_TRA
minvalue 1
maxvalue 9999999999999999999999999999
start with 101
increment by 1
cache 20;

prompt
prompt Creating sequence SEQ_TT_KE_HOACH_TT
prompt ====================================
prompt
create sequence HAI.SEQ_TT_KE_HOACH_TT
minvalue 1
maxvalue 9999999999999999999999999999
start with 81
increment by 1
cache 20;

prompt
prompt Creating sequence SEQ_TT_QUYET_DINH
prompt ===================================
prompt
create sequence HAI.SEQ_TT_QUYET_DINH
minvalue 1
maxvalue 9999999999999999999999999999
start with 101
increment by 1
cache 20;

prompt
prompt Creating sequence SEQ_TT_THANH_TRA
prompt ==================================
prompt
create sequence HAI.SEQ_TT_THANH_TRA
minvalue 1
maxvalue 9999999999999999999999999999
start with 141
increment by 1
cache 20;

prompt
prompt Creating sequence SEQ_TT_THANH_TRA_LINH_VUC
prompt ===========================================
prompt
create sequence HAI.SEQ_TT_THANH_TRA_LINH_VUC
minvalue 1
maxvalue 9999999999999999999999999999
start with 141
increment by 1
cache 20;

prompt
prompt Creating sequence SEQ_XAC_MINH
prompt ==============================
prompt
create sequence HAI.SEQ_XAC_MINH
minvalue 1
maxvalue 9999999999999999999999999999
start with 1
increment by 1
cache 20;

prompt
prompt Creating package KNTC
prompt =====================
prompt
CREATE OR REPLACE PACKAGE HAI.KNTC IS
  TYPE MYCUR IS REF CURSOR;
  -------------------------------------------------------------------------------
  PROCEDURE SO_TIEP_DAN( P_CUR IN OUT MYCUR,
                                        P_SO_HO_SO_KNTC NVARCHAR2,
                                        P_MA_LINH_VUC_KNTC NVARCHAR2,
                                        P_MA_LOAI_KNTC NVARCHAR2,
                                        P_KNTC_MA_LOAI_DT NVARCHAR2,
                                        P_NGAY_TIEP_NHAN NVARCHAR2,
                                        P_NOI_DUNG_TIEP_DAN NVARCHAR2,
                                        P_DIA_CHI NVARCHAR2,
                                        P_YEU_CAU_GAP_LD INT
                                        );
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_TIEP_DAN_DETAIL(P_CUR IN OUT MYCUR, P_MA_HO_SO_KNTC INT);
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_TIEP_DAN(P_VAL OUT NVARCHAR2,
                          P_MA_HO_SO_KNTC INT,
                          P_MA_NGUON_DON_DEN NVARCHAR2,
                          P_NGAY_TIEP_DAN NVARCHAR2,
                          P_VU_VIEC_MOI INT,
                          P_NOI_DUNG_TIEP_DAN NVARCHAR2,
                          P_YEU_CAU_GAP_LD INT,
                          P_NGAY_YCGLD NVARCHAR2,
                          P_MA_LD_TIEP_DAN INT,
                          P_Y_KIEN_LD NVARCHAR2,
                          P_MA_CAN_BO_TIEP_DAN INT,
                          P_MA_CO_QUAN_TIEP_DAN NVARCHAR2,
                          P_MA_LINH_VUC_KNTC NVARCHAR2,
                          P_MA_LOAI_KNTC NVARCHAR2,
                          P_KNTC_MA_LOAI_DT NVARCHAR2,
                          P_KNTC_CMND NVARCHAR2,
                          P_KNTC_HO_VA_TEN NVARCHAR2,
                          P_KNTC_MA_PHUONG_XA NVARCHAR2,
                          P_KNTC_SO_NHA NVARCHAR2,
                          P_KNTC_TEN_CQTC NVARCHAR2,
                          P_KNTC_DIA_CHI_CQTC NVARCHAR2,
                          P_KNTC_SO_NGUOI_DAI_DIEN INT,
                          P_KNTC_TEN_NHUNG_NGUOI_DD NVARCHAR2,
                          P_MA_HO_SO_KNTC_GOC INT,
                          P_MA_DON_VI_XU_LY_CHINH NVARCHAR2
                        );
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_NGUOI_BI_KNTC(P_VAL OUT NVARCHAR2,
                          P_MA_HO_SO_KNTC INT,
                          P_BKNTC_MA_LOAI_DT NVARCHAR2,
                          P_BKNTC_HO_VA_TEN NVARCHAR2,
                          P_BKNTC_DIA_CHI NVARCHAR2,
                          P_BKNTC_TEN_CQTC NVARCHAR2,
                          P_BKNTC_DIA_CHI_CQTC NVARCHAR2
                        );
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_GIAI_QUYET(P_VAL OUT NVARCHAR2,
                          P_MA_HO_SO_KNTC INT,
                          P_MA_GIAI_QUYET INT,
                          P_MA_CAN_BO INT,
                          P_NGAY_GIAI_QUYET NVARCHAR2,
                          P_LAN_GIAI_QUYET INT,
                          P_MA_HUONG_GIAI_QUYET NVARCHAR2,
                          P_NOI_DUNG_GIAI_QUYET NVARCHAR2,
                          P_TIEN_DO_XU_LY NVARCHAR2,
                          P_SO_KY_HIEU NVARCHAR2,
                          P_TRICH_YEU NVARCHAR2,
                          P_CO_QUAN_BAN_HANH NVARCHAR2,
                          P_SO_BUT_LUC NVARCHAR2,
                          P_SO_TRANG NVARCHAR2,
                          P_NGAY_TRINH_LANH_DAO_KY NVARCHAR2,
                          P_NGAY_LANH_DAO_KY NVARCHAR2,
                          P_NGAY_CHUYEN_VAN_BAN NVARCHAR2,
                          P_MA_LANH_DAO_KY INT,
                          P_FILE_VAN_BAN NVARCHAR2,
                          P_DIEU_KIEN_XU_LY INT,
                          P_THAM_QUYEN_GIAI_QUYET INT
                        );
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_GIAI_QUYET(P_VAL OUT NVARCHAR2, P_MA_GIAI_QUYET INT);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_GIAI_QUYET(P_CUR IN OUT MYCUR, P_MA_HO_SO_KNTC INT);
  -----------------------------------------------
   PROCEDURE UPDATE_FILE_GIAI_QUYET(P_VAL OUT NVARCHAR2, P_MA_GIAI_QUYET NVARCHAR2, P_FILE_VAN_BAN NVARCHAR2);


/*  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_TIEP_DAN_CO_DON(P_VAL OUT NVARCHAR2,
                          P_MA_HO_SO_KNTC INT,
                          P_MA_NGUON_DON_DEN NVARCHAR2,
                          P_NGAY_TIEP_DAN NVARCHAR2,
                          P_VU_VIEC_MOI INT,
                          P_NOI_DUNG_TIEP_DAN NVARCHAR2,
                          P_YEU_CAU_GAP_LD INT,
                          P_MA_LD_TIEP_DAN INT,
                          P_Y_KIEN_LD NVARCHAR2,
                          P_MA_CAN_BO_TIEP_DAN INT,
                          P_MA_CO_QUAN_TIEP_DAN NVARCHAR2,
                          P_MA_LINH_VUC_KNTC NVARCHAR2,
                          P_MA_LOAI_KNTC NVARCHAR2,
                          P_KNTC_MA_LOAI_DT NVARCHAR2,
                          P_KNTC_CMND NVARCHAR2,
                          P_KNTC_HO_VA_TEN NVARCHAR2,
                          P_KNTC_MA_PHUONG_XA NVARCHAR2,
                          P_KNTC_SO_NHA NVARCHAR2,
                          P_KNTC_TEN_CQTC NVARCHAR2,
                          P_KNTC_DIA_CHI_CQTC NVARCHAR2,
                          P_KNTC_SO_NGUOI_DAI_DIEN INT,
                          P_KNTC_TEN_NHUNG_NGUOI_DD NVARCHAR2,
                          P_MA_HO_SO_KNTC_GOC INT,
                          P_MA_DON_VI_XU_LY_CHINH NVARCHAR2,
                          P_MA_TRANG_THAI_GIAI_QUYET  NVARCHAR2
                        );*/
  -------------------------------------------------------------------------------
  PROCEDURE M2A(P_CUR IN OUT MYCUR, P_TU_NGAY NVARCHAR2, P_DEN_NGAY NVARCHAR2);
  -----------------------------------------------------------------------------
  PROCEDURE M2B(P_CUR IN OUT MYCUR, P_TU_NGAY NVARCHAR2, P_DEN_NGAY NVARCHAR2);
  END KNTC;
/

prompt
prompt Creating package KNTC_BK
prompt ========================
prompt
CREATE OR REPLACE PACKAGE HAI.KNTC_BK IS
  TYPE MYCUR IS REF CURSOR; 
  -------------------------------------------------------------------------------
  PROCEDURE SO_TIEP_DAN( P_CUR IN OUT MYCUR,
                                        P_SO_HO_SO_KNTC NVARCHAR2,
                                        P_MA_LINH_VUC_KNTC NVARCHAR2,
                                        P_MA_LOAI_KNTC NVARCHAR2,
                                        P_KNTC_MA_LOAI_DT NVARCHAR2,
                                        P_NGAY_TIEP_NHAN NVARCHAR2,
                                        P_NOI_DUNG_TIEP_DAN NVARCHAR2,
                                        P_DIA_CHI NVARCHAR2,
                                        P_YEU_CAU_GAP_LD INT  
                                        );
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_TIEP_DAN_DETAIL(P_CUR IN OUT MYCUR, P_MA_HO_SO_KNTC INT);
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_TIEP_DAN(P_VAL OUT NVARCHAR2,
                          P_MA_HO_SO_KNTC INT,
                          P_MA_NGUON_DON_DEN NVARCHAR2,
                          P_NGAY_TIEP_DAN NVARCHAR2,
                          P_VU_VIEC_MOI INT,
                          P_NOI_DUNG_TIEP_DAN NVARCHAR2,
                          P_YEU_CAU_GAP_LD INT,
                          P_MA_LD_TIEP_DAN INT,
                          P_Y_KIEN_LD NVARCHAR2,
                          P_MA_CAN_BO_TIEP_DAN INT,
                          P_MA_CO_QUAN_TIEP_DAN NVARCHAR2,
                          P_MA_LINH_VUC_KNTC NVARCHAR2,   
                          P_MA_LOAI_KNTC NVARCHAR2,
                          P_KNTC_MA_LOAI_DT NVARCHAR2,
                          P_KNTC_CMND NVARCHAR2,
                          P_KNTC_HO_VA_TEN NVARCHAR2,
                          P_KNTC_MA_PHUONG_XA NVARCHAR2,
                          P_KNTC_SO_NHA NVARCHAR2,
                          P_KNTC_TEN_CQTC NVARCHAR2,
                          P_KNTC_DIA_CHI_CQTC NVARCHAR2,
                          P_KNTC_SO_NGUOI_DAI_DIEN INT,
                          P_KNTC_TEN_NHUNG_NGUOI_DD NVARCHAR2,
                          P_MA_HO_SO_KNTC_GOC INT,
                          P_MA_DON_VI_XU_LY_CHINH NVARCHAR2
                        );
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_NGUOI_BI_KNTC(P_VAL OUT NVARCHAR2,
                          P_MA_HO_SO_KNTC INT,
                          P_BKNTC_MA_LOAI_DT NVARCHAR2,
                          P_BKNTC_HO_VA_TEN NVARCHAR2,
                          P_BKNTC_DIA_CHI NVARCHAR2,
                          P_BKNTC_TEN_CQTC NVARCHAR2,
                          P_BKNTC_DIA_CHI_CQTC NVARCHAR2
                        );
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_GIAI_QUYET(P_VAL OUT NVARCHAR2,
                          P_MA_HO_SO_KNTC INT,
                          P_MA_GIAI_QUYET INT,
                          P_MA_CAN_BO INT,
                          P_NGAY_GIAI_QUYET NVARCHAR2,
                          P_LAN_GIAI_QUYET INT,
                          P_MA_HUONG_GIAI_QUYET NVARCHAR2,
                          P_NOI_DUNG_GIAI_QUYET NVARCHAR2,
                          P_SO_KY_HIEU NVARCHAR2,
                          P_TRICH_YEU NVARCHAR2,
                          P_CO_QUAN_BAN_HANH NVARCHAR2,
                          P_SO_BUT_LUC NVARCHAR2,
                          P_SO_TRANG NVARCHAR2,
                          P_NGAY_TRINH_LANH_DAO_KY NVARCHAR2,
                          P_NGAY_LANH_DAO_KY NVARCHAR2,
                          P_NGAY_CHUYEN_VAN_BAN NVARCHAR2,
                          P_MA_LANH_DAO_KY INT,
                          P_FILE_VAN_BAN NVARCHAR2
                        );
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_GIAI_QUYET(P_VAL OUT NVARCHAR2, P_MA_GIAI_QUYET INT);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_GIAI_QUYET(P_CUR IN OUT MYCUR, P_MA_HO_SO_KNTC INT);
  -----------------------------------------------
   PROCEDURE UPDATE_FILE_GIAI_QUYET(P_VAL OUT NVARCHAR2, P_MA_GIAI_QUYET NVARCHAR2, P_FILE_VAN_BAN NVARCHAR2);


/*  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_TIEP_DAN_CO_DON(P_VAL OUT NVARCHAR2,
                          P_MA_HO_SO_KNTC INT,
                          P_MA_NGUON_DON_DEN NVARCHAR2,
                          P_NGAY_TIEP_DAN NVARCHAR2,
                          P_VU_VIEC_MOI INT,
                          P_NOI_DUNG_TIEP_DAN NVARCHAR2,
                          P_YEU_CAU_GAP_LD INT,
                          P_MA_LD_TIEP_DAN INT,
                          P_Y_KIEN_LD NVARCHAR2,
                          P_MA_CAN_BO_TIEP_DAN INT,
                          P_MA_CO_QUAN_TIEP_DAN NVARCHAR2,
                          P_MA_LINH_VUC_KNTC NVARCHAR2,   
                          P_MA_LOAI_KNTC NVARCHAR2,
                          P_KNTC_MA_LOAI_DT NVARCHAR2,
                          P_KNTC_CMND NVARCHAR2,
                          P_KNTC_HO_VA_TEN NVARCHAR2,
                          P_KNTC_MA_PHUONG_XA NVARCHAR2,
                          P_KNTC_SO_NHA NVARCHAR2,
                          P_KNTC_TEN_CQTC NVARCHAR2,
                          P_KNTC_DIA_CHI_CQTC NVARCHAR2,
                          P_KNTC_SO_NGUOI_DAI_DIEN INT,
                          P_KNTC_TEN_NHUNG_NGUOI_DD NVARCHAR2,
                          P_MA_HO_SO_KNTC_GOC INT,
                          P_MA_DON_VI_XU_LY_CHINH NVARCHAR2,
                          P_MA_TRANG_THAI_GIAI_QUYET  NVARCHAR2
                        );*/
  -------------------------------------------------------------------------------
  PROCEDURE M2A(P_CUR IN OUT MYCUR, P_TU_NGAY NVARCHAR2, P_DEN_NGAY NVARCHAR2);
  -----------------------------------------------------------------------------
  PROCEDURE M2B(P_CUR IN OUT MYCUR, P_TU_NGAY NVARCHAR2, P_DEN_NGAY NVARCHAR2);
  END KNTC_BK;
/

prompt
prompt Creating package KNTC_DM
prompt ========================
prompt
create or replace package hai.KNTC_DM is
  TYPE MYCUR IS REF CURSOR; 
 
  -------------------------------------------------------------------------------
   PROCEDURE SELECT_HUONG_GIAI_QUYET(P_CUR IN OUT MYCUR);
   -------------------------------------------------------------------------------
   PROCEDURE SELECT_HUONG_GIAI_QUYET_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_HUONG_GIAI_QUYET NVARCHAR2);
   -------------------------------------------------------------------------------
   PROCEDURE UPDATE_HUONG_GIAI_QUYET(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_HUONG_GIAI_QUYET     NVARCHAR2,
                           P_TEN_HUONG_GIAI_QUYET    NVARCHAR2,
                           P_STT_HUONG_GIAI_QUYET    INT,
                           P_TT_HUONG_GIAI_QUYET     INT);
                      
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_HUONG_GIAI_QUYET(P_VAL   OUT NVARCHAR2, P_MA_HUONG_GIAI_QUYET NVARCHAR2);                                                       
  -------------------------------------------------------------------------------

   PROCEDURE SELECT_TT_GIAI_QUYET(P_CUR IN OUT MYCUR);
   -------------------------------------------------------------------------------
   PROCEDURE SELECT_TT_GIAI_QUYET_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_TRANG_THAI_GIAI_QUYET NVARCHAR2);
   -------------------------------------------------------------------------------
  PROCEDURE UPDATE_TT_GIAI_QUYET(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_TRANG_THAI_GIAI_QUYET     NVARCHAR2,
                           P_TEN_TRANG_THAI_GIAI_QUYET    NVARCHAR2,
                           P_STT_TRANG_THAI_GIAI_QUYET    INT,
                           P_TT_TRANG_THAI_GIAI_QUYET     INT);
                      
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_TT_GIAI_QUYET(P_VAL   OUT NVARCHAR2, P_MA_TRANG_THAI_GIAI_QUYET NVARCHAR2);                                                       
  -------------------------------------------------------------------------------

   PROCEDURE SELECT_LINH_VUC_KNTC(P_CUR IN OUT MYCUR);
   -------------------------------------------------------------------------------
   PROCEDURE SELECT_LINH_VUC_KNTC_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_LINH_VUC_KNTC NVARCHAR2);
   -------------------------------------------------------------------------------
  PROCEDURE UPDATE_LINH_VUC_KNTC(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_LINH_VUC_KNTC     NVARCHAR2,
                           P_TEN_LINH_VUC_KNTC    NVARCHAR2,
                           P_STT_LINH_VUC_KNTC    INT,
                           P_TT_LINH_VUC_KNTC     INT);
                      
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_LINH_VUC_KNTC(P_VAL   OUT NVARCHAR2, P_MA_LINH_VUC_KNTC NVARCHAR2); 
  -----------------------------------DM_LOAI_DTBKNTC--------------------------------------------
     PROCEDURE SELECT_LOAI_DTBKNTC(P_CUR IN OUT MYCUR);
   -------------------------------------------------------------------------------
   PROCEDURE SELECT_LOAI_DTBKNTC_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_LOAI_DTBKNTC NVARCHAR2);
   -------------------------------------------------------------------------------
  PROCEDURE UPDATE_LOAI_DTBKNTC(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_LOAI_DTBKNTC     NVARCHAR2,
                           P_TEN_LOAI_DTBKNTC    NVARCHAR2,
                           P_STT_LOAI_DTBKNTC    INT,
                           P_TT_LOAI_DTBKNTC     INT);
                      
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_LOAI_DTBKNTC(P_VAL   OUT NVARCHAR2, P_MA_LOAI_DTBKNTC NVARCHAR2);
    -----------------------------------DM_LOAI_DTKNTC--------------------------------------------
     PROCEDURE SELECT_LOAI_DTKNTC(P_CUR IN OUT MYCUR);
   -------------------------------------------------------------------------------
   PROCEDURE SELECT_LOAI_DTKNTC_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_LOAI_DTKNTC NVARCHAR2);
   -------------------------------------------------------------------------------
  PROCEDURE UPDATE_LOAI_DTKNTC(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_LOAI_DTKNTC     NVARCHAR2,
                           P_TEN_LOAI_DTKNTC    NVARCHAR2,
                           P_STT_LOAI_DTKNTC    INT,
                           P_TT_LOAI_DTKNTC     INT);
                      
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_LOAI_DTKNTC(P_VAL   OUT NVARCHAR2, P_MA_LOAI_DTKNTC NVARCHAR2);
   -----------------------------------DM_LOAI_KET_QUA--------------------------------------------
     PROCEDURE SELECT_LOAI_KET_QUA(P_CUR IN OUT MYCUR);
   -------------------------------------------------------------------------------
   PROCEDURE SELECT_LOAI_KET_QUA_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_LOAI_KET_QUA NVARCHAR2);
   -------------------------------------------------------------------------------
  PROCEDURE UPDATE_LOAI_KET_QUA(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_LOAI_KET_QUA     NVARCHAR2,
                           P_TEN_LOAI_KET_QUA    NVARCHAR2,
                           P_STT_LOAI_KET_QUA    INT,
                           P_TT_LOAI_KET_QUA     INT);
                      
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_LOAI_KET_QUA(P_VAL   OUT NVARCHAR2, P_MA_LOAI_KET_QUA NVARCHAR2);
---------------------------DM_NGUON_DON_DEN-------------------------------------
PROCEDURE SELECT_NGUON_DON_DEN(P_CUR IN OUT MYCUR) ;
-------------------------------------------------------------------------------
PROCEDURE SELECT_NGUON_DON_DEN_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_NGUON_DON_DEN NVARCHAR2);
-------------------------------------------------------------------------------                                  
 PROCEDURE UPDATE_NGUON_DON_DEN(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_NGUON_DON_DEN     NVARCHAR2,
                           P_TEN_NGUON_DON_DEN    NVARCHAR2,
                           P_STT_NGUON_DON_DEN   INT,
                           P_TT_NGUON_DON_DEN     INT);     
                           
    -------------------------------------------------------------------------------
  PROCEDURE DELETE_NGUON_DON_DEN(P_VAL   OUT NVARCHAR2, P_MA_NGUON_DON_DEN NVARCHAR2);                                                      
                                                     
---------------------------DM_LOAI_KNTC-------------------------------------
PROCEDURE SELECT_LOAI_KNTC(P_CUR IN OUT MYCUR) ;
-------------------------------------------------------------------------------
PROCEDURE SELECT_LOAI_KNTC_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_LOAI_KNTC NVARCHAR2);
-------------------------------------------------------------------------------                                  
 PROCEDURE UPDATE_LOAI_KNTC(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_LOAI_KNTC     NVARCHAR2,
                           P_TEN_LOAI_KNTC    NVARCHAR2,
                           P_STT_LOAI_KNTC   INT,
                           P_TT_LOAI_KNTC     INT);     
                           
-------------------------------------------------------------------------------
  PROCEDURE DELETE_LOAI_KNTC(P_VAL   OUT NVARCHAR2, P_MA_LOAI_KNTC NVARCHAR2);   
  ---------------------------DM_THAM_QUYEN-------------------------------------
 PROCEDURE SELECT_THAM_QUYEN(P_CUR IN OUT MYCUR) ;
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_THAM_QUYEN_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_THAM_QUYEN NVARCHAR2);
 -------------------------------------------------------------------------------                                  
 PROCEDURE UPDATE_THAM_QUYEN(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_THAM_QUYEN     NVARCHAR2,
                           P_TEN_THAM_QUYEN    NVARCHAR2,
                           P_STT_THAM_QUYEN   INT,
                           P_TT_THAM_QUYEN     INT);     
                           
 -------------------------------------------------------------------------------
 PROCEDURE DELETE_THAM_QUYEN(P_VAL   OUT NVARCHAR2, P_MA_THAM_QUYEN NVARCHAR2);   
end KNTC_DM;
/

prompt
prompt Creating package KNTC_SELECT
prompt ============================
prompt
create or replace package hai.KNTC_SELECT is
  TYPE MYCUR IS REF CURSOR; 
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_NGUON_DON_DEN(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_CHUC_VU(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2); 
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_DAN_TOC(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUOC_TICH(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_TON_GIAO(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_THAM_QUYEN(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAI_KNTC(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LINH_VUC_KNTC(P_CUR IN OUT MYCUR ,P_TYPE NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAI_KET_QUA(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAI_VAN_BAN(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2);   
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_TINH_THANH(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUAN_HUYEN(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUAN_HUYEN_CUA_TINH(P_CUR IN OUT MYCUR, P_MA_TINH_THANH NVARCHAR2, P_TYPE NVARCHAR2);  
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_PHUONG_XA(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2);    
    -------------------------------------------------------------------------------
  PROCEDURE SELECT_PHUONG_XA_CUA_HUYEN(P_CUR IN OUT MYCUR, P_MA_QUAN_HUYEN NVARCHAR2, P_TYPE NVARCHAR2);                                                                                                                  
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAI_DTKNTC(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAI_DTBKNTC(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_HUONG_GIAI_QUYET(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_TRANG_THAI_GIAI_QUYET(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_CO_QUAN(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2);
  ------------------------------------------------------------------------------
   PROCEDURE SELECT_CAN_BO(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_DON_VI_CUA_CQ(P_CUR IN OUT MYCUR, P_MA_CO_QUAN NVARCHAR2, P_TYPE NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LANH_DAO_CUA_CQ(P_CUR IN OUT MYCUR, P_MA_CO_QUAN NVARCHAR2, P_TYPE NVARCHAR2);
end KNTC_SELECT;
/

prompt
prompt Creating package LIB_DM
prompt =======================
prompt
CREATE OR REPLACE PACKAGE HAI.LIB_DM IS
TYPE MYCUR IS REF CURSOR;
-------------------------------------------------------------------------------
 PROCEDURE SELECT_DONVI_nothing(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_DONVI_tatca(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_DONVI_chon(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_DONVI_phuongxa(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_DONVI_motcuaxa(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_DONVI_motcuaxa2(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_DONVI_CUA_CQ_nothing(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2); 
 PROCEDURE SELECT_DONVI_CUA_CQ_tatca(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2); 
 PROCEDURE SELECT_DONVI_CUA_CQ_chon(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2); 
 PROCEDURE SELECT_DONVI_tiepnhan(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2);
-------------------------------------------------------------------------------
 PROCEDURE SELECT_TOCHUYENMON_nothing(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_TOCHUYENMON_tatca(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_TOCHUYENMON_chon(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_TOCHUYENMON_null(P_CUR IN OUT MYCUR); 
 PROCEDURE SELECT_TOCHUYENMON_by_mdv(P_CUR IN OUT MYCUR,P_MA_DON_VI NVARCHAR2); 

-------------------------------------------------------------------------------
 PROCEDURE SELECT_DONVICHUQUAN_nothing(P_CUR IN OUT MYCUR, P_MA_CO_QUAN NVARCHAR2); 
 PROCEDURE SELECT_DONVICHUQUAN_tatca(P_CUR IN OUT MYCUR, P_MA_CO_QUAN NVARCHAR2); 
 PROCEDURE SELECT_DONVICHUQUAN_chon(P_CUR IN OUT MYCUR, P_MA_CO_QUAN NVARCHAR2); 
-------------------------------------------------------------------------------
 PROCEDURE SELECT_PHUONGXA_nothing(P_CUR IN OUT MYCUR, P_MA_QUAN_HUYEN NVARCHAR2);
 PROCEDURE SELECT_PHUONGXA_NULL(P_CUR IN OUT MYCUR, P_MA_QUAN_HUYEN NVARCHAR2);
 PROCEDURE SELECT_PHUONGXA_tatca(P_CUR IN OUT MYCUR, P_MA_QUAN_HUYEN NVARCHAR2);
 PROCEDURE SELECT_PHUONGXA_chon(P_CUR IN OUT MYCUR, P_MA_QUAN_HUYEN NVARCHAR2);
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_LOAIDONVI_nothing(P_CUR IN OUT MYCUR, P_MA_LOAI_CO_QUAN NVARCHAR2);
 PROCEDURE SELECT_LOAIDONVI_nothing_cuacq(P_CUR IN OUT MYCUR, P_MA_LOAI_CO_QUAN NVARCHAR2, P_MA_CO_QUAN NVARCHAR2);
 PROCEDURE SELECT_LOAIDONVI_tatca(P_CUR IN OUT MYCUR, P_MA_LOAI_CO_QUAN NVARCHAR2);
 PROCEDURE SELECT_LOAIDONVI_tatca_cuacq(P_CUR IN OUT MYCUR, P_MA_LOAI_CO_QUAN NVARCHAR2, P_MA_CO_QUAN NVARCHAR2);
 PROCEDURE SELECT_LOAIDONVI_chon(P_CUR IN OUT MYCUR, P_MA_LOAI_CO_QUAN NVARCHAR2);
 PROCEDURE SELECT_LOAIDONVI_chon_cuacq(P_CUR IN OUT MYCUR, P_MA_LOAI_CO_QUAN NVARCHAR2, P_MA_CO_QUAN NVARCHAR2);
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_LOAINHOMNSD_nothing(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_LOAINHOMNSD_tatca(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_LOAINHOMNSD_chon(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_LOAINHOMNSD_CBX_BY_MDV(P_CUR IN OUT MYCUR,P_MA_TO_CHUYEN_MON INT,P_MA_DON_VI NVARCHAR2);
 PROCEDURE SELECT_LOAINHOMNSD_CBX_BY_MT(P_CUR IN OUT MYCUR,P_MA_TO_CHUYEN_MON INT);
 PROCEDURE SELECT_LOAINHOMNSD_BY_MLDV(P_CUR IN OUT MYCUR,P_MA_LOAI_DON_VI NVARCHAR2);
 PROCEDURE SELECT_LOAINHOMNSD_BY_MLDVchon(P_CUR IN OUT MYCUR,P_MA_LOAI_DON_VI NVARCHAR2);
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_MENU_nothing(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_MENU_tatca(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_MENU_chon(P_CUR IN OUT MYCUR);
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_QUYEN_nothing(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_QUYEN_tatca(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_QUYEN_chon(P_CUR IN OUT MYCUR);
-------------------------------------------------------------------------------
 PROCEDURE SELECT_CHUCVU_nothing(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_CHUCVU_chon(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_CHUCVU_tatca(P_CUR IN OUT MYCUR); 
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_LOAICOQUAN_nothing(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_LOAICOQUAN_chon(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_LOAICOQUAN_tatca(P_CUR IN OUT MYCUR); 
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_COQUAN_nothing(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_COQUAN_nothing_desc(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_COQUAN_chon(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_UBND_HUYEN(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_COQUAN_tatca(P_CUR IN OUT MYCUR); 
 PROCEDURE SELECT_COQUAN_BY_LCQ_nothing(P_CUR IN OUT MYCUR,P_MA_LOAI_CO_QUAN NVARCHAR2);
 PROCEDURE SELECT_COQUAN_BY_LCQ_chon(P_CUR IN OUT MYCUR,P_MA_LOAI_CO_QUAN NVARCHAR2);
 PROCEDURE SELECT_COQUAN_BY_LCQ_tatca(P_CUR IN OUT MYCUR,P_MA_LOAI_CO_QUAN NVARCHAR2); 
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_QUANHUYEN_nothing(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_QUANHUYEN_chon(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_QUANHUYEN_tatca(P_CUR IN OUT MYCUR); 
 PROCEDURE SELECT_QUANHUYEN_Select(P_CUR IN OUT MYCUR, P_MA_TINH_THANH NVARCHAR2);
 PROCEDURE SELECT_QUANHUYEN_tinh(P_CUR IN OUT MYCUR, P_MA_TINH_THANH NVARCHAR2); 
  PROCEDURE SELECT_QUANHUYEN_ORDER(P_CUR IN OUT MYCUR, P_MA_TINH_THANH NVARCHAR2);
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_TINHTHANH_nothing(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_TINHTHANH_chon(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_TINHTHANH_tatca(P_CUR IN OUT MYCUR); 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
END LIB_DM;
/

prompt
prompt Creating package LIB_FUN
prompt ========================
prompt
CREATE OR REPLACE PACKAGE HAI.LIB_FUN IS
TYPE MYCUR IS REF CURSOR;
 -------------------------------------------------------------------------------
 FUNCTION GET_SO_LUONG_CBHT_CUA_DV(P_MA_DON_VI NVARCHAR2) RETURN INT ; 
 -------------------------------------------------------------------------------
 FUNCTION GET_SO_LUONG_TO_CUA_DV(P_MA_DON_VI NVARCHAR2) RETURN INT;
 -------------------------------------------------------------------------------
 FUNCTION GET_SO_LUONG_CBHT_CUA_TO(P_MA_TO_CHUYEN_MON INT) RETURN INT ;

 END LIB_FUN;
/

prompt
prompt Creating package LIB_NOTABLE
prompt ============================
prompt
CREATE OR REPLACE PACKAGE HAI.LIB_NOTABLE IS
 TYPE MYCUR IS REF CURSOR;
 TYPE MY_ARR IS ARRAY(10) OF NVARCHAR2(4);
  /********* BEGIN: HOC **********/
  
  --FUNC: GET_TENTRANGTHAI_HS
  FUNCTION GET_TENTRANGTHAI_HS(
    P_TRANG_THAI NVARCHAR2)
    RETURN NVARCHAR2;
  
  --FUNC: IS_NUMBERIC
  FUNCTION IS_NUMBERIC(
    P_STR NVARCHAR2)
    RETURN NUMBER;
   
  /********* END: HOC **********/ 
 -------------------------------------------------------------------------------
 FUNCTION IS_NUMBER (P_STRING IN VARCHAR2) RETURN INT;
 -------------------------------------------------------------------------------
 FUNCTION REPLACE_BAD_CHAR (P_CHUOI NVARCHAR2) RETURN NVARCHAR2;
 -------------------------------------------------------------------------------
 FUNCTION LOC_DAU (P_CHUOI NVARCHAR2) RETURN NVARCHAR2;
 -------------------------------------------------------------------------------
 FUNCTION LOC_DAU2 (P_CHUOI NVARCHAR2) RETURN NVARCHAR2;
 -------------------------------------------------------------------------------
 FUNCTION LOC_DAU_VA_KHOANG_TRANG (P_CHUOI NVARCHAR2) RETURN NVARCHAR2;
 -------------------------------------------------------------------------------
 FUNCTION GET_GIO_HIEN_TAI RETURN NUMBER;
 -------------------------------------------------------------------------------
 FUNCTION GET_THANG_HIEN_TAI  RETURN NUMBER;
 -------------------------------------------------------------------------------
 FUNCTION GET_NAM_HIEN_TAI  RETURN NUMBER;
 -------------------------------------------------------------------------------
 FUNCTION GET_THANG_FROM_CHUOI_NGAY(P_NGAY NVARCHAR2)  RETURN NUMBER; 
 -------------------------------------------------------------------------------
 FUNCTION GET_NAM_FROM_CHUOI_NGAY(P_NGAY NVARCHAR2)  RETURN NUMBER;
 -------------------------------------------------------------------------------
 FUNCTION SO_SANH_NGAY_2_CHUOI_NGAY(P_NGAY1 NVARCHAR2,P_NGAY2 NVARCHAR2)  RETURN NUMBER;
 -------------------------------------------------------------------------------
 FUNCTION KIEM_TRA_SO_DIEN_THOAI(P_SO_DIEN_THOAI NVARCHAR2) RETURN NVARCHAR2;
  
 END LIB_NOTABLE;
/

prompt
prompt Creating package MC_CB
prompt ======================
prompt
CREATE OR REPLACE PACKAGE HAI.MC_CB IS
  TYPE MYCUR IS REF CURSOR;
  
  /* BEGIN: HOC */
  
  --PROC: SELECT_DON_VI
  PROCEDURE SELECT_DON_VI(
    P_CUR IN OUT MYCUR,
    P_MA_DON_VI NVARCHAR2,
    P_TEN_DON_VI NVARCHAR2,
    P_MA_LOAI_DON_VI NVARCHAR2,
    P_MA_PHUONG_XA NVARCHAR2,
    P_TRANG_THAI NUMBER,
    P_MA_DON_VI_CHU_QUAN NVARCHAR2,
    P_MA_TAT NVARCHAR2,
    P_MA_CO_QUAN NVARCHAR2);
  
  --PROC: SELECT_TO_CHUYEN_MON
  PROCEDURE SELECT_TO_CHUYEN_MON(
    P_CUR IN OUT MYCUR,
    P_MA_TO_CHUYEN_MON NVARCHAR2,
    P_TEN_TO_CHUYEN_MON NVARCHAR2,
    P_MA_DON_VI NVARCHAR2,
    P_MA_LOAI_NHOM_NSD NVARCHAR2,
    P_TRANG_THAI NUMBER);
  
  --PROC: SELECT_CAN_BO
  PROCEDURE SELECT_CAN_BO(
    P_CUR IN OUT MYCUR,
    P_MA_CAN_BO NUMBER,
    P_MA_CAN_BO_LIEN_THONG NUMBER,
    P_TEN_CAN_BO NVARCHAR2,
    P_TAI_KHOAN NVARCHAR2,
    P_CMND NVARCHAR2,
    P_DIA_CHI NVARCHAR2,
    P_DI_DONG NVARCHAR2,
    P_TRANG_THAI NUMBER,
    P_DANG_KY_NHAC_VIEC NUMBER,
    P_MA_CO_QUAN NVARCHAR2,
    P_MA_PHUONG_XA NVARCHAR2,
    P_MA_TO_CHUYEN_MON NVARCHAR2);
    
  --PROC: UPDATE_OTP
  PROCEDURE UPDATE_OTP(
    P_KQ OUT NUMBER,
    P_MA_CAN_BO NUMBER,
    P_DI_DONG NVARCHAR2,
    P_NGAY_DANG_KY_OTP NVARCHAR2);
    
  /* END: HOC*/
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_DON_VI_FILTER(P_CUR IN OUT MYCUR,
                                 P_MA_CO_QUAN         NVARCHAR2,
                                 P_MA_LOAI_DON_VI NVARCHAR2,
                                 P_MA_PHUONG_XA NVARCHAR2,
                                 P_MA_DON_VI_CHU_QUAN NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_DON_VI_DETAIL(P_CUR       IN OUT MYCUR,
                                 P_MA_DON_VI NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_DON_VI(P_VAL                 OUT NVARCHAR2,
                           P_UPDATE_TYPE        NVARCHAR2,
                           P_NGUOI_CAP_NHAT     INT,
                           P_MA_DON_VI          NVARCHAR2,
                           P_TEN_DON_VI         NVARCHAR2,
                           P_MA_CO_QUAN     NVARCHAR2,
                           P_MA_LOAI_DON_VI     NVARCHAR2,
                           P_MA_PHUONG_XA       NVARCHAR2,
                           P_MA_DON_VI_CHU_QUAN NVARCHAR2,
                           P_MA_TAT NVARCHAR2,
                           P_SO_HO_SO_HIEN_TAI INT,
                           P_STT_DON_VI         INT,
                           P_TRANG_THAI         INT);
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_DON_VI(P_VAL       OUT NVARCHAR2,
                          P_NGUOI_XOA INT,
                          P_MA_DON_VI NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_TO_CHUYEN_MON_DETAIL(P_CUR        IN OUT MYCUR,
                                  P_MA_TO_CHUYEN_MON INT);
  ------------------------------------------------------------------------------
  PROCEDURE SELECT_TO_CHUYEN_MON_ALL_TR(P_CUR IN OUT MYCUR , 
                                        P_MA_DON_VI NVARCHAR2,
                                        P_MA_CO_QUAN NVARCHAR2,
                                        P_SITE_ROOT NVARCHAR2);
  ------------------------------------------------------------------------------
  PROCEDURE UPDATE_TO_CHUYEN_MON(P_VAL                 OUT NVARCHAR2,
                           P_UPDATE_TYPE         NVARCHAR2,
                           P_NGUOI_CAP_NHAT      INT,
                           P_MA_TO_CHUYEN_MON          INT,
                           P_TEN_TO_CHUYEN_MON         NVARCHAR2,
                           P_MA_DON_VI      NVARCHAR2,
                           P_MA_LOAI_NHOM_NSD NVARCHAR2,
                           P_STT_TO_CHUYEN_MON         INT,
                           P_TRANG_THAI          INT);
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_TO_CHUYEN_MON(P_VAL        OUT NVARCHAR2,
                           P_NGUOI_XOA  INT,
                           P_MA_TO_CHUYEN_MON INT);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_CAN_BO_DETAIL(P_CUR IN OUT MYCUR, P_MA_CAN_BO INT);
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_CAN_BO(P_VAL                 OUT NVARCHAR2,
                           P_UPDATE_TYPE         NVARCHAR2,
                           P_NGUOI_CAP_NHAT      INT,
                           P_MA_CAN_BO          INT,
                           P_TEN_CAN_BO NVARCHAR2,
                           P_TAI_KHOAN         NVARCHAR2,
                           P_MAT_KHAU NVARCHAR2,
                           P_CMND NVARCHAR2,
                           P_DIA_CHI NVARCHAR2,
                           P_DI_DONG NVARCHAR2,
                           P_HINH_ANH NVARCHAR2,
                           P_STT_CAN_BO         INT,
                           P_TRANG_THAI          INT,
                           P_MA_QUYEN_LOAD_DAU_TIEN NVARCHAR2,
                           P_DANG_KY_NHAC_VIEC INT,
                           P_GIOI_TINH         NUMBER,
                           P_NGAY_SINH         NVARCHAR2,
                           P_MA_CO_QUAN NVARCHAR2);
 ------------------------------------------------------------------------------------
 PROCEDURE RESET_MAT_KHAU(P_VAL            OUT NVARCHAR2,
                          P_MA_CAN_BO      INT,
                          P_MAT_KHAU_MOI       NVARCHAR2);
 ------------------------------------------------------------------------------
 PROCEDURE DELETE_CAN_BO(P_VAL       OUT NVARCHAR2,
                          P_NGUOI_XOA INT,
                          P_MA_CAN_BO INT);                           

 PROCEDURE SELECT_CAN_BO_CHUA_PHAN_CT(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2);
 ------------------------------------------------------------------------------
 PROCEDURE SELECT_CAN_BO_BY_MDV_ALL_TR(P_CUR IN OUT MYCUR ,
                                       P_MA_DON_VI NVARCHAR2,
                                       P_SITE_ROOT NVARCHAR2,
                                       P_MA_CO_QUAN NVARCHAR2);
 ------------------------------------------------------------------------------
 PROCEDURE SELECT_CAN_BO_BY_MTCM_ALL_TR(P_CUR IN OUT MYCUR,
                                        P_MA_DON_VI NVARCHAR2 ,
                                        P_MA_TO_CHUYEN_MON INT,
                                        P_SITE_ROOT NVARCHAR2,
                                        P_MA_CO_QUAN NVARCHAR2);
 ------------------------------------------------------------------------------
 PROCEDURE SELECT_CAN_BO_BY_MTCM_ALL_TR2(P_CUR IN OUT MYCUR,P_MA_TO_CHUYEN_MON INT,P_SITE_ROOT NVARCHAR2);
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_ALL_TO_OF_CANBO(P_CUR IN OUT MYCUR, P_MA_CAN_BO NVARCHAR2); 
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_THUOC_TO_DETAIL(P_CUR IN OUT MYCUR, 
                                   P_MA_CAN_BO INT,
                                   P_MA_TO_CHUYEN_MON INT,
                                   P_MA_CHUC_VU NVARCHAR2,
                                   P_TU_NGAY NVARCHAR2);

 -------------------------------------------------------------------------------
 PROCEDURE INSERT_THUOC_TO(P_VAL           OUT NVARCHAR2,
                        P_NGUOI_CAP_NHAT        INT,
                        P_MA_CAN_BO             INT,
                        P_MA_TO_CHUYEN_MON      INT,
                        P_MA_CHUC_VU            NVARCHAR2,
                        P_KIEM_NHIEM            INT,
                        P_DUOC_PHAN_CONG_THU_LY INT,
                        P_DUOC_DUYET_HO_SO INT,
                        P_TU_NGAY               NVARCHAR2);
 -------------------------------------------------------------------------------
 PROCEDURE UPDATE_THUOC_TO(P_VAL           OUT NVARCHAR2,
                        P_NGUOI_CAP_NHAT        INT,
                        P_MA_CAN_BO             INT,
                        P_MA_TO_CHUYEN_MON      INT,
                        P_MA_CHUC_VU            NVARCHAR2,
                        P_KIEM_NHIEM            INT,
                        P_DUOC_PHAN_CONG_THU_LY INT,
                        P_DUOC_DUYET_HO_SO INT,
                        P_TU_NGAY               NVARCHAR2,
                        P_DEN_NGAY               NVARCHAR2);
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_THONGTINCANHAN(P_CUR IN OUT MYCUR, P_MA_CAN_BO INT);
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_QUYEN_DUOC_PHAN(P_CUR IN OUT MYCUR, P_MA_CAN_BO INT);
 -------------------------------------------------------------------------------
 PROCEDURE UPDATE_THONGTIN_CANHAN(P_VAL            OUT NVARCHAR2,
                          P_MA_CAN_BO      INT,
                          P_TEN_CAN_BO     NVARCHAR2,
                          P_CMND           NVARCHAR2,
                          P_DIA_CHI        NVARCHAR2,
                          P_DI_DONG        NVARCHAR2,
                          P_HINH_ANH       NVARCHAR2,
                          P_MA_QUYEN_LOAD_DAU_TIEN NVARCHAR2,
                          P_GIOI_TINH              NVARCHAR2,
                          P_NGAY_SINH              NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_CO_QUAN_FILTER(P_CUR IN OUT MYCUR,
                                 P_MA_LOAI_CO_QUAN NVARCHAR2,
                                 P_MA_QUAN_HUYEN NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_CO_QUAN_DETAIL(P_CUR       IN OUT MYCUR,
                                 P_MA_CO_QUAN NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_CO_QUAN(P_VAL                OUT NVARCHAR2,
                          P_MA_CO_QUAN          NVARCHAR2,
                          P_TEN_CO_QUAN         NVARCHAR2,
                          P_MA_LOAI_CO_QUAN     NVARCHAR2,
                          P_MA_QUAN_HUYEN       NVARCHAR2,
                          P_MA_TAT_CO_QUAN NVARCHAR2,
                          P_APPS NVARCHAR2,
                          P_DIA_CHI_CO_QUAN NVARCHAR2,
                          P_DIEN_THOAI_CO_QUAN NVARCHAR2,
                          P_LOGO_CO_QUAN NVARCHAR2,
                          P_STT_CO_QUAN INT,
                          P_TRANG_THAI         INT);
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_CO_QUAN(P_VAL       OUT NVARCHAR2,
                          P_NGUOI_XOA INT,
                          P_MA_CO_QUAN NVARCHAR2);
 -------------------------------------------------------------------------------
 PROCEDURE UPDATE_THUOC_TO_NHANH(P_VAL              OUT NVARCHAR2,
                            P_NGUOI_CAP_NHAT   INT,
                            P_MA_CAN_BO        INT,
                            P_MA_TO_CHUYEN_MON INT,
                            P_MA_TO_CU INT,
                            P_MA_CHUC_VU       NVARCHAR2);
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_CAN_BO_MOI_THEM_DETAIL(P_CUR IN OUT MYCUR,P_MA_CAN_BO NVARCHAR2);
 -------------------------------------------------------------------------------
 PROCEDURE TIM_KIEM_CAN_BO(P_CUR IN OUT MYCUR,
                          P_MA_DON_VI NVARCHAR2,
                          P_MA_TO_CHUYEN_MON NVARCHAR2,
                          P_MA_CO_QUAN NVARCHAR2);  
 -------------------------------------------------------------------------------
 PROCEDURE UPDATE_CAN_BO(P_VAL            OUT NVARCHAR2,
                          P_UPDATE_TYPE    NVARCHAR2,
                          P_NGUOI_CAP_NHAT INT,
                          P_MA_CAN_BO      INT,
                          P_TEN_CAN_BO     NVARCHAR2,
                          P_TAI_KHOAN      NVARCHAR2,
                          P_MAT_KHAU       NVARCHAR2,
                          P_CMND           NVARCHAR2,                                                
                          P_DIA_CHI        NVARCHAR2,
                          P_DI_DONG        NVARCHAR2,
                          P_HINH_ANH       NVARCHAR2,
                          P_STT_CAN_BO             INT,
                          P_TRANG_THAI             INT,
                          P_MA_QUYEN_LOAD_DAU_TIEN NVARCHAR2,
                          P_DANG_KY_NHAC_VIEC INT,                          
                          P_GIOI_TINH      NUMBER,
                          P_NGAY_SINH      NVARCHAR2,
                          P_MA_CO_QUAN NVARCHAR2,
                          P_MA_TO_CHUYEN_MON NVARCHAR2,
                          P_MA_CHUC_VU NVARCHAR2);
PROCEDURE SELECT_DANH_SACH_CAN_BO(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2,P_MA_LOAI_DON_VI NVARCHAR2);
PROCEDURE SELECT_DM_CAN_BO(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2,P_MA_DON_VI NVARCHAR2,P_MA_TO_CHUYEN_MON NVARCHAR2);
PROCEDURE SELECT_DM_CAN_BO_LDV(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2,P_MA_LOAI_DON_VI NVARCHAR2);















END MC_CB;
/

prompt
prompt Creating package MC_DM
prompt ======================
prompt
CREATE OR REPLACE PACKAGE HAI.MC_DM IS
  TYPE MYCUR IS REF CURSOR; 
 
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_PHUONG_XA_FILTER(P_CUR IN OUT MYCUR,
                                    P_MA_QUAN_HUYEN NVARCHAR2,
                                    P_MA_TINH_THANH NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_PHUONG_XA_DETAIL(P_CUR          IN OUT MYCUR,
                                    P_MA_PHUONG_XA NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_PHUONG_XA(P_VAL            OUT NVARCHAR2,
                             P_UPDATE_TYPE    NVARCHAR2,
                             P_NGUOI_CAP_NHAT INT,
                             P_MA_PHUONG_XA   NVARCHAR2,
                             P_TEN_PHUONG_XA  NVARCHAR2,
                             P_MA_QUAN_HUYEN  NVARCHAR2,
                             P_STT_PHUONG_XA  INT,
                             P_TRANG_THAI     INT);
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_PHUONG_XA(P_VAL          OUT NVARCHAR2,
                             P_NGUOI_XOA    INT,
                             P_MA_PHUONG_XA NVARCHAR2);                       
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAI_CO_QUAN(P_CUR IN OUT MYCUR);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAI_CO_QUAN_DETAIL(P_CUR                 IN OUT MYCUR,
                                           P_MA_LOAI_CO_QUAN NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_LOAI_CO_QUAN(P_VAL                  OUT NVARCHAR2,
                                    P_UPDATE_TYPE          NVARCHAR2,
                                    P_MA_LOAI_CO_QUAN  NVARCHAR2,
                                    P_TEN_LOAI_CO_QUAN NVARCHAR2,
                                    P_STT_LOAI_CO_QUAN INT,
                                    P_TRANG_THAI           INT);
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_LOAI_CO_QUAN(P_VAL                 OUT NVARCHAR2,
                                    P_NGUOI_XOA           INT,
                                    P_MA_LOAI_CO_QUAN NVARCHAR2);        
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUAN_HUYEN(P_CUR IN OUT MYCUR,P_MA_TINH_THANH NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUAN_HUYEN_DETAIL(P_CUR                 IN OUT MYCUR,
                                           P_MA_QUAN_HUYEN NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_QUAN_HUYEN(P_VAL                  OUT NVARCHAR2,
                                    P_UPDATE_TYPE          NVARCHAR2,
                                    P_MA_QUAN_HUYEN  NVARCHAR2,
                                    P_TEN_QUAN_HUYEN NVARCHAR2,
                                    P_MA_TINH_THANH NVARCHAR2,
                                    P_STT_QUAN_HUYEN INT,
                                    P_TRANG_THAI           INT);
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_QUAN_HUYEN(P_VAL                 OUT NVARCHAR2,
                                    P_NGUOI_XOA           INT,
                                    P_MA_QUAN_HUYEN NVARCHAR2);  

  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAI_NHOM_NSD_FILTER(P_CUR IN OUT MYCUR,
                                        P_MA_LOAI_DON_VI NVARCHAR2,
                                        P_MA_LOAI_CO_QUAN NVARCHAR2,
                                        P_MA_CO_QUAN NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAI_NHOM_NSD_DETAIL(P_CUR            IN OUT MYCUR,
                                      P_MA_LOAI_NHOM_NSD NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_LOAI_NHOM_NSD(P_VAL           OUT NVARCHAR2,
                               P_UPDATE_TYPE     NVARCHAR2,
                               P_NGUOI_CAP_NHAT  INT,
                               P_MA_LOAI_NHOM_NSD  NVARCHAR2,
                               P_TEN_LOAI_NHOM_NSD NVARCHAR2,
                               P_MA_LOAI_DON_VI    NVARCHAR2,
                               P_STT_LOAI_NHOM_NSD INT,
                               P_TRANG_THAI        INT);
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_LOAI_NHOM_NSD(P_VAL            OUT NVARCHAR2,
                               P_NGUOI_XOA      INT,
                               P_MA_LOAI_NHOM_NSD NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAI_DON_VI_FILTER(P_CUR IN OUT MYCUR,
                               P_MA_LOAI_CO_QUAN NVARCHAR2,
                               P_MA_CO_QUAN NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAI_DON_VI_DETAIL(P_CUR            IN OUT MYCUR,
                                      P_MA_LOAI_DON_VI NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_LOAI_DON_VI(P_VAL             OUT NVARCHAR2,
                               P_UPDATE_TYPE     NVARCHAR2,
                               P_NGUOI_CAP_NHAT  INT,
                               P_MA_LOAI_DON_VI  NVARCHAR2,
                               P_TEN_LOAI_DON_VI NVARCHAR2,
                               P_MA_LOAI_CO_QUAN  NVARCHAR2,
                               P_MA_CO_QUAN  NVARCHAR2,
                               P_DON_VI_CAP_HUYEN INT,
                               P_STT_LOAI_DON_VI INT,
                               P_TRANG_THAI      INT);
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_LOAI_DON_VI(P_VAL            OUT NVARCHAR2,
                               P_NGUOI_XOA      INT,
                               P_MA_LOAI_DON_VI NVARCHAR2);

  -------------------------------------------------------------------------------
  PROCEDURE SELECT_CHUC_VU(P_CUR IN OUT MYCUR);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_CHUC_VU_DETAIL(P_CUR        IN OUT MYCUR,
                                  P_MA_CHUC_VU NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_CHUC_VU(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_CHUC_VU     NVARCHAR2,
                           P_TEN_CHUC_VU    NVARCHAR2,
                           P_STT_CHUC_VU    INT,
                           P_TT_CHUC_VU     INT);
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_CHUC_VU(P_VAL        OUT NVARCHAR2,
                           P_NGUOI_XOA  INT,
                           P_MA_CHUC_VU NVARCHAR2);
END MC_DM;
/

prompt
prompt Creating package MC_HT
prompt ======================
prompt
CREATE OR REPLACE PACKAGE HAI.MC_HT IS
 TYPE MYCUR IS REF CURSOR;
-------------------------------------------------------------------------------
 FUNCTION GET_MENU_CON(P_MA_MENU NVARCHAR2, P_SITE_ROOT NVARCHAR2,P_MA_CAN_BO INT, P_APP NVARCHAR2, P_MODULE NVARCHAR2) RETURN NVARCHAR2;
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_MENU(P_CUR IN OUT MYCUR,P_SITE_ROOT NVARCHAR2,P_MA_CAN_BO INT, P_APP NVARCHAR2, P_MODULE NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE CHECK_DANG_NHAP(
    P_CUR IN OUT MYCUR,
    P_TAI_KHOAN IN NVARCHAR2,
    P_MAT_KHAU IN NVARCHAR2,
    P_MAT_KHAU_MD5 IN NVARCHAR2,
    P_CLIENT_IP CHAR,
    P_BROWSER CHAR,
    P_DEVICE CHAR) ;
END MC_HT;
/

prompt
prompt Creating package MC_PQ
prompt ======================
prompt
CREATE OR REPLACE PACKAGE HAI.MC_PQ IS
  TYPE MYCUR IS REF CURSOR;
  
  /* BEGIN: HOC */
  --PROC: SELECT_NQPQ
  PROCEDURE SELECT_NQPQ(
    P_CUR IN OUT MYCUR,
    P_MA_CAN_BO NUMBER);
    
  --PROC: SELECT_CBPQ
  PROCEDURE SELECT_CBPQ(
    P_CUR IN OUT MYCUR,
    P_MA_CAN_BO NUMBER,
    P_MA_CO_QUAN NVARCHAR2,
    P_MA_TO_CHUYEN_MON NVARCHAR2,
    P_MA_NHOM_QUYEN NVARCHAR2,
    P_TRANG_THAI NUMBER);
    
  -- PROC: DELETE_CONQ
  PROCEDURE DELETE_CONQ(
    P_KQ OUT NUMBER,
    P_MA_CAN_BO NUMBER,
    P_MA_NHOM_QUYEN NVARCHAR2);
    
  /* END: HOC */
  -------------------------------------------------------------------------------
  FUNCTION GET_CHUOI_ALL_QUYEN_CUA_MENU(P_MA_MENU NVARCHAR2,
                                        P_TEN_MENU NVARCHAR2,
                                        P_MA_NHOM_QUYEN NVARCHAR2,
                                        P_MA_CO_QUAN NVARCHAR2) RETURN NCLOB;
  -------------------------------------------------------------------------------
  FUNCTION GET_ALL_NHOM_QUYEN_CUA_CAN_BO(P_MA_CAN_BO INT) RETURN NVARCHAR2;
  -------------------------------------------------------------------------------
  PROCEDURE CHECK_CO_NHOM_QUYEN(P_VAL OUT NVARCHAR2, P_MA_CAN_BO INT,P_MA_NHOM_QUYEN NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE CHECK_CO_QUYEN(P_VAL OUT NVARCHAR2, P_MA_CAN_BO INT,P_MA_QUYEN NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_NHOM_QUYEN(P_CUR IN OUT MYCUR);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_NHOM_QUYEN_DETAIL(P_CUR           IN OUT MYCUR,
                                     P_MA_NHOM_QUYEN NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_NHOM_QUYEN(P_VAL            OUT NVARCHAR2,
                              P_UPDATE_TYPE    NVARCHAR2,
                              P_NGUOI_CAP_NHAT INT,
                              P_MA_NHOM_QUYEN  NVARCHAR2,
                              P_TEN_NHOM_QUYEN NVARCHAR2,
                              P_STT_NHOM_QUYEN INT,
                              P_TRANG_THAI     INT);
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_NHOM_QUYEN(P_VAL           OUT NVARCHAR2,
                              P_NGUOI_XOA     INT,
                              P_MA_NHOM_QUYEN NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_ALL_QUYEN_CUA_NQ(P_CUR IN OUT MYCUR,
                                    P_MA_NHOM_QUYEN NVARCHAR2);
 -------------------------------------------------------------------------------
  PROCEDURE SELECT_ALL_TR_QUYEN_CUA_NQ(P_CUR IN OUT MYCUR,
                                    P_MA_NHOM_QUYEN NVARCHAR2,
                                    P_MA_CO_QUAN NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_ALL_NQ_CO_QUYEN(P_VAL            OUT NVARCHAR2,
                                           P_MA_NHOM_QUYEN  NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE INSERT_NQ_CO_QUYEN(P_VAL          OUT NVARCHAR2,
                                     P_NGUOI_CAP_NHAT INT,
                                     P_MA_NHOM_QUYEN  NVARCHAR2,
                                     P_MA_QUYEN NVARCHAR2);                                           
                                                                               
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_MENU(P_CUR IN OUT MYCUR);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_MENU_DETAIL(P_CUR IN OUT MYCUR, P_MA_MENU NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_MENU(P_VAL            OUT NVARCHAR2,
                        P_UPDATE_TYPE    NVARCHAR2,
                        P_NGUOI_CAP_NHAT INT,
                        P_MA_MENU        NVARCHAR2,
                        P_TEN_MENU       NVARCHAR2,
                        P_STT_MENU       INT,
                        P_TRANG_THAI     INT);
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_MENU(P_VAL       OUT NVARCHAR2,
                        P_NGUOI_XOA INT,
                        P_MA_MENU   NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUYEN_FILTER(P_CUR IN OUT MYCUR, 
                                P_MA_MENU NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUYEN_DETAIL(P_CUR IN OUT MYCUR, P_MA_QUYEN NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_QUYEN(P_VAL                OUT NVARCHAR2,
                         P_UPDATE_TYPE        NVARCHAR2,
                         P_NGUOI_CAP_NHAT     INT,
                         P_MA_QUYEN           NVARCHAR2,
                         P_TEN_QUYEN          NVARCHAR2,
                         P_MA_MENU            NVARCHAR2,
                         P_APPS               NVARCHAR2,
                         P_MODULES            NVARCHAR2,
                         P_HIEN_THI_TREN_MENU INT,
                         P_STT_QUYEN          INT,
                         P_TRANG_THAI         INT);
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_QUYEN(P_VAL       OUT NVARCHAR2,
                         P_NGUOI_XOA INT,
                         P_MA_QUYEN  NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_ALL_NHOM_QUYEN_CAN_BO(P_CUR IN OUT MYCUR,
                                         P_MA_CAN_BO INT);
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_ALL_CB_CO_NHOM_QUYEN(P_VAL             OUT NVARCHAR2,
                                         P_MA_CAN_BO  INT);
  -------------------------------------------------------------------------------
  PROCEDURE INSERT_CB_CO_NHOM_QUYEN(P_VAL                 OUT NVARCHAR2,
                                     P_NGUOI_CAP_NHAT      INT,
                                     P_MA_CAN_BO  INT,
                                     P_MA_NHOM_QUYEN NVARCHAR2); 
---------------------------------------------SELECT CAN BO CO QUAN--------
PROCEDURE SELECT_CAN_BO_CQ(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2);

END MC_PQ;
/

prompt
prompt Creating package TNMT_BTTDC
prompt ===========================
prompt
create or replace package hai.TNMT_BTTDC is
TYPE MYCUR IS REF CURSOR;
------------------------------DM_VB_TIEP_NHAN-----------------------------
PROCEDURE SELECT_VB_TIEP_NHAN(P_CUR IN OUT MYCUR);
-----------------------------------------------------------
  
  PROCEDURE SELECT_VB_TIEP_NHAN_LV(P_CUR IN OUT MYCUR,
                                   P_MA_LINH_VUC   NVARCHAR2  );
 -----------------------------------------------------------
                                  
PROCEDURE SELECT_VB_TIEP_NHAN_DETAIL(P_CUR        IN OUT MYCUR,
                                  P_MA_VB_TIEP_NHAN NVARCHAR2);
-----------------------------------------------------------
PROCEDURE UPDATE_VB_TIEP_NHAN(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_VB_TIEP_NHAN     NVARCHAR2,
                           P_TEN_VB_TIEP_NHAN    NVARCHAR2,
                           P_STT_VB_TIEP_NHAN    INT,
                           P_MA_HINH_THUC        NVARCHAR2,
                           P_TT_VB_TIEP_NHAN     INT,
                           P_TT_GIA_TRI          INT);
 -----------------------------------------------------------

PROCEDURE DELETE_VB_TIEP_NHAN(P_VAL   OUT NVARCHAR2, P_MA_VB_TIEP_NHAN NVARCHAR2);
---------------------------------PHIEU_TIEP_NHAN_HO_SO------------
 PROCEDURE SELECT_PHIEU_TIEP_NHAN(P_CUR IN OUT MYCUR);
 PROCEDURE SELECT_PHIEU_TIEP_NHAN_LV(P_CUR IN OUT MYCUR,P_MA_HINH_THUC NVARCHAR2,P_TT_PTN INT);
  ----------------------------------------------------------
   PROCEDURE SELECT_PHIEU_TIEP_NHAN_WAIT(P_CUR IN OUT MYCUR,P_TT_PHIEU_TIEP_NHAN INT);
  ---------------------------------------
  PROCEDURE SELECT_PHIEU_TIEP_NHAN_DETAIL(P_CUR        IN OUT MYCUR,
                                  P_MA_PHIEU_TIEP_NHAN NVARCHAR2);
 -------------------------------------------------------------------------------
  PROCEDURE UPDATE_PHIEU_TIEP_NHAN(P_VAL            OUT NVARCHAR2,
                           P_MA                     OUT NVARCHAR2,                         
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_PHIEU_TIEP_NHAN    NVARCHAR2,
                           P_TEN_DON_VI            NVARCHAR2,
                           P_TEN_CONG_TRINH    NVARCHAR2,
                           P_NGUOI_GIAO            NVARCHAR2,
                           P_NGUOI_GIAO_BO_SUNG NVARCHAR2,
                           P_CB_NHAN            INT,
                           P_CB_NHAN_BO_SUNG    INT,
                           P_NGAY_GIAO          NVARCHAR2,
                           P_NGAY_HEN_BO_SUNG   NVARCHAR2,
                           P_GHI_CHU            NVARCHAR2,
                           P_STT_PHIEU_TIEP_NHAN   INT,
                           P_MA_HINH_THUC          NVARCHAR2,
                           P_MA_QUAN_HUYEN         NVARCHAR2,
                           P_TT_PHIEU_TIEP_NHAN    INT);
  ----------------------------update_tt_phieu_tiep_nhan---------------------------------------------------
  PROCEDURE UPDATE_TT_PHIEU_TIEP_NHAN(P_MA_PHIEU_TIEP_NHAN    NVARCHAR2); 
   -----------------------------------------------------------------------
                                  
 PROCEDURE DELETE_PHIEU_TIEP_NHAN(P_VAL   OUT NVARCHAR2, P_MA_PHIEU_TIEP_NHAN NVARCHAR2); 
 --------------------------------------VB_DA_TIEP_NHAN--------------------------------
 PROCEDURE SELECT_VB_DA_TIEP_NHAN(P_CUR IN OUT MYCUR, P_MA_HO_SO NVARCHAR2);
 
 PROCEDURE SELECT_VB_DA_TIEP_NHAN_PTN(P_CUR IN OUT MYCUR, P_MA_PHIEU_TIEP_NHAN NVARCHAR2);
  -------------------------------------------------------------------------------
PROCEDURE SELECT_VB_DA_TIEP_NHAN_DETAIL(P_CUR        IN OUT MYCUR,
                                  P_MA_VB_DA_TIEP_NHAN NVARCHAR2);
 -------------------------------------------------------------------------------
  PROCEDURE UPDATE_VB_DA_TIEP_NHAN(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_VB_DA_TIEP_NHAN     NVARCHAR2,
                           P_TEN_VB_TIEP_NHAN    NVARCHAR2,
                           P_STT_VB_TIEP_NHAN    INT,
                           P_GIA_TRI             INT,
                           P_FILEPATH            NVARCHAR2,
                           P_MA_HO_SO  NVARCHAR2,
                           P_TT_VB_TIEP_NHAN     INT,
                           P_MA_VB_TIEP_NHAN_DM  NVARCHAR2);
 ---------------------------------------------------------------------------------
 PROCEDURE UPDATE_VB_DA_TIEP_NHAN1(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_VB_DA_TIEP_NHAN     NVARCHAR2,
                           P_TEN_VB_TIEP_NHAN    NVARCHAR2,
                           P_STT_VB_TIEP_NHAN    INT,
                           P_GIA_TRI             INT,
                           P_FILEPATH            NVARCHAR2,
                           P_MA_PHIEU_TIEP_NHAN  NVARCHAR2,
                           P_TT_VB_TIEP_NHAN     INT,
                           P_MA_VB_TIEP_NHAN_DM  NVARCHAR2);                          
 -------------------------------------------------------------------------------
 PROCEDURE DELETE_VB_DA_TIEP_NHAN(P_VAL   OUT NVARCHAR2, P_MA_VB_DA_TIEP_NHAN NVARCHAR2);                                                           
 ------------------------------------------HINH_THUC_HO_SO------------------
 PROCEDURE SELECT_HINH_THUC(P_CUR IN OUT MYCUR);
  -------------------------------------------------------------------------------
PROCEDURE SELECT_HINH_THUC_DETAIL(P_CUR        IN OUT MYCUR,
                                  P_MA_HINH_THUC NVARCHAR2);
 -------------------------------------------------------------------------------
  PROCEDURE UPDATE_HINH_THUC(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_HINH_THUC     NVARCHAR2,
                           P_TEN_HINH_THUC    NVARCHAR2,
                           P_STT_HINH_THUC    INT,
                           P_TRANG_THAI     INT);                                  
 -------------------------------------------------------------------------------
  PROCEDURE DELETE_HINH_THUC(P_VAL   OUT NVARCHAR2, P_MA_HINH_THUC NVARCHAR2);
   --------------------------------LAN_XU_LY_HO_SO-----------------------------------------------

  
 ---------------------------------VB_XU_LY----------------------------------------------
   
   
   -------------------------------------SELECT_HO_SO--------------------------------------
  
  
  
  ------------------------------------SELECT_HS_EXCEL--------------------------------------------------------
  PROCEDURE SELECT_HO_SO_EXCEL(P_CUR IN OUT MYCUR,P_MA_LINH_VUC NVARCHAR2,P_FROM_DATE NVARCHAR2, P_TO_DATE NVARCHAR2);
  -------------------------------------SELECT_HO_SO_DETAIL--------------------------------------

 
  -------------------------------------UPDATE_HO_SO--------------------------------------

 
  -------------------------------------UPDATE_HO_SO--------------------------------------

  
  ---------------------------------------------------------------------------------------
  PROCEDURE SELECT_PHIEU_TIEP_NHAN_EXCEL(P_CUR        IN OUT MYCUR,
                                  P_TT_PHIEU_TIEP_NHAN INT );
  ---------------------------------------------------------------------------------
                                                      
  PROCEDURE SELECT_PTN_EXCEL_DATE(P_CUR        IN OUT MYCUR,
                                  P_TT_PHIEU_TIEP_NHAN INT,P_FROM_DATE NVARCHAR2,P_TO_DATE NVARCHAR2 );

----------------------------------------ELECT EXCEL TEST HO SO----------------------

------------------------------------------------------------------------------------------

------------------------------------------------DM_THUOC_TINH_HS-----------------------------------
PROCEDURE SELECT_DM_THUOCTINH_HS(P_CUR IN OUT MYCUR);
---------------------------------------------------------------------------
  PROCEDURE SELECT_DM_THUOCTINH_HS_LV(P_CUR IN OUT MYCUR,
                                   P_MA_LINH_VUC   NVARCHAR2  );
 -----------------------------------------------------------------------------
 PROCEDURE SELECT_DM_THUOCTINH_HS_DETAIL(P_CUR        IN OUT MYCUR,
                                  P_MA_THUOC_TINH NVARCHAR2);
      
 -------------------------------------------------------------------------------
  PROCEDURE UPDATE_DM_THUOC_TINH_HS(P_UPDATE_TYPE    NVARCHAR2,
                                  P_VAL   OUT NVARCHAR2,
                           P_MA_THUOC_TINH NVARCHAR2,
                           P_TEN_THUOC_TINH NVARCHAR2,
                           P_GIA_TRI_THUOC_TINH NVARCHAR2,
                           P_TRANG_THAI INT ,
                           P_STT_THUOC_TINH INT ,
                           P_MA_LINH_VUC NVARCHAR2);
                           
 ---------------------------------------------------------GT_THUOC_TINH_HS------------
 PROCEDURE SELECT_GT_THUOCTINH_HS(P_CUR IN OUT MYCUR);
 -----------------------------------------------------------------------------------
  PROCEDURE SELECT_GT_THUOCTINH_1HS_DETAIL(P_CUR        IN OUT MYCUR,
                                  P_MA_HO_SO NVARCHAR2);
 ----------------------------------------------------------------------------------
  PROCEDURE UPDATE_GT_THUOC_TINH_1HS( P_VAL   OUT NVARCHAR2,
    P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_THUOC_TINH NVARCHAR2,
                           P_TEN_THUOC_TINH NVARCHAR2 ,
                           P_GIA_TRI_THUOC_TINH NVARCHAR2,
                           P_TRANG_THAI INT ,
                           P_STT_THUOC_TINH INT,
                           P_MA_LINH_VUC NVARCHAR2,
                           P_MA_HO_SO NVARCHAR2,
                           P_MA_THUOC_TINH_DM NVARCHAR2);
 ---------------------------------------------------HOSO2--------------------------------
    PROCEDURE SELECT_HOSO2(P_CUR IN OUT MYCUR,P_MA_LINH_VUC NVARCHAR2);
    ----------------------------------------------------------------------------------
     PROCEDURE SELECT_HOSO2_DETAIL(P_CUR        IN OUT MYCUR,
                                  P_MA_HO_SO NVARCHAR2);
   ----------------------------------------------------------------------------------------
   PROCEDURE UPDATE_HO_SO2( P_VAL   OUT NVARCHAR2,
     P_UPDATE_TYPE NVARCHAR2,
     P_MA_HO_SO2 NVARCHAR2,
     P_KHHS NVARCHAR2,
     P_TEN_HO_SO NVARCHAR2,
     P_TEN_CONG_TRINH NVARCHAR2,
     P_MA_HUYEN NVARCHAR2,
     P_MA_QUOC_TICH NVARCHAR2,
     P_MA_HINH_THUC NVARCHAR2,
     P_NGAY_LAP_HO_SO NVARCHAR2,
     P_TRANG_THAI INT ,
     P_STT INT  ,
     P_TTSTNMT NVARCHAR2,
     P_QDUBND NVARCHAR2,
     P_TTSTC NVARCHAR2,
     P_NGUOI_NOP NVARCHAR2,
     P_TTSTNMTSH NVARCHAR2,
     P_QDUBNDSH NVARCHAR2,
     P_TTSTCSH NVARCHAR2,
     P_TEN_DON_VI NVARCHAR2,
     P_LINH_VUC NVARCHAR2,
     P_HT_TRA_TIEN NVARCHAR2,
     P_LOAI_DAT_GIAO NVARCHAR2,
     P_LOAI_DAT_THUE NVARCHAR2,
     P_GIA_GIAO NVARCHAR2,
     P_KPTD NVARCHAR2,
     P_TT_KPTD INT,
     P_GIA_THUE NVARCHAR2
     );
-------------------------------------------------------------------------------------------------
  PROCEDURE SELECT_GT_THUOCTINHLV(P_CUR        IN OUT MYCUR,
                                  P_MA_LINH_VUC NVARCHAR2); 
 ----------------------------------THU VIEN PHAP LUAT--------------------------------------
 PROCEDURE SELECT_VB_PL(P_CUR IN OUT MYCUR);
 -------------------------------------------------------------------------------------------
 PROCEDURE SELECT_VB_PL_DETAIL(P_CUR        IN OUT MYCUR,
                                  P_MA_VB_PL NVARCHAR2);
 -------------------------------------------------------------------------------------------
 PROCEDURE UPDATE_VB_PL(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_VB     NVARCHAR2,
                           P_TRICH_YEU    NVARCHAR2,
                           P_SO_HIEU    NVARCHAR2,
                           P_TRANG_THAI        INT,
                           P_STT     INT,
                           P_CO_QUAN_BAN_HANH NVARCHAR2,
                           P_NGAY_BAN_HANH NVARCHAR2,
                           P_FILE_PATH NVARCHAR2   
                           ) ;
                           
  --------------------------------------------EXCEL_KPTD----------------------------------
  PROCEDURE SELECT_HO_SO_KP_EXCEL(P_CUR IN OUT MYCUR,P_MA_LINH_VUC NVARCHAR2,P_FROM_DATE NVARCHAR2, P_TO_DATE NVARCHAR2,P_TTKPTD NVARCHAR2);  
  ------------------------------------------------------------------------------------------------
  PROCEDURE SELECT_HO_SO_LV_EXCEL(P_CUR IN OUT MYCUR,P_MA_LINH_VUC NVARCHAR2,P_FROM_DATE NVARCHAR2, P_TO_DATE NVARCHAR2,P_LINHVUC NVARCHAR2);                       
  
  
      ---------------------------------------------DELETE-HO-SO---------------------------------------------------
PROCEDURE DELETE_HO_SO2(P_VAL   OUT NVARCHAR2, P_MA_HO_SO NVARCHAR2);
    ---------------------------------------------DELETE-GTTT---------------------------------------------------
PROCEDURE DELETE_GT_THUOCTINH_HS(P_VAL   OUT NVARCHAR2, P_MA_HO_SO NVARCHAR2);
    ---------------------------------------------DELETE-VPTN---------------------------------------------------
PROCEDURE DELETE_VBTN(P_VAL   OUT NVARCHAR2, P_MA_HO_SO NVARCHAR2);

    ----------------------------------------\
    PROCEDURE SELECT_HO_SO_EXCEL_CSBT(P_CUR IN OUT MYCUR,P_MA_LINH_VUC NVARCHAR2);
     PROCEDURE SELECT_HO_SO_EXCEL_HSGKD(P_CUR IN OUT MYCUR,P_MA_LINH_VUC NVARCHAR2);    
    ---------------------------------------------
   PROCEDURE SELECT_HO_SO_KP_EXCEL_GCSBT(P_CUR IN OUT MYCUR,P_MA_LINH_VUC NVARCHAR2,P_TTKPTD NVARCHAR2);
      PROCEDURE SELECT_HO_SO_LV_EXCEL_GTCMDSD(P_CUR IN OUT MYCUR,P_MA_LINH_VUC NVARCHAR2,P_LINHVUC NVARCHAR2);                                                    
end TNMT_BTTDC;
/

prompt
prompt Creating package TNMT_DATCONG
prompt =============================
prompt
create or replace package hai.TNMT_DATCONG is
 TYPE MYCUR IS REF CURSOR; 
 ------------------------------DC_VAN_BAN_SDD------------------------------------------
PROCEDURE SELECT_VANBAN_SDD(P_CUR  IN OUT MYCUR, P_MA_HS_DAT NVARCHAR2);
PROCEDURE SELECT_VANBAN_SDD_DETAIL(P_CUR  IN OUT MYCUR,P_MA_HS_DAT NVARCHAR2,P_MA_HS NVARCHAR2);
 ------------------------------DC_SU_DUNG_DAT------------------------------------------
PROCEDURE SELECT_SU_DUNG_DAT(P_CUR  IN OUT MYCUR, P_MA_HS_DAT number);
---------------------------------------------------------------------------------------
PROCEDURE SELECT_SU_DUNG_DAT_DETAIL(P_CUR  IN OUT MYCUR,P_MA_HS_DAT number,P_MA_SU_DUNG_DAT NVARCHAR2);
------------------------------DC_THUA_DAT------------------------------------------
PROCEDURE SELECT_DC_THUADAT(P_CUR  IN OUT MYCUR, P_MA_PHUONG_XA NVARCHAR2);
--------------------------------DC_HO_SO_DAT----------------------------------------
PROCEDURE UPDATE_DC_HOSODAT(P_VAL            OUT NVARCHAR2,
                           P_MA_HS_DAT     NUMBER,
                           P_UPDATE_TYPE    NVARCHAR2,
                          -- P_MA_HUYEN    NVARCHAR2,
                           P_TEN_DON_VI    NVARCHAR2,
                           P_PHUONG_THUC NVARCHAR2,
                           P_MA_MUC_DICH NVARCHAR2,
                           P_THUOC_TO_CHUC int,
                           P_MA_QUOC_TICH NVARCHAR2,
                           P_SDT NVARCHAR2, 
                           P_GHI_CHU NVARCHAR2,
                           P_MA_HINH_THUC NVARCHAR2,
                           P_DAU_GIA INT,
                           P_TIEN_DAU_GIA FLOAT,
                           P_LY_DO NVARCHAR2,
                           P_TRANG_THAI NVARCHAR2,
                           P_MA_THUA NUMBER,
                           P_TIEN_THUE NVARCHAR2,
                           P_ID_DONG NUMBER,
                           P_THOI_HAN INT,
                           P_TG_BD NVARCHAR2,
                           P_TG_KT NVARCHAR2,
                           P_MA_DOI_TUONG INT,
                           P_DIEN_TICH_SD FLOAT,
                           P_DON_VI_TO_CHUC_DAU_GIA NVARCHAR2
                           ); 
                           --------
                            
PROCEDURE UPDATE_DC_HOSODAT_BD(P_VAL            OUT NVARCHAR2,
                           P_MA_HS_DAT     NUMBER,
                          -- P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_HUYEN    NVARCHAR2,
                           P_TEN_DON_VI    NVARCHAR2,
                           P_PHUONG_THUC NVARCHAR2,
                           P_MA_MUC_DICH NVARCHAR2,
                           P_THUOC_TO_CHUC int,
                           P_MA_QUOC_TICH NVARCHAR2,
                           P_SDT NVARCHAR2, 
                           P_GHI_CHU NVARCHAR2,
                           P_MA_HINH_THUC NVARCHAR2,
                           P_DAU_GIA INT,
                           P_TIEN_DAU_GIA FLOAT, 
                           P_LY_DO NVARCHAR2,
                           P_TRANG_THAI NVARCHAR2,
                           P_MA_THUA NUMBER,
                           P_TIEN_THUE NVARCHAR2,
                           P_ID_DONG NUMBER,
                           P_THOI_HAN INT,
                           P_TG_BD NVARCHAR2,
                           P_TG_KT NVARCHAR2,
                           P_MA_DOI_TUONG INT,
                           P_DIEN_TICH_SD FLOAT
                           );
--------------------------------------------------------------------------------------
PROCEDURE UPDATE_DC_VANBAN_SDD(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_HS     NUMBER,
                           P_MA_HS_DAT     NUMBER,
                           P_TIEU_DE_HS    NVARCHAR2,
                           P_TOM_TAT_HS    NVARCHAR2,
                           P_FILE_HS    NVARCHAR2,
                           P_NGAY_BAN_HANH     NVARCHAR2,
                           P_CO_QUAN_BAN_HANH     NVARCHAR2,
                           P_MA_LOAI_VAN_BAN     NVARCHAR2,
                          -- P_MA_HS_DAT     NUMBER,
                           --P_NGAY_UP     NVARCHAR2,
                           P_NGUOI_UP    NVARCHAR2,
                           P_SO_KY_HIEU     NVARCHAR2,
                           P_SO_TRANG     INT,
                           P_TT_VAN_BAN     INT
                           );   
--------------------------------------------------------------------------------------
  PROCEDURE DELETE_DC_VANBAN_SDD(P_VAL   OUT NVARCHAR2, P_MA_HS NUMBER); 
 --------------------------------------------------------------------------------------
        PROCEDURE UPDATE_DC_SU_DUNG_DAT(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_SU_DUNG_DAT     number,
                           P_MA_HS_DAT number,
                           P_NGAY_SD_DAT    NVARCHAR2,
                           P_GHI_CHU_HSD    NVARCHAR2,
                           P_THANH_TIEN_SDD     FLOAT,
                           P_MA_GIAO_DICH     NVARCHAR2,
                           P_DON_GIA     INT
                           );
--------------------------------------------------------------------------------------
  PROCEDURE DELETE_DC_SU_DUNG_DAT(P_VAL   OUT NVARCHAR2, P_MA_SU_DUNG_DAT NUMBER);
--------------------------------------------------------------------------------------   
 PROCEDURE REPORT_TC_THUEDATHUYEN(P_CUR  IN OUT MYCUR, P_MA_HUYEN NVARCHAR2);
--------------------------------------------------------------------------------------  
 PROCEDURE REPORT_NUOC_NGOAI_THUE(P_CUR  IN OUT MYCUR, P_NAM NVARCHAR2);
-------------------------------------------------------------------------------------- 
 PROCEDURE REPORT_XAY_DUNG_CSDL_DAT(P_CUR  IN OUT MYCUR);
--------------------------------------------------------------------------------------  
PROCEDURE REPORT_GIAO_DAT(P_CUR  IN OUT MYCUR, P_NAM NVARCHAR2);
--------------------------------------------------------------------------------------
PROCEDURE REPORT_THUE_DAT(P_CUR  IN OUT MYCUR, P_NAM NVARCHAR2);
--------------------------------------------------------------------------------------
 PROCEDURE REPORT_VPDD(P_CUR  IN OUT MYCUR, P_NAM NVARCHAR2);                         
-------------------------------------------------------------------------------------- 
PROCEDURE REPORT_THUHOIDAT(P_CUR  IN OUT MYCUR, P_NAM NVARCHAR2);
--------------------------------------------------------------------------------------  
 PROCEDURE REPORT_CHUYENDICH(P_CUR  IN OUT MYCUR, P_NAM NVARCHAR2);
 --------------------------------------------------------------------------------------     
  PROCEDURE REPORT_DODAC(P_CUR  IN OUT MYCUR, P_NAM NVARCHAR2) ; 
--------------------------------------------------------------------------------------     
    PROCEDURE DELETE_HO_SO_DAT(P_VAL   OUT NVARCHAR2, P_MA_HS_DAT NVARCHAR2);
--------------------------------------------------------------------------------------
    PROCEDURE REPORT_12(P_CUR  IN OUT MYCUR, P_NAM NVARCHAR2) ;           
--------------------------------------------------------------------------------------- 
 PROCEDURE REPORT_3(P_CUR  IN OUT MYCUR, P_NAM NVARCHAR2); 
 --------------------------------------------------------------------------------------- 
     PROCEDURE REPORT_2(P_CUR  IN OUT MYCUR, P_NAM NVARCHAR2);  
 ---------------------------------------------------------------------------------------   
 PROCEDURE REPORT_DAU_GIA(P_CUR  IN OUT MYCUR 
   --, P_NAM NVARCHAR2
   );
 ---------------------------------------------------------------------------------------
 PROCEDURE REPORT_GIAO_THUE_TC(P_CUR  IN OUT MYCUR) ;
 ------------------------------------------------------------------------------------
 PROCEDURE REPORT_GIAO_THUE_CN(P_CUR  IN OUT MYCUR); 
  ------------------------------------------------------------------------------------
 PROCEDURE REPORT_5B(P_CUR  IN OUT MYCUR);
 ------------------------------------------------------------------------------------
 PROCEDURE REPORT_1(P_CUR  IN OUT MYCUR);
 ------------------------------------------------------------------------------------
 PROCEDURE REPORT_2N(P_CUR  IN OUT MYCUR);
 ------------------------------------------------------------------------------------
 PROCEDURE REPORT_3N(P_CUR  IN OUT MYCUR);
------------------------------------------------------------------------------------ 
PROCEDURE REPORT_5A(P_CUR  IN OUT MYCUR);   
end TNMT_DATCONG;
/

prompt
prompt Creating package TNMT_DATCONG_DM
prompt ================================
prompt
create or replace package hai.TNMT_DATCONG_DM is
 TYPE MYCUR IS REF CURSOR; 
  PROCEDURE SELECT_HINH_THUC_DM(P_CUR IN OUT MYCUR);
---------------------------DM_HINH_THUC---------------------------------------
PROCEDURE SELECT_HINH_THUC(P_CUR IN OUT MYCUR) ;
-------------------------------------------------------------------------------
PROCEDURE SELECT_HINH_THUC_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_HINH_THUC NVARCHAR2);
-------------------------------------------------------------------------------                                  
PROCEDURE UPDATE_HINH_THUC(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_HINH_THUC     NVARCHAR2,
                           P_TEN_HINH_THUC    NVARCHAR2,
                           P_STT_HINH_THUC    INT,
                           P_TT_HINH_THUC     INT);     
                           
 -------------------------------------------------------------------------------
PROCEDURE DELETE_HINH_THUC(P_VAL   OUT NVARCHAR2, P_MA_HINH_THUC NVARCHAR2);  
---------------------------DM_LOAI_VAN_BAN---------------------------------------
PROCEDURE SELECT_LOAI_VAN_BAN(P_CUR IN OUT MYCUR) ;
-------------------------------------------------------------------------------
PROCEDURE SELECT_LOAI_VAN_BAN_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_LOAI_VAN_BAN NVARCHAR2);
-------------------------------------------------------------------------------                                  
PROCEDURE UPDATE_LOAI_VAN_BAN(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_LOAI_VAN_BAN     NVARCHAR2,
                           P_TEN_LOAI_VAN_BAN    NVARCHAR2,
                           P_STT_LOAI_VAN_BAN    INT,
                           P_TT_LOAI_VAN_BAN     INT);     
                           
 -------------------------------------------------------------------------------
PROCEDURE DELETE_LOAI_VAN_BAN(P_VAL   OUT NVARCHAR2, P_MA_LOAI_VAN_BAN NVARCHAR2);   
---------------------------DM_LOAI_DAT---------------------------------------
PROCEDURE SELECT_LOAI_DAT(P_CUR IN OUT MYCUR) ;
-------------------------------------------------------------------------------
PROCEDURE SELECT_LOAI_DAT_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_LOAI_DAT NVARCHAR2);
-------------------------------------------------------------------------------
PROCEDURE UPDATE_LOAI_DAT(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_LOAI_DAT     number,
                           P_TEN_LOAI_DAT    NVARCHAR2,
                           P_DAT_NONG_NGHIEP    INT,
                           P_STT_LOAI_DAT    INT,
                           P_TT_LOAI_DAT     INT,
                           P_MA    NVARCHAR2);     
                           
 -------------------------------------------------------------------------------
PROCEDURE DELETE_LOAI_DAT(P_VAL   OUT NVARCHAR2, P_MA_LOAI_DAT NVARCHAR2);
---------------------------DM_MUC_DICH_SU_DUNG_DAT---------------------------------------
PROCEDURE SELECT_MUC_DICH_SU_DUNG_DAT(P_CUR IN OUT MYCUR) ;
-------------------------------------------------------------------------------
PROCEDURE SELECT_MUC_DICH_SD_DAT_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_MUC_DICH_SU_DUNG_DAT NVARCHAR2);
-------------------------------------------------------------------------------
 PROCEDURE UPDATE_MUC_DICH_SU_DUNG_DAT(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_MUC_DICH_SU_DUNG_DAT     NVARCHAR2,
                           P_TEN_MUC_DICH_SU_DUNG_DAT    NVARCHAR2,
                           P_LOAI_MUC_DICH_MUC_DICH    INT,
                           P_STT_MUC_DICH_SU_DUNG_DAT    INT,
                           P_TT_MUC_DICH_SU_DUNG_DAT     INT,
                           P_CHUYEN_MUC_DICH    NVARCHAR2,
                           P_MA    NVARCHAR2);     
                           
-------------------------------------------------------------------------------
PROCEDURE DELETE_MUC_DICH_SU_DUNG_DAT(P_VAL   OUT NVARCHAR2, P_MA_MUC_DICH_SU_DUNG_DAT NVARCHAR2);
  ---------------------------DM_GIAO_DICH---------------------------------------
PROCEDURE SELECT_GIAO_DICH(P_CUR IN OUT MYCUR) ;
-------------------------------------------------------------------------------
PROCEDURE SELECT_GIAO_DICH_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_GIAO_DICH NVARCHAR2);
-------------------------------------------------------------------------------                                  
PROCEDURE UPDATE_GIAO_DICH(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_GIAO_DICH     NVARCHAR2,
                           P_TEN_GIAO_DICH    NVARCHAR2,
                           P_STT_GIAO_DICH    INT,
                           P_TT_GIAO_DICH     INT);     
                           
 -------------------------------------------------------------------------------
PROCEDURE DELETE_GIAO_DICH(P_VAL   OUT NVARCHAR2, P_MA_GIAO_DICH NVARCHAR2);   
---------------------------DM_CSDL_DAT---------------------------------------
PROCEDURE SELECT_CSDL_DAT(P_CUR IN OUT MYCUR) ;
-------------------------------------------------------------------------------
PROCEDURE SELECT_CSDL_DAT_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_CSDL_DAT NVARCHAR2);
-------------------------------------------------------------------------------                                  
PROCEDURE UPDATE_CSDL_DAT(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_CSDL_DAT     NVARCHAR2,
                           P_TEN_CSDL_DAT    NVARCHAR2,
                           P_STT_CSDL_DAT    INT,
                           P_TT_CSDL_DAT     INT);     
                           
 -------------------------------------------------------------------------------
PROCEDURE DELETE_CSDL_DAT(P_VAL   OUT NVARCHAR2, P_MA_CSDL_DAT NVARCHAR2);   
---------------------------DM_LOAI_LUY_TIEN---------------------------------------
PROCEDURE SELECT_LOAI_LUY_TIEN(P_CUR IN OUT MYCUR) ;
-------------------------------------------------------------------------------
PROCEDURE SELECT_LOAI_LUY_TIEN_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_LOAI_LUY_TIEN NVARCHAR2);
-------------------------------------------------------------------------------                                  
PROCEDURE UPDATE_LOAI_LUY_TIEN(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_LOAI_LUY_TIEN     number,
                           P_TEN_LOAI_LUY_TIEN    NVARCHAR2,
                           P_STT_LOAI_LUY_TIEN    INT,
                           P_TT_LOAI_LUY_TIEN     INT);     
                           
 -------------------------------------------------------------------------------
PROCEDURE DELETE_LOAI_LUY_TIEN(P_VAL   OUT NVARCHAR2, P_MA_LOAI_LUY_TIEN NVARCHAR2);   
---------------------------DM_QH_CSDL---------------------------------------
PROCEDURE SELECT_QH_CSDL(P_CUR IN OUT MYCUR,P_MA_QUAN_HUYEN NVARCHAR2,P_MA_TINH_THANH NVARCHAR2) ;
-------------------------------------------------------------------------------
PROCEDURE SELECT_QH_CSDL_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_QH_CSDL NVARCHAR2);
-------------------------------------------------------------------------------
   PROCEDURE UPDATE_QH_CSDL(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_QH_CSDL     NVARCHAR2,
                           P_NAMCAPNHAT    NVARCHAR2,
                           P_MA_PHUONG_XA    NVARCHAR2,
                           P_MA_CSDL_DAT    NVARCHAR2,
                            P_SO_LUONG     INT,
                           P_TRANG_THAI     INT);
-------------------------------------------------------------------------------
PROCEDURE DELETE_QH_CSDL(P_VAL   OUT NVARCHAR2, P_MA_QH_CSDL NVARCHAR2) ;
---------------------------DM_CD_MUC_DICH---------------------------------------
PROCEDURE SELECT_CD_MUC_DICH(P_CUR IN OUT MYCUR) ;
-------------------------------------------------------------------------------
PROCEDURE SELECT_CD_MUC_DICH_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_CD_MUC_DICH NVARCHAR2);
-------------------------------------------------------------------------------
PROCEDURE UPDATE_CD_MUC_DICH(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_CD_MUC_DICH     NVARCHAR2,
                           P_TEN_CD_MUC_DICH    NVARCHAR2,
                           P_LA_NOI_BO    INT,
                           P_STT_CD_MUC_DICH    INT,
                           P_TT_CD_MUC_DICH     INT);     
                           
 -------------------------------------------------------------------------------
PROCEDURE DELETE_CD_MUC_DICH(P_VAL   OUT NVARCHAR2, P_MA_CD_MUC_DICH NVARCHAR2);
------------------------------DC_QH_MUC_DICH_SD---------------------------------
PROCEDURE SELECT_QH_MUC_DICH_SD(P_CUR IN OUT MYCUR); 
-------------------------------------------------------------------------------
  PROCEDURE SELECT_QH_MUC_DICH_SD_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_QH_MUC_DICH_SD NVARCHAR2);
-------------------------------------------------------------------------------
PROCEDURE UPDATE_QH_MUC_DICH_SD(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_QH_MUC_DICH_SD     NVARCHAR2,
                           P_NAMCAPNHAT    NVARCHAR2,
                           P_MA_QUAN_HUYEN    NVARCHAR2,
                           P_MA_CD_MUC_DICH    NVARCHAR2,
                           P_DIEN_TICH     FLOAT);
-------------------------------------------------------------------------------
  PROCEDURE DELETE_QH_MUC_DICH_SD(P_VAL   OUT NVARCHAR2, P_MA_QH_MUC_DICH_SD NVARCHAR2); 
-------------------------------------------------------------------------------  
PROCEDURE SELECT_DC_HO_SO_DAT(P_CUR IN OUT MYCUR, P_MA_QUAN_HUYEN NVARCHAR2);  
-------------------------------------------------------------------------------
PROCEDURE SELECT_DC_HO_SO_DAT_DETAIL(P_CUR  IN OUT MYCUR,P_MA_HS_DAT NVARCHAR2); 
-------------------------------------------------------------------------------
PROCEDURE SELECT_DC_THUA_DAT(P_CUR IN OUT MYCUR, P_MA_QUAN_HUYEN NVARCHAR2, P_MA_PHUONG_XA NVARCHAR2,P_DON_VI NVARCHAR2,P_MA_MUC_DICH NVARCHAR2,P_MA_HINH_THUC NVARCHAR2,P_NAM NVARCHAR2,P_TRANG_THAI NVARCHAR2);
-------------------------------------------------------------------------------  
PROCEDURE SELECT_DC_THUA_DAT_DETAIL(P_CUR IN OUT MYCUR, P_MA_THUA NVARCHAR2);
-------------------------------------------------------------------------------
PROCEDURE UPDATE_DC_THUADAT(P_VAL            OUT NVARCHAR2,
                       
                           P_MA_THUA     INT,
                           P_LOAI_DAT    NVARCHAR2,
                           P_SO_THUA    INT,
                           P_THUADATGOC    NVARCHAR2,
                           P_MA_PHUONG_XA    NVARCHAR2,
                           P_ID_BIEN_DONG   INT,
                           P_TRANG_THAI_SD   INT,
                           P_MA_MUC_DICH_SD    NVARCHAR2,
                           P_HINH_THUC_SD NVARCHAR2,
                            P_FILE_HS nvarchar2);                         
-------------------------------------------------------------------------------
PROCEDURE UPDATE_DC_THUADAT_THEM(P_VAL            OUT NVARCHAR2,
                       
                           P_LOAI_DAT    NVARCHAR2,
                           P_SO_THUA    INT,
                           P_THUADATGOC    NVARCHAR2,
                           P_MA_PHUONG_XA NVARCHAR2,
                           --
                           P_ID_DONG INT,
                           P_TRANG_THAI_SD INT,
                           P_MUC_DICH_SD NVARCHAR2,
                           P_MA_HINH_THUC NVARCHAR2,
                           --
                           P_NAM_CAP_NHAT NVARCHAR2,
                           P_DIEN_TICH FLOAT,
                           P_TOA_DO NVARCHAR2,
                           P_LA_DAT_CONG INT,
                           P_TO_BAN_DO NVARCHAR2,
                           P_LA_THUOC_TO_CHUC NVARCHAR2,
                           P_SO_GCN_DAT NVARCHAR2,
                           P_KET_QUA_XD NVARCHAR2,
                           P_MA_LOAI_LUY_TIEN NVARCHAR2,
                           P_DK_KE_KHAI INT,
                           ------
                           P_VI_TRI NVARCHAR2,
                           P_NGUOI_SU_DUNG NVARCHAR2,
                           P_THOI_HAN INT,
                           P_TG_BD NVARCHAR2,
                           P_TG_KT NVARCHAR2,
                           P_SU_DUNG NVARCHAR2,
                           P_MA_CAP_QUAN_LY   INT,
                            P_FILE_HS nvarchar2
                           ) ;
-------------------------------------------------------------------------------
  PROCEDURE DELETE_DC_THUADAT_LUYTIEN(P_VAL   OUT NVARCHAR2, P_MA_THUADAT NVARCHAR2) ;                            
  -------------------------------------------------------------------------------
PROCEDURE SELECT_LUY_TIEN(P_CUR IN OUT MYCUR,P_MA_THUADAT NVARCHAR2) ;
  -------------------------------------------------------------------------------
PROCEDURE SELECT_LUY_TIEN_DETAIL(P_CUR IN OUT MYCUR,P_MA_LUY_TIEN number,P_MA_THUA INT);
---------------------------------------------------------------------------------
PROCEDURE UPDATE_LUY_TIEN_DAT(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_LUY_TIEN NUMBER,
                           P_NAM_CAP_NHAT NVARCHAR2,
                           P_DIEN_TICH FLOAT,
                           P_TOA_DO NVARCHAR2,
                           P_LA_DAT_CONG INT,
                           P_TOA_DO_BAN_DO NVARCHAR2,
                           P_LA_THUOC_TO_CHUC NVARCHAR2,
                           P_SO_GCN_DAT NVARCHAR2,
                           P_KET_QUA_XD NVARCHAR2,
                           P_MA_LOAI_LUY_TIEN NVARCHAR2,
                           P_DK_KE_KHAI INT,
                           P_MA_THUA NUMBER,
                           
                           P_VI_TRI NVARCHAR2,
                           P_NGUOI_SU_DUNG NVARCHAR2,
                           P_THOI_HAN INT,
                           P_TG_BD NVARCHAR2,
                           P_TG_KT NVARCHAR2,
                           P_SU_DUNG NVARCHAR2,
                           P_MA_CAP_QUAN_LY   INT
                           );
----------------------------------------------------------------------------------
    PROCEDURE DELETE_DC_LUYTIEN(P_VAL   OUT NVARCHAR2, P_MA_LUY_TIEN NVARCHAR2);
----------------------------------------------------------------------------------
PROCEDURE SELECT_DAT_HUYEN(P_CUR IN OUT MYCUR, P_MA_QUAN_HUYEN NVARCHAR2);     
----------------------------------------------------------------------------------
  PROCEDURE SELECT_DAT_HUYEN_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_DAT_HUYEN NVARCHAR2);
----------------------------------------------------------------------------------
  PROCEDURE UPDATE_DAT_HUYEN(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_DAT_HUYEN     NUMBER,
                           P_NAM_CAP_NHAT    NVARCHAR2,
                           P_DIEN_TICH_TU_NHIEN    FLOAT,
                           P_DIEN_TICH_DO_DAC     FLOAT,
                           P_MA_QUAN_HUYEN     NVARCHAR2);
----------------------------------------------------------------------------------
  PROCEDURE DELETE_DAT_HUYEN(P_VAL   OUT NVARCHAR2, P_MA_DAT_HUYEN NVARCHAR2);
----------------------------------------------------------------------------------  
 PROCEDURE SELECT_BIEU_DO_DAT_CONG(P_CUR  IN OUT MYCUR);                          
 ---------------------------------------------------------------------------------- 
PROCEDURE SELECT_NAM_TINH(P_CUR  IN OUT MYCUR);  
 ----------------------------------------------------------------------------------
  PROCEDURE SELECT_DAT_HUYEN_TINH(P_CUR  IN OUT MYCUR,P_NAM NVARCHAR2);
  ----------------------------------------------------------------------------------  
  PROCEDURE SELECT_DAT_TONG_TINH(P_CUR  IN OUT MYCUR,P_NAM NVARCHAR2);       
 ----------------------------------------------------------------------------------
PROCEDURE SELECT_DC_CHUYEN_DICH_LOAI_DAT(P_CUR IN OUT MYCUR,P_QUAN_HUYEN NVARCHAR2,P_NAM NVARCHAR2);
----------------------------------------------------------------------------------
PROCEDURE SELECT_DC_CD_LOAI_DAT_DETAIL(P_CUR  IN OUT MYCUR, P_MA_CD_DAT INT);
----------------------------------------------------------------------------------
 PROCEDURE UPDATE_DC_CD_LOAI_DAT(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_CD_DAT INT ,
       P_MA_QUAN_HUYEN NVARCHAR2,
       P_MA_LOAI_DAT NVARCHAR2,
       P_NAM_CAP_NHAT NVARCHAR2,--BIEU 3
       P_C_THUA_DAT_KK INT  ,
       P_C_THUA_DAT_KK_LT INT ,--CÓ LUỸ TIẾN
       P_S_THUA_DAT_KK FLOAT ,
       P_S_THUA_DAT_KK_LT FLOAT ,--CÓ LUỸ TIẾN
       P_C_THUA_DAT_XD INT ,
       P_C_THUA_DAT_XD_LT INT  ,--CÓ LUỸ TIẾN
       P_S_THUA_DAT_XD FLOAT   ,
       P_S_THUA_DAT_XD_LT FLOAT  ,--CÓ LUỸ TIẾN
       P_GHI_CHU_B3 NVARCHAR2,
       P_S_CAN_CAP FLOAT , --BIEU_02
       P_S_CAN_CAP_TC FLOAT , 
       P_S_CAN_CAP_CN FLOAT , 
       P_C_GCN INT   , 
       P_C_GCN_LT INT   ,
       P_C_GCN_TC INT   , 
       P_C_GCN_TC_LT INT ,   
       P_C_GCN_CN INT , 
       P_C_GCN_CN_LT INT ,
       P_S_GCN INT  , 
       P_S_GCN_LT INT  ,
       P_S_GCN_TC INT  , 
       P_S_GCN_TC_LT INT ,   
       P_S_GCN_CN INT , 
       P_S_GCN_CN_LT INT ,
       P_C_GCN_NGUOI INT ,
       P_GHI_CHU_B2 NVARCHAR2 ); 
----------------------------------------------------------------------------------    
PROCEDURE DELETE_DC_CD_LOAI_DAT(P_VAL   OUT NVARCHAR2, P_MA_CD_DAT NVARCHAR2);   
----------------------------------------------------------------------------------
PROCEDURE SELECT_BIEN_DONG(P_CUR IN OUT MYCUR);
----------------------------------------------------------------------------------
PROCEDURE SELECT_BIEN_DONG_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_ID_DONG NVARCHAR2);
----------------------------------------------------------------------------------
  PROCEDURE UPDATE_BIEN_DONG(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_ID_DONG     number,
                           P_TEN_BIEN_DONG    NVARCHAR2,
                           P_LOAI NVARCHAR2,
                           P_TRANG_THAI INT);
----------------------------------------------------------------------------------
  PROCEDURE DELETE_BIEN_DONG(P_VAL   OUT NVARCHAR2, P_ID_DONG INT);
----------------------------------------------------------------------------------
 PROCEDURE SELECT_MUC_DICH_SD_ALL(P_CUR IN OUT MYCUR);
 ----------------------------------------------------------------------------------
 PROCEDURE SELECT_HINH_THUC_SD_ALL(P_CUR IN OUT MYCUR) ;
 ----
 FUNCTION datediff (datepart IN VARCHAR2, date_from IN DATE, date_to IN DATE)RETURN NUMBER;
 ---------
  PROCEDURE SELECT_THUADAT_SD(P_CUR IN OUT MYCUR);
  ------
     PROCEDURE SELECT_BIEN_DONG_HS(P_CUR IN OUT MYCUR);
       ---
       
PROCEDURE UPDATE_DC_HOSODAT(P_VAL            OUT NVARCHAR2,
                           P_MA_HS_DAT     NUMBER,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_HUYEN    NVARCHAR2,
                           P_TEN_DON_VI    NVARCHAR2,
                           P_PHUONG_THUC NVARCHAR2,
                           P_MA_MUC_DICH NVARCHAR2,
                           P_THUOC_TO_CHUC int,
                           P_MA_QUOC_TICH NVARCHAR2,
                           P_SDT NVARCHAR2, 
                           P_GHI_CHU NVARCHAR2,
                           P_MA_HINH_THUC NVARCHAR2,
                           P_DAU_GIA INT,
                           P_TIEN_DAU_GIA FLOAT,
                           P_LY_DO NVARCHAR2,
                           P_TRANG_THAI NVARCHAR2,
                           P_MA_THUA NUMBER,
                           P_TIEN_THUE NVARCHAR2,
                           P_ID_DONG NUMBER,
                           P_MA_DOI_TUONG INT
                           );
-------------------------------------------------------------
PROCEDURE SELECT_DOI_TUONG(P_CUR IN OUT MYCUR);
----------------------------------------------------------------------------------
   PROCEDURE SELECT_DOI_TUONG_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_DOI_TUONG NVARCHAR2);
----------------------------------------------------------------------------------
  PROCEDURE UPDATE_DOI_TUONG(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_DOI_TUONG     INT,
                           P_TEN_DOI_TUONG    NVARCHAR2);
----------------------------------------------------------------------------------
PROCEDURE DELETE_DOI_TUONG(P_VAL   OUT NVARCHAR2, P_MA_DOI_TUONG NVARCHAR2);
----------------------------------------------------------------------------------
PROCEDURE SELECT_CAP_QUAN_LY(P_CUR IN OUT MYCUR);
----------------------------------------------------------------------------------
PROCEDURE SELECT_CAP_QUAN_LY_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_CAP_QUAN_LY NVARCHAR2);
PROCEDURE SELECT_CAP_QUAN_LY_DM(P_CUR IN OUT MYCUR);
----------------------------------------------------------------------------------
  PROCEDURE UPDATE_CAP_QUAN_LY(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_CAP_QUAN_LY     INT,
                           P_TEN_CAP_QUAN_LY    NVARCHAR2) ;
----------------------------------------------------------------------------------
 PROCEDURE DELETE_CAP_QUAN_LY(P_VAL   OUT NVARCHAR2, P_MA_CAP_QUAN_LY NVARCHAR2);
----------------------------------------------------------------------------------
PROCEDURE SELECT_DOI_TUONG_FULL(P_CUR IN OUT MYCUR);
----------------------------------------------------------------------------------
   PROCEDURE SELECT_THUADAT_SD_HS(P_CUR IN OUT MYCUR) ;
----------------------------------------------------------------------------------
 PROCEDURE SELECT_BIEN_DONG_TD(P_CUR IN OUT MYCUR) ;
----------------------------------------------------------------------------------
 PROCEDURE SELECT_DOI_TUONG_ALL(P_CUR IN OUT MYCUR);
  ----------------------------------------------------------------------------------
   PROCEDURE SELECT_QUOC_TICH_ALL(P_CUR IN OUT MYCUR) ;
   -----------------------------------------------------------
    PROCEDURE SELECT_LOAI_DAT_ALL(P_CUR IN OUT MYCUR);
    ---------------------------------------
    PROCEDURE SELECT_BIEN_DONG_ALL(P_CUR IN OUT MYCUR);
    ------
    PROCEDURE SELECT_DC_HO_SO_DAT_1(P_CUR IN OUT MYCUR, P_MA_QUAN_HUYEN NVARCHAR2,P_MA_PHUONG_XA NVARCHAR2,P_MA_DOI_TUONG INT,P_MA_MUC_DICH NVARCHAR2,
P_MA_HINH_THUC NVARCHAR2,P_MA_QUOC_TICH NVARCHAR2,P_TRANG_THAI NVARCHAR2,P_PTTT NVARCHAR2,P_MA_LOAI_DAT NVARCHAR2,P_ID_DONG NUMBER);  

--------------------------------------------
  PROCEDURE SELECT_QUYEN_DUNG(P_CUR  IN OUT MYCUR, P_MA_CAN_BO NUMBER, P_MA_MODULE NVARCHAR2);
------------------------------------------
PROCEDURE SELECT_PHAN_QUYEN_CT(P_CUR  IN OUT MYCUR, P_MA_CAN_BO NUMBER);
------------------------------------------
 PROCEDURE SELECT_PHAN_QUYEN_CT_DETAIL(P_CUR  IN OUT MYCUR, P_MA_CAN_BO NUMBER) ;
------------------------------------------
  PROCEDURE SELECT_PHAN_QUYEN_CT_COUNT(P_CUR  IN OUT MYCUR, P_MA_CAN_BO NUMBER) ;
------------------------------------------
 PROCEDURE UPDATE_PHAN_QUYEN_CB(P_VAL            OUT NVARCHAR2,
                           P_MA_CAN_BO    INT,
                           P_MA_MENU    NVARCHAR2,
                           P_LOAI    NVARCHAR2,
                           P_TRANG_THAI    INT);
------------------------------------------
PROCEDURE SELECT_DC_PHAN_QUYEN(P_CUR IN OUT MYCUR);
------------------------------------------------------------
    PROCEDURE SELECT_DC_PHAN_QUYEN_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_PHAN_QUYEN NVARCHAR2);
---------------------------------------------------------
  PROCEDURE UPDATE_DC_PHAN_QUYEN(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_PHAN_QUYEN    NVARCHAR2,
                           P_TEN_PHAN_QUYEN    NVARCHAR2,
                           P_MA_CAN_BO    INT,
                           P_LOAI     NVARCHAR2);
---------------------------------------------------------------
PROCEDURE DELETE_DC_PHAN_QUYEN(P_VAL   OUT NVARCHAR2, P_MA_PHAN_QUYEN NVARCHAR2);
----------------------------------------------------------------

PROCEDURE SELECT_CB_CAN_BO(P_CUR IN OUT MYCUR);
------------------------------------------------
PROCEDURE SELECT_DC_MUC_DICH_PHAN_QUYEN(P_CUR IN OUT MYCUR, P_MA_CAN_BO INT) ;
-------------------------------------------------------------------
PROCEDURE SELECT_DC_HINH_THUC_PHAN_QUYEN(P_CUR IN OUT MYCUR, P_MA_CAN_BO INT);
----------------------------------------------------------------------------------
PROCEDURE UPDATE_DC_THUADAT_EXCEL(P_VAL            OUT NVARCHAR2,
                           P_LOAI_DAT    number,
                           P_SO_THUA    INT,
                           P_THUADATGOC    NVARCHAR2,
                           P_MA_PHUONG_XA NVARCHAR2,
                           --P_TRANG_THAI_SD INT,
                           P_MUC_DICH_SD NVARCHAR2,
                           P_MA_HINH_THUC NVARCHAR2,
                           P_NAM_CAP_NHAT NVARCHAR2,
                           P_DIEN_TICH FLOAT,
                           --P_LA_DAT_CONG INT,
                           P_TO_BAN_DO NVARCHAR2,
                           P_LA_THUOC_TO_CHUC NVARCHAR2,
                           P_SO_GCN_DAT NVARCHAR2,
                           P_KET_QUA_XD NVARCHAR2,
                           P_MA_LOAI_LUY_TIEN number,
                           P_DK_KE_KHAI INT,
                           P_VI_TRI NVARCHAR2,
                           P_NGUOI_SU_DUNG NVARCHAR2,
                           P_THOI_HAN INT,
                           P_TG_BD NVARCHAR2,
                           P_TG_KT NVARCHAR2,
                           P_MA_CAP_QUAN_LY   INT,
                           P_MA_HUYEN    NVARCHAR2,
                           P_PHUONG_THUC NVARCHAR2,
                           P_MA_QUOC_TICH NVARCHAR2,
                           P_SDT NVARCHAR2, 
                           P_GHI_CHU NVARCHAR2,
                           P_DAU_GIA INT,
                           P_TIEN_DAU_GIA FLOAT,
                           P_LY_DO NVARCHAR2,
                           P_TIEN_THUE NVARCHAR2,
                           P_MA_DOI_TUONG INT,
                           P_DIEN_TICH_SD FLOAT,
                           P_DON_VI_TO_CHUC_DAU_GIA NVARCHAR2
                           );
---------------------------------------------------------------------------  
PROCEDURE SELECT_DC_LOG(P_CUR IN OUT MYCUR) ;
-----------------------------------------------------------------------------
  PROCEDURE UPDATE_LOG(P_VAL            OUT NVARCHAR2,
                           P_MA_CAN_BO    NUMBER,
                           P_THAO_TAC    NVARCHAR2);
-------------------------------------------------------------------------------
 PROCEDURE DELETE_DC_LOG(P_VAL   OUT NVARCHAR2) ;
 -------------------------------------------------------------
    -------------------------------------------------------------------------------
  PROCEDURE DELETE_DC_LOG_ROWS(P_VAL   OUT NVARCHAR2, P_MA_LOG NUMBER);
  ---------------------------------
  PROCEDURE SELECT_PHX_ALL(P_CUR IN OUT MYCUR);
  ------------------------------------------------------------------------------------
PROCEDURE SELECT_QUOC_TICH(P_CUR IN OUT MYCUR);
  -----------------------------------------------------------------------------
    PROCEDURE SELECT_QUOC_TICH_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_QUOC_TICH NVARCHAR2);
  --------------------------------------------------------------------------------
   PROCEDURE UPDATE_QUOC_TICH(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_QUOC_TICH     NVARCHAR2,
                           P_TEN_QUOC_TICH    NVARCHAR2,
                           P_STT_QUOC_TICH    INT,
                           P_TT_QUOC_TICH     INT);
  ---------------------------------------------------------------------------
    PROCEDURE DELETE_QUOC_TICH(P_VAL   OUT NVARCHAR2, P_MA_QUOC_TICH NVARCHAR2);
    -------------------------------------------------
    PROCEDURE SELECT_THUADAT_TO(P_CUR IN OUT MYCUR) ;
end TNMT_DATCONG_DM;
/

prompt
prompt Creating package TNMT_DATCONG_TK
prompt ================================
prompt
create or replace package hai.TNMT_DATCONG_TK is
 TYPE MYCUR IS REF CURSOR;


end TNMT_DATCONG_TK;
/

prompt
prompt Creating package TNMT_DUNGCHUNG
prompt ===============================
prompt
create or replace package hai.TNMT_DUNGCHUNG is
  TYPE MYCUR IS REF CURSOR; 
 -------------------------------------------------------------------------------
  PROCEDURE SELECT_CHUC_VU(P_CUR IN OUT MYCUR);
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_CHUC_VU_DETAIL(P_CUR        IN OUT MYCUR,
                                  P_MA_CHUC_VU NVARCHAR2);
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_CHUC_VU(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_CHUC_VU     NVARCHAR2,
                           P_TEN_CHUC_VU    NVARCHAR2,
                           P_STT_CHUC_VU    INT,
                           P_TT_CHUC_VU     INT);
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_CHUC_VU(P_VAL OUT NVARCHAR2, P_MA_CHUC_VU NVARCHAR2);
 ---------------------------DM_DAN_TOC---------------------------------------
 PROCEDURE SELECT_DAN_TOC(P_CUR IN OUT MYCUR) ;
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_DAN_TOC_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_DAN_TOC NVARCHAR2);
 -------------------------------------------------------------------------------                                  
 PROCEDURE UPDATE_DAN_TOC(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_DAN_TOC     NVARCHAR2,
                           P_TEN_DAN_TOC    NVARCHAR2,
                           P_STT_DAN_TOC    INT,
                           P_TT_DAN_TOC     INT);     
                           
 -------------------------------------------------------------------------------
  PROCEDURE DELETE_DAN_TOC(P_VAL   OUT NVARCHAR2, P_MA_DAN_TOC NVARCHAR2);  
 ---------------------------DM_TON_GIAO---------------------------------------
 PROCEDURE SELECT_TON_GIAO(P_CUR IN OUT MYCUR) ;
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_TON_GIAO_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_TON_GIAO NVARCHAR2);
 -------------------------------------------------------------------------------                                  
 PROCEDURE UPDATE_TON_GIAO(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_TON_GIAO     NVARCHAR2,
                           P_TEN_TON_GIAO    NVARCHAR2,
                           P_STT_TON_GIAO   INT,
                           P_TT_TON_GIAO     INT);     
                           
 -------------------------------------------------------------------------------
 PROCEDURE DELETE_TON_GIAO(P_VAL   OUT NVARCHAR2, P_MA_TON_GIAO NVARCHAR2);                                                      
                                                    
 ---------------------------DM_QUOC_TICH-------------------------------------
 PROCEDURE SELECT_QUOC_TICH(P_CUR IN OUT MYCUR) ;
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_QUOC_TICH_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_QUOC_TICH NVARCHAR2);
 -------------------------------------------------------------------------------                                  
 PROCEDURE UPDATE_QUOC_TICH(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_QUOC_TICH     NVARCHAR2,
                           P_TEN_QUOC_TICH    NVARCHAR2,
                           P_STT_QUOC_TICH   INT,
                           P_TT_QUOC_TICH     INT);     
                           
 -------------------------------------------------------------------------------
 PROCEDURE DELETE_QUOC_TICH(P_VAL   OUT NVARCHAR2, P_MA_QUOC_TICH NVARCHAR2);                                                      
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_LOAI_VAN_BAN(P_CUR IN OUT MYCUR) ;
 -------------------------------------------------------------------------------
 PROCEDURE SELECT_LOAI_VAN_BAN_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_LOAI_VAN_BAN NVARCHAR2);
 -------------------------------------------------------------------------------                                  
 PROCEDURE UPDATE_LOAI_VAN_BAN(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_LOAI_VAN_BAN     NVARCHAR2,
                           P_TEN_LOAI_VAN_BAN    NVARCHAR2,
                           P_STT_LOAI_VAN_BAN   INT,
                           P_TT_LOAI_VAN_BAN     INT);     
                           
-------------------------------------------------------------------------------
  PROCEDURE DELETE_LOAI_VAN_BAN(P_VAL   OUT NVARCHAR2, P_MA_LOAI_VAN_BAN NVARCHAR2);                                                      
   
end TNMT_DUNGCHUNG;
/

prompt
prompt Creating package TNMT_LICH_CONG_TAC
prompt ===================================
prompt
CREATE OR REPLACE PACKAGE HAI.TNMT_LICH_CONG_TAC IS
TYPE MYCUR IS REF CURSOR;
-------------------------------------------------
PROCEDURE UPDATE_LICH_CONG_TAC(P_VAL OUT NVARCHAR2,P_STT INT,P_MA_CAN_BO NVARCHAR2, P_NGAY_CONG_TAC NVARCHAR2,P_NGAY_KET_THUC NVARCHAR2,P_VAN_TAT NVARCHAR2, P_NOI_DUNG NVARCHAR2);
-------------------------------------------------
END TNMT_LICH_CONG_TAC;
/

prompt
prompt Creating package TNMT_QUANLYNHANUOC
prompt ===================================
prompt
CREATE OR REPLACE PACKAGE HAI.TNMT_QUANLYNHANUOC is
  TYPE MYCUR IS REF CURSOR; 
--============== lop tap huan
PROCEDURE SELECT_LOP_TAP_HUANS(P_CUR IN OUT MYCUR, P_MA_CO_QUAN NVARCHAR2); 
--============== lop tap huan
PROCEDURE SELECT_LOP_TAP_HUAN(P_CUR IN OUT MYCUR, P_MA_LOP_TAP_HUAN INT,P_NGAY_MO_LOP NVARCHAR2); 
--============== select lop tap huan
PROCEDURE SELECT_DM_LOP_TAP_HUAN(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2);
--============== update lop tap huan
PROCEDURE UPDATE_LOP_TAP_HUAN(P_VAL OUT NVARCHAR2, P_UPDATE_TYPE NVARCHAR2,P_MA_LOP_TAP_HUAN NVARCHAR2,
                              P_NGAY_MO_LOP NVARCHAR2, P_SO_LUONG NVARCHAR2,P_SO_LUONG_DI_HOC NVARCHAR2,
                              P_GHI_CHU NVARCHAR2, P_TRANG_THAI NVARCHAR2);
--============== delete lop tap huan
PROCEDURE DELETE_LOP_TAP_HUAN(P_VAL OUT NVARCHAR2, P_NGUOI_XOA INT,P_MA_LOP_TAP_HUAN INT, P_NGAY_MO_LOP NVARCHAR2);
END TNMT_QUANLYNHANUOC;
/

prompt
prompt Creating package TNMT_TEST
prompt ==========================
prompt
create or replace package hai.TNMT_TEST is
TYPE MYCUR IS REF CURSOR;
 PROCEDURE SELECT_ALL_QUYET_DINH(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2);
 PROCEDURE SELECT_SINGLE_QUYET_DINH(P_CUR IN OUT MYCUR,P_MA_QUYET_DINH NUMBER);
 PROCEDURE DELETE_QUYET_DINH(  P_VAL            OUT NVARCHAR2,
                               P_MA_QUYET_DINH NUMBER);
PROCEDURE UPDATE_QUYET_DINH(P_VAL          OUT NVARCHAR2,
                           P_UPDATE_TYPE    VARCHAR2,
                           P_MA_QUYET_DINH  INT ,
                           P_TEN_QUYET_DINH NVARCHAR2,
                           P_NOI_DUNG       NVARCHAR2,
                           P_FILE_DINH_KEM  NVARCHAR2,
                           P_NGUOI_CAP_NHAT INT,
                           P_TRANG_THAI     INT,
                           P_MA_CO_QUAN NVARCHAR2
                           );
PROCEDURE SELECT_ALL_KEHOACH_TT(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2);
PROCEDURE SELECT_SINGLE_KEHOACH_TT (P_CUR IN OUT MYCUR, P_MA_KE_HOACH_TT INT);
PROCEDURE DELETE_KEHOACH_TT(  P_VAL            OUT NVARCHAR2,
                               P_MA_KE_HOACH_TT INT);
PROCEDURE UPDATE_KEHOACH_TT(P_VAL          OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_KE_HOACH_TT INT,
                           P_TEN_KE_HOACH_TT NVARCHAR2,
                           P_NGAY_LAP_KE_HOACH       NVARCHAR2,
                           P_FILE_DINH_KEM  NVARCHAR2,
                           P_MA_QUYET_DINH INT,
                           P_TRANG_THAI     INT,
                           P_MA_CO_QUAN NVARCHAR2
                           );
end TNMT_TEST;
/

prompt
prompt Creating package TNMT_TEST1
prompt ===========================
prompt
create or replace package hai.TNMT_TEST1 is
TYPE MYCUR IS REF CURSOR;
-----------------------------------------------
 PROCEDURE SELECT_ALL_QUYET_DINH(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2);
-----------------------------------------------
 PROCEDURE SELECT_SINGLE_QUYET_DINH(P_CUR IN OUT MYCUR,P_MA_QUYET_DINH NUMBER);
----------------------------------------------
 PROCEDURE DELETE_QUYET_DINH(  P_VAL            OUT NVARCHAR2,
                               P_MA_QUYET_DINH NUMBER);
---------------------------------------------------
PROCEDURE UPDATE_QUYET_DINH(P_VAL          OUT NVARCHAR2,
                           P_UPDATE_TYPE    VARCHAR2,
                           P_MA_QUYET_DINH  INT ,
                           P_TEN_QUYET_DINH NVARCHAR2,
                           P_NOI_DUNG       NVARCHAR2,
                           P_FILE_DINH_KEM  NVARCHAR2,
                           P_NGUOI_CAP_NHAT INT,
                           P_TRANG_THAI     INT,
                           P_MA_CO_QUAN NVARCHAR2
                           );
---------------------------------------------------
PROCEDURE SELECT_ALL_KEHOACH_TT(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2);
---------------------------------------------------
PROCEDURE SELECT_SINGLE_KEHOACH_TT (P_CUR IN OUT MYCUR, P_MA_KE_HOACH_TT INT);
---------------------------------------------------
PROCEDURE DELETE_KEHOACH_TT(  P_VAL            OUT NVARCHAR2,
                               P_MA_KE_HOACH_TT INT);
---------------------------------------------------
PROCEDURE UPDATE_KEHOACH_TT(P_VAL          OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_KE_HOACH_TT INT,
                           P_TEN_KE_HOACH_TT NVARCHAR2,
                           P_NGAY_LAP_KE_HOACH       NVARCHAR2,
                           P_FILE_DINH_KEM  NVARCHAR2,
                           P_MA_QUYET_DINH INT,
                           P_TRANG_THAI     INT,
                           P_MA_CO_QUAN NVARCHAR2
                           );
--------------------------------------------------------
end TNMT_TEST1;
create or replace package body TNMT_TEST1 is
------------------SELECT_ALL_QUYET_DINH-----------------------
PROCEDURE SELECT_ALL_QUYET_DINH(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TRANG_THAI = 0 THEN
                'Mở'
               ELSE
                'Ðóng'
             END AS TEN_TRANG_THAI
        FROM TT_QUYET_DINH A
        WHERE A.MA_CO_QUAN=P_MA_CO_QUAN
       ORDER BY A.MA_QUYET_DINH;
  END;
--------------------SELECT_SINGLE_QUYET_DINH-----------------
PROCEDURE SELECT_SINGLE_QUYET_DINH (P_CUR IN OUT MYCUR, P_MA_QUYET_DINH NUMBER)AS
  BEGIN
    OPEN P_CUR FOR
    SELECT A.MA_QUYET_DINH, A.TEN_QUYET_DINH, A.NOI_DUNG, A.FILE_DINH_KEM, A.NGAY_CAP_NHAT,A.TRANG_THAI,
           CASE
             WHEN A.TRANG_THAI = 0 THEN
               'Mở'
               ELSE
                 'Ðóng'
           END AS TEN_TRANG_THAI
           FROM TT_QUYET_DINH A
           WHERE A.MA_QUYET_DINH = P_MA_QUYET_DINH;
  END;
------------------DELETE_QUYET_DINH---------------------
 PROCEDURE DELETE_QUYET_DINH(  P_VAL            OUT NVARCHAR2,
                               P_MA_QUYET_DINH NUMBER) AS
  BEGIN
    P_VAL := 'CO_LOI';
       DELETE FROM TT_QUYET_DINH
       WHERE MA_QUYET_DINH LIKE P_MA_QUYET_DINH;
      P_VAL := 'THANH_CONG';
  END;

-------------------------UPDATE_QUYET_DINH-------------------
PROCEDURE UPDATE_QUYET_DINH(P_VAL          OUT NVARCHAR2,
                           P_UPDATE_TYPE    VARCHAR2,
                           P_MA_QUYET_DINH  INT,
                           P_TEN_QUYET_DINH NVARCHAR2,
                           P_NOI_DUNG       NVARCHAR2,
                           P_FILE_DINH_KEM  NVARCHAR2,
                           P_NGUOI_CAP_NHAT INT,
                           P_TRANG_THAI     INT,
                           P_MA_CO_QUAN NVARCHAR2
                           )  AS
  V_TON_TAI_TEN INT;
  BEGIN
    P_VAL := 'CO_LOI';
    IF P_UPDATE_TYPE = 'THEM_MOI' THEN
      SELECT COUNT(MA_QUYET_DINH) INTO V_TON_TAI_TEN FROM TT_QUYET_DINH
      WHERE UPPER(TEN_QUYET_DINH) = UPPER(P_TEN_QUYET_DINH);
      IF V_TON_TAI_TEN > 0 THEN P_VAL :='TON_TAI_TEN';
       ELSE
        INSERT INTO TT_QUYET_DINH
           (TEN_QUYET_DINH,
           NOI_DUNG,
           FILE_DINH_KEM,
           NGUOI_CAP_NHAT,
           NGAY_CAP_NHAT,
           TRANG_THAI,
           MA_CO_QUAN
          )
        VALUES
          (P_TEN_QUYET_DINH,
           P_NOI_DUNG,
           P_FILE_DINH_KEM,
           P_NGUOI_CAP_NHAT,
           SYSDATE,
           P_TRANG_THAI,
           P_MA_CO_QUAN
          );
        P_VAL := 'THANH_CONG';
     END IF;
     ELSE
      SELECT COUNT(MA_QUYET_DINH)INTO V_TON_TAI_TEN FROM TT_QUYET_DINH
      WHERE UPPER(TEN_QUYET_DINH) = UPPER(P_TEN_QUYET_DINH)
      AND MA_QUYET_DINH <> P_MA_QUYET_DINH;
      IF V_TON_TAI_TEN >0 THEN P_VAL :='TON_TAI_TEN';
      ELSE
        UPDATE TT_QUYET_DINH
           SET TEN_QUYET_DINH = P_TEN_QUYET_DINH,
               NOI_DUNG = P_NOI_DUNG,
               FILE_DINH_KEM = P_FILE_DINH_KEM,
               NGUOI_CAP_NHAT = P_NGUOI_CAP_NHAT,
               NGAY_CAP_NHAT = SYSDATE,
               TRANG_THAI = P_TRANG_THAI,
               MA_CO_QUAN=P_MA_CO_QUAN
         WHERE MA_QUYET_DINH = P_MA_QUYET_DINH;
        P_VAL := 'THANH_CONG';
    END IF;
    END IF;
  END;
--------------------SELECT_ALL_KEHOACH_TT--------------------
PROCEDURE SELECT_ALL_KEHOACH_TT(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TRANG_THAI = 0 THEN
                'Mở'
               ELSE
                'Ðóng'
             END AS TEN_TRANG_THAI
        FROM TT_KE_HOACH_THANH_TRA A WHERE A.MA_CO_QUAN=P_MA_CO_QUAN
       ORDER BY A.MA_KE_HOACH_TT;
  END;
--------------------SELECT_SINGLE_KEHOACH_TT------------------
PROCEDURE SELECT_SINGLE_KEHOACH_TT (P_CUR IN OUT MYCUR, P_MA_KE_HOACH_TT INT)AS
  BEGIN
    OPEN P_CUR FOR
    SELECT A.MA_KE_HOACH_TT, A.TEN_KE_HOACH_TT, A.NGAY_LAP_KE_HOACH, A.FILE_DINH_KEM, A.NGAY_CAP_NHAT, A.TRANG_THAI,
           a.ma_quyet_dinh,CASE
             WHEN A.TRANG_THAI = 0 THEN
               'Mở'
               ELSE
                 'Ðóng'
           END AS TEN_TRANG_THAI
           FROM TT_KE_HOACH_THANH_TRA A
           WHERE A.MA_KE_HOACH_TT = P_MA_KE_HOACH_TT;
  END;
--------------------DELETE_KEHOACH_TT--------------------
 PROCEDURE DELETE_KEHOACH_TT(  P_VAL            OUT NVARCHAR2,
                               P_MA_KE_HOACH_TT INT) AS
  BEGIN
    P_VAL := 'CO_LOI';
       DELETE FROM TT_KE_HOACH_THANH_TRA
       WHERE MA_KE_HOACH_TT LIKE P_MA_KE_HOACH_TT;
      P_VAL := 'THANH_CONG';
  END;
--------------------UPDATE_KEHOACH_TT--------------------
PROCEDURE UPDATE_KEHOACH_TT(P_VAL          OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_KE_HOACH_TT INT,
                           P_TEN_KE_HOACH_TT NVARCHAR2,
                           P_NGAY_LAP_KE_HOACH       NVARCHAR2,
                           P_FILE_DINH_KEM  NVARCHAR2,
                           P_MA_QUYET_DINH INT,
                           P_TRANG_THAI     INT,
                           P_MA_CO_QUAN NVARCHAR2
                           )  AS
  V_TON_TAI_TEN INT;
  BEGIN
    P_VAL := 'CO_LOI';
    IF P_UPDATE_TYPE = 'THEM_MOI' THEN
      SELECT COUNT(MA_KE_HOACH_TT) INTO V_TON_TAI_TEN FROM TT_KE_HOACH_THANH_TRA
      WHERE UPPER(TEN_KE_HOACH_TT) = UPPER(P_TEN_KE_HOACH_TT);
      IF V_TON_TAI_TEN > 0 THEN P_VAL :='TON_TAI_TEN';
       ELSE
        INSERT INTO TT_KE_HOACH_THANH_TRA
           (TEN_KE_HOACH_TT,
           NGAY_LAP_KE_HOACH,
           FILE_DINH_KEM,
           NGAY_CAP_NHAT,
           MA_QUYET_DINH,
           TRANG_THAI,
           MA_CO_QUAN
          )
        VALUES
         ( P_TEN_KE_HOACH_TT,
           P_NGAY_LAP_KE_HOACH,
           P_FILE_DINH_KEM,
           SYSDATE,
           P_MA_QUYET_DINH,
           P_TRANG_THAI,
           P_MA_CO_QUAN
          );
        P_VAL := 'THANH_CONG';
     END IF;
     ELSE
      SELECT COUNT(MA_KE_HOACH_TT)INTO V_TON_TAI_TEN FROM TT_KE_HOACH_THANH_TRA
      WHERE UPPER(TEN_KE_HOACH_TT) = UPPER(P_TEN_KE_HOACH_TT)
      AND MA_KE_HOACH_TT <> MA_KE_HOACH_TT;
      IF V_TON_TAI_TEN >0 THEN P_VAL :='TON_TAI_TEN';
      ELSE
        UPDATE TT_KE_HOACH_THANH_TRA
           SET TEN_KE_HOACH_TT = P_TEN_KE_HOACH_TT,
               NGAY_LAP_KE_HOACH = P_NGAY_LAP_KE_HOACH,
               FILE_DINH_KEM = P_FILE_DINH_KEM,
               NGAY_CAP_NHAT = SYSDATE,
               MA_QUYET_DINH = P_MA_QUYET_DINH,
               TRANG_THAI = P_TRANG_THAI,
               MA_CO_QUAN=P_MA_CO_QUAN
         WHERE MA_KE_HOACH_TT = P_MA_KE_HOACH_TT;
        P_VAL := 'THANH_CONG';
    END IF;
    END IF;
  END;
-------------------------------------------------------------
END TNMT_TEST1;
/

prompt
prompt Creating package TNMT_THANHTRABAOCAO
prompt ====================================
prompt
CREATE OR REPLACE PACKAGE HAI.TNMT_THANHTRABAOCAO is
  TYPE MYCUR IS REF CURSOR; 
  
PROCEDURE BAO_CAO_CHUYEN_NGANH_LIST(P_CUR IN OUT MYCUR,P_TU_NGAY NVARCHAR2,P_DEN_NGAY NVARCHAR2,P_MA_CO_QUAN NVARCHAR2);
--===========//// BAO CAO LINH VUC DANH SACH//=============--
PROCEDURE BAO_CAO_LINH_VUC_LIST(P_CUR IN OUT MYCUR,P_TU_NGAY NVARCHAR2,P_DEN_NGAY NVARCHAR2,P_MA_LINH_VUC NVARCHAR2,P_THAM_NHUNG INT, P_THANH_TRA_LAI INT,P_MA_CO_QUAN NVARCHAR2);
--===========//SELECT BAO CAO CHUYEN NGANH
PROCEDURE BAO_CAO_CHUYEN_NGANH(P_CUR IN OUT MYCUR,P_TU_NGAY NVARCHAR2,P_DEN_NGAY NVARCHAR2,P_MA_CO_QUAN NVARCHAR2);
PROCEDURE BAO_CAO_LINH_VUC(P_CUR IN OUT MYCUR,P_TU_NGAY NVARCHAR2,P_DEN_NGAY NVARCHAR2,P_MA_LINH_VUC NVARCHAR2,P_MA_CO_QUAN NVARCHAR2);
--BAO CAO THANH TRA LAI
PROCEDURE BAO_CAO_THANH_TRA_LAI(P_CUR IN OUT MYCUR,P_TU_NGAY NVARCHAR2,P_DEN_NGAY NVARCHAR2,P_MA_LINH_VUC NVARCHAR2,P_MA_CO_QUAN NVARCHAR2);
PROCEDURE BAO_CAO_THANH_TRA_LAI_LIST(P_CUR IN OUT MYCUR,P_TU_NGAY NVARCHAR2,P_DEN_NGAY NVARCHAR2,P_MA_CO_QUAN NVARCHAR2);
--bao cao tham nhung
PROCEDURE BAO_CAO_THAM_NHUNG(P_CUR IN OUT MYCUR,P_TU_NGAY NVARCHAR2,P_DEN_NGAY NVARCHAR2,P_MA_LINH_VUC NVARCHAR2,P_MA_CO_QUAN NVARCHAR2);
-- bao cao thong ke xu ly don
PROCEDURE THONG_KE_XU_LY_DON(P_CUR IN OUT MYCUR,P_TU_NGAY NVARCHAR2, P_DEN_NGAY NVARCHAR2, P_MA_CO_QUAN NVARCHAR2);
PROCEDURE BAO_CAO_QLNN(P_CUR IN OUT MYCUR,P_TU_NGAY NVARCHAR2,P_DEN_NGAY NVARCHAR2,P_MA_CO_QUAN NVARCHAR2);
END TNMT_THANHTRABAOCAO;
/

prompt
prompt Creating package TNMT_THANHTRA_DT
prompt =================================
prompt
create or replace package hai.TNMT_THANHTRA_DT is



end TNMT_THANHTRA_DT;
/

prompt
prompt Creating package TNMT_THANHTRA_H
prompt ================================
prompt
CREATE OR REPLACE PACKAGE HAI.TNMT_THANHTRA_H is
  TYPE MYCUR IS REF CURSOR; 

--===========//GET DOAN THANH TRA//=============--
PROCEDURE GET_DOAN_THANH_TRAS(P_CUR IN OUT MYCUR, P_MA_CO_QUAN NVARCHAR2);

--===========//GET DOAN THANH TRA//=============--
PROCEDURE GET_DOAN_THANH_TRA(P_CUR IN OUT MYCUR, P_MA_DOAN_TT NVARCHAR2);

--===========//UPDATE DOAN THANH TRA//=============--
PROCEDURE UPDATE_DOAN_THANH_TRA(P_VAL OUT NVARCHAR2,P_UPDATE_TYPE NVARCHAR2,P_MA_DOAN_TT NVARCHAR2,P_TEN_DOAN_TT NVARCHAR2,
                                P_MUC_DICH NVARCHAR2, P_NGAY_THANH_LAP NVARCHAR2,P_NGAY_HET_HAN NVARCHAR2,P_NGAY_GIA_HAN NVARCHAR2,
                                P_MA_CO_QUAN NVARCHAR2,P_TRANG_THAI INT);

--===========//DELETE DOAN THANH TRA//=============--
PROCEDURE DELETE_DOAN_THANH_TRA(P_VAL OUT NVARCHAR2,P_NGUOI_XOA INT,P_MA_DOAN_TT NVARCHAR2);

--===========//SELECT CAN BO THANH TRA//=============-- 
PROCEDURE GET_DS_CAN_BOS(P_CUR IN OUT MYCUR,P_MA_DOAN_TT NVARCHAR2,P_MA_CO_QUAN NVARCHAR2);

--===========//SELECT CAN BO DOAN THANH TRA//=============-- 
PROCEDURE GET_CAN_BO_DOAN_TT(P_CUR IN OUT MYCUR,P_MA_DOAN_TT NVARCHAR2);
--===========//DELETE CAN BO DOAN THANH TRA//=============--
PROCEDURE DELETE_CAN_BO_DOAN_TT(P_MA_DOAN_TT NVARCHAR2);
--===========//INSERT CAN BO DOAN THANH TRA//=============--
PROCEDURE INSERT_CAN_BO_DOAN_TT(P_MA_DOAN_TT NVARCHAR2,P_MA_CAN_BO NVARCHAR2,P_MA_CHUC_DANH NVARCHAR2);
--===========//SELECT KE HOACH THANH TRA//=============--
PROCEDURE SELECT_KE_HOACH_THANH_TRA(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2);
--===========//SELECT DOAN THANH TRA//=============--
PROCEDURE SELECT_DOAN_THANH_TRA(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2);
--===========//SELECT LINH VUC THANH TRA//=============--
PROCEDURE SELECT_LINH_VUC_THANH_TRA(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2);
--===========//UPDATE BIEN BAN THANH TRA//=============--
PROCEDURE UPDATE_BIEN_BAN_THANH_TRA(P_VAL OUT NVARCHAR2,P_UPDATE_TYPE NVARCHAR2,P_SO_THANH_TRA NVARCHAR2,P_MA_KE_HOACH_TT INT, P_MA_DOAN_TT INT,P_LOAI_HINH_THANH_TRA NVARCHAR2,
                                    P_NGAY_BD_THANH_TRA NVARCHAR2,P_NGAY_KT_THANH_TRA NVARCHAR2,P_NOI_DUNG_THANH_TRA NVARCHAR2,P_TEN_TO_CHUC_CA_NHAN NVARCHAR2,P_LOAI_HINH_DN INT, P_DIA_CHI_TO_CHUC_CA_NHAN NVARCHAR2,
                                    P_KET_QUA_THANH_TRA NVARCHAR2,P_HINH_THUC_XU_PHAT INT, P_LY_DO_XU_PHAT NVARCHAR2, P_TAI_SAN_TICH_THU NVARCHAR2,P_SO_TIEN_TICH_THU NVARCHAR2,P_TAI_SAN_TIEU_HUY NVARCHAR2,P_SO_TIEN_TIEU_HUY NVARCHAR2,P_SO_TIEN_XU_PHAT NVARCHAR2,P_MA_CO_QUAN NVARCHAR2,
                                    P_FILE_QUYET_DINH NVARCHAR2, P_NGAY_KY_QUYET_DINH NVARCHAR2, P_FILE_NOI_DUNG_THANH_TRA NVARCHAR2,P_SO_BIEN_BAN_VI_PHAM_HC NVARCHAR2,
                                    P_NGAY_LAP_BIEN_BAN NVARCHAR2, P_FILE_BIEN_BAN_VI_PHAM NVARCHAR2,P_SO_QUYET_DINH_XU_PHAT NVARCHAR2,P_TRANG_THAI_NOP_PHAT NVARCHAR2);
--===========//SELECT BIEN BAN THANH TRA//=============--
PROCEDURE SELECT_BIEN_BAN_THANH_TRAS(P_CUR IN OUT MYCUR);
--===========//SELECT 1 BIEN BAN THANH TRA//=============--
PROCEDURE SELECT_BIEN_BAN_THANH_TRA(P_CUR IN OUT MYCUR,P_SO_THANH_TRA NVARCHAR2);
--===========//delete 1 BIEN BAN THANH TRA//=============--
PROCEDURE DELETE_BIEN_BAN_THANH_TRA(P_VAL OUT NVARCHAR2,P_SO_THANH_TRA NVARCHAR2,P_NGUOI_XOA INT);
--===========//UPDATE BIEN BAN THANH TRA LINH VUC//=============--
PROCEDURE UPDATE_BIEN_BAN_TT_LINH_VUC(P_VAL OUT NVARCHAR2,P_UPDATE_TYPE NVARCHAR2,P_SO_THANH_TRA NVARCHAR2,P_MA_KE_HOACH_TT INT, P_MA_DOAN_TT INT,P_LOAI_HINH_THANH_TRA NVARCHAR2,
                                    P_NGAY_BD_THANH_TRA NVARCHAR2,P_NGAY_KT_THANH_TRA NVARCHAR2,P_NOI_DUNG_THANH_TRA NVARCHAR2,P_LINH_VUC_THANH_TRA NVARCHAR2,P_TEN_TO_CHUC_CA_NHAN NVARCHAR2,P_LOAI_HINH_DN INT, P_DIA_CHI_TO_CHUC_CA_NHAN NVARCHAR2,
                                    P_KET_QUA_THANH_TRA NVARCHAR2,P_KIEN_NGHI_XU_LY INT, P_NOI_DUNG_KIEN_NGHI_XU_LY NVARCHAR2,P_NOI_DUNG_KIEN_NGHI_THU_HOI NVARCHAR2, P_KIEN_NGHI_THU_HOI NVARCHAR2,P_SO_TIEN_THU_HOI FLOAT,
                                    P_NOI_DUNG_KIEN_NGHI_KHAC NVARCHAR2,P_KIEN_NGHI_KHAC NVARCHAR2,P_SO_TIEN_KIEN_NGHI_KHAC NVARCHAR2,P_KET_QUA_XU_LY INT,P_NOI_DUNG_XU_LY NVARCHAR2,
                                    P_DAT_PHAI_THU FLOAT,P_SO_TIEN_PHAI_THU FLOAT, P_DAT_DA_THU FLOAT,
                                    P_SO_TIEN_DA_THU FLOAT,P_SO_NGUOI_LIEN_QUAN INT,P_SO_TIEN_THAM_NHUNG FLOAT, P_TAI_SAN_THAM_NHUNG NVARCHAR2,
                                    P_TS_QUY_DOI_THANH_TIEN FLOAT, P_DAT_THAM_NHUNG FLOAT,P_FILE_QUYET_DINH NVARCHAR2, P_FILE_NOI_DUNG_THANH_TRA NVARCHAR2,P_NGAY_KY_QUYET_DINH NVARCHAR2, P_MA_CO_QUAN NVARCHAR2);
 --===========//SELECT 1 BIEN BAN THANH TRA LINH VUC//=============--
PROCEDURE SELECT_BIEN_BAN_TT_LINH_VUC(P_CUR IN OUT MYCUR,P_SO_THANH_TRA NVARCHAR2);
--===========//SELECT BIEN BAN THANH TRA LINH VUC//=============--
PROCEDURE SELECT_BIEN_BAN_TT_LINH_VUCS(P_CUR IN OUT MYCUR);
--===========//delete 1 BIEN BAN THANH TRA LINH VUC//=============--
PROCEDURE DELETE_BIEN_BAN_TT_LINH_VUC(P_VAL OUT NVARCHAR2,P_SO_THANH_TRA NVARCHAR2,P_NGUOI_XOA INT);
--===========// select dang thanh tra 
PROCEDURE SELECT_DANG_VI_PHAM(P_CUR IN OUT MYCUR, P_MA_LINH_VUC NVARCHAR2,P_SO_THANH_TRA NVARCHAR2,P_MA_CO_QUAN NVARCHAR2);
--=======================
PROCEDURE UPDATE_TT_DANG_VI_PHAM(P_MA_DANG_VI_PHAM INT,P_SO_THANH_TRA NVARCHAR2,P_VI_PHAM NVARCHAR2);
PROCEDURE DELETE_TT_DANG_VI_PHAM(P_SO_THANH_TRA NVARCHAR2);
-----------------------------------------------
PROCEDURE SELECT_LY_DO_TTL(P_CUR IN OUT MYCUR, P_MA_CO_QUAN NVARCHAR2);
-----------------------------------------------
PROCEDURE UPDATE_THANH_TRA_LAI(P_VAL OUT NVARCHAR2,P_UPDATE_TYPE NVARCHAR2, P_SO_THANH_TRA INT, P_NGAY_TTL NVARCHAR2,P_LAN_TTL NVARCHAR2,
                               P_LY_DO_TTL NVARCHAR2,P_KET_QUA_TTL NVARCHAR2,P_KIEN_NGHI_XU_LY NVARCHAR2, P_NOI_DUNG_KIEN_NGHI_XU_LY NVARCHAR2,
                               P_NOI_DUNG_KIEN_NGHI_THU_HOI NVARCHAR2, P_KIEN_NGHI_THU_HOI NVARCHAR2, P_SO_TIEN_THU_HOI NVARCHAR2, P_NOI_DUNG_KIEN_NGHI_KHAC NVARCHAR2,
                               P_KIEN_NGHI_KHAC NVARCHAR2, P_SO_TIEN_KHAC NVARCHAR2, P_KET_QUA_XU_LY NVARCHAR2, P_NOI_DUNG_XU_LY NVARCHAR2,
                               P_NOI_DUNG_VI_PHAM_KINH_TE NVARCHAR2,P_DAT_VI_PHAM NVARCHAR2,P_SO_TIEN_VI_PHAM NVARCHAR2,P_DAT_DA_THU NVARCHAR2,P_SO_TIEN_DA_THU NVARCHAR2
                               ,P_SO_TIEN_THAM_NHUNG FLOAT, P_TAI_SAN_THAM_NHUNG NVARCHAR2, P_TS_QUY_DOI_THANH_TIEN FLOAT,P_DAT_THAM_NHUNG FLOAT);
-----------------------------------------------
PROCEDURE SELECT_THANH_TRA_LAI(P_CUR OUT MYCUR,P_SO_THANH_TRA INT,P_LAN_TTL INT);
END TNMT_THANHTRA_H;
/

prompt
prompt Creating package TNMT_THANHTRA_NAT
prompt ==================================
prompt
create or replace package hai.TNMT_THANHTRA_NAT is
TYPE MYCUR IS REF CURSOR;
-----------------------------------------------
 PROCEDURE SELECT_ALL_QUYET_DINH(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2);
-----------------------------------------------
 PROCEDURE SELECT_SINGLE_QUYET_DINH(P_CUR IN OUT MYCUR,P_MA_QUYET_DINH NUMBER);
----------------------------------------------
 PROCEDURE DELETE_QUYET_DINH(  P_VAL            OUT NVARCHAR2,
                               P_MA_QUYET_DINH NUMBER);
---------------------------------------------------
PROCEDURE UPDATE_QUYET_DINH(P_VAL          OUT NVARCHAR2,
                           P_UPDATE_TYPE    VARCHAR2,
                           P_MA_QUYET_DINH  INT ,
                           P_TEN_QUYET_DINH NVARCHAR2,
                           P_NOI_DUNG       NVARCHAR2,
                           P_FILE_DINH_KEM  NVARCHAR2,
                           P_NGUOI_CAP_NHAT INT,
                           P_TRANG_THAI     INT,
                           P_MA_CO_QUAN NVARCHAR2
                           );
---------------------------------------------------
PROCEDURE SELECT_ALL_KEHOACH_TT(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2);
---------------------------------------------------
PROCEDURE SELECT_SINGLE_KEHOACH_TT (P_CUR IN OUT MYCUR, P_MA_KE_HOACH_TT INT);
---------------------------------------------------
PROCEDURE DELETE_KEHOACH_TT(  P_VAL            OUT NVARCHAR2,
                               P_MA_KE_HOACH_TT INT);
---------------------------------------------------
PROCEDURE UPDATE_KEHOACH_TT(P_VAL          OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_KE_HOACH_TT INT,
                           P_TEN_KE_HOACH_TT NVARCHAR2,
                           P_NGAY_LAP_KE_HOACH       NVARCHAR2,
                           P_FILE_DINH_KEM  NVARCHAR2,
                           P_MA_QUYET_DINH INT,
                           P_TRANG_THAI     INT,
                           P_MA_CO_QUAN NVARCHAR2
                           );
--------------------------------------------------------
end TNMT_THANHTRA_NAT;
/

prompt
prompt Creating package TNMT_THANHTRA_TK
prompt =================================
prompt
create or replace package hai.TNMT_THANHTRA_TK is

end TNMT_THANHTRA_TK;
/

prompt
prompt Creating package body KNTC
prompt ==========================
prompt
CREATE OR REPLACE PACKAGE BODY HAI.KNTC IS
  -------------------------------------------------------------------------------
  PROCEDURE SO_TIEP_DAN( P_CUR IN OUT MYCUR,
                                  P_SO_HO_SO_KNTC NVARCHAR2,
                                  P_MA_LINH_VUC_KNTC NVARCHAR2,
                                  P_MA_LOAI_KNTC NVARCHAR2,
                                  P_KNTC_MA_LOAI_DT NVARCHAR2,
                                  P_NGAY_TIEP_NHAN NVARCHAR2,
                                  P_NOI_DUNG_TIEP_DAN NVARCHAR2,
                                  P_DIA_CHI NVARCHAR2,
                                  P_YEU_CAU_GAP_LD INT
                                  ) AS
  P_NGAY_TIEP_NHAN_UPPER NVARCHAR2(200);
  P_NOI_DUNG_TIEP_DAN_UPPER NVARCHAR2(200);
  BEGIN
     P_NGAY_TIEP_NHAN_UPPER:= UPPER(P_NGAY_TIEP_NHAN);
     P_NOI_DUNG_TIEP_DAN_UPPER:= UPPER(P_NOI_DUNG_TIEP_DAN);
     OPEN P_CUR FOR SELECT A.*,
                           D.TEN_CAN_BO,
                           C.TEN_LINH_VUC_KNTC,
                           DT.TEN_LOAI_DTKNTC,
                           A.KNTC_SO_NHA || ', ' || X.TEN_PHUONG_XA || ', ' || H.TEN_QUAN_HUYEN || ', ' || T.TEN_TINH_THANH AS DIA_CHI,
                           CASE WHEN A.YEU_CAU_GAP_LD =1 THEN 'Có' else 'Không' end AS GAP_LANH_DAO
                    FROM KNTC_HO_SO A,
                         DM_LINH_VUC_KNTC C,
                         CB_CAN_BO D,
                         DM_PHUONG_XA X,
                         DM_QUAN_HUYEN H,
                         DM_TINH_THANH T,
                         DM_LOAI_DTKNTC DT
                    WHERE A.MA_CAN_BO_TIEP_DAN = D.MA_CAN_BO
                    AND A.KNTC_MA_PHUONG_XA=X.MA_PHUONG_XA
                    AND X.MA_QUAN_HUYEN=H.MA_QUAN_HUYEN
                    AND H.MA_TINH_THANH=T.MA_TINH_THANH
                    AND A.KNTC_MA_LOAI_DT=DT.MA_LOAI_DTKNTC
                    AND (P_SO_HO_SO_KNTC IS NULL OR A.SO_HO_SO_KNTC = P_SO_HO_SO_KNTC)
                    AND (P_NGAY_TIEP_NHAN IS NULL OR UPPER(A.NGAY_TIEP_DAN) LIKE P_NGAY_TIEP_NHAN_UPPER)
                    AND A.MA_LINH_VUC_KNTC=C.MA_LINH_VUC_KNTC
                    AND (P_MA_LINH_VUC_KNTC IS NULL OR A.MA_LINH_VUC_KNTC= P_MA_LINH_VUC_KNTC)
                    AND (P_MA_LOAI_KNTC IS NULL OR A.MA_LOAI_KNTC=P_MA_LOAI_KNTC)
                    AND (P_KNTC_MA_LOAI_DT IS NULL OR A.KNTC_MA_LOAI_DT = P_KNTC_MA_LOAI_DT)
                    AND (P_NOI_DUNG_TIEP_DAN IS NULL
                      OR UPPER(A.NOI_DUNG_TIEP_DAN) LIKE P_NOI_DUNG_TIEP_DAN_UPPER
                      OR UPPER(A.KNTC_HO_VA_TEN)    LIKE P_NOI_DUNG_TIEP_DAN_UPPER
                      OR UPPER(A.KNTC_CMND)         LIKE P_NOI_DUNG_TIEP_DAN_UPPER
                      )
                    AND (P_DIA_CHI IS NULL
                         OR UPPER(A.KNTC_SO_NHA || ', ' || X.TEN_PHUONG_XA || ', ' || H.TEN_QUAN_HUYEN || ', ' || T.TEN_TINH_THANH) LIKE UPPER('%'||P_DIA_CHI||'%'))
                    AND (P_YEU_CAU_GAP_LD =-1 OR A.YEU_CAU_GAP_LD = P_YEU_CAU_GAP_LD)
                    ORDER BY A.SO_HO_SO_KNTC DESC, A.NGAY_TIEP_DAN DESC, A.NGAY_NHAP DESC;
  END;
-------------------------------------------------------------------------------
  PROCEDURE SELECT_TIEP_DAN_DETAIL(P_CUR IN OUT MYCUR, P_MA_HO_SO_KNTC INT) AS
  V_MAX_LAN_GIAI_QUYET INT;
  BEGIN
    SELECT MAX(LAN_GIAI_QUYET) INTO V_MAX_LAN_GIAI_QUYET FROM KNTC_GIAI_QUYET A WHERE A.MA_HO_SO_KNTC = P_MA_HO_SO_KNTC;
    IF V_MAX_LAN_GIAI_QUYET IS NULL THEN
       V_MAX_LAN_GIAI_QUYET:=0;
    END IF;
    OPEN P_CUR FOR
     SELECT A.*,
            V_MAX_LAN_GIAI_QUYET AS MAX_LAN_GIAI_QUYET,
            D.TEN_CAN_BO,
            C.TEN_LINH_VUC_KNTC,
            H.MA_QUAN_HUYEN,
            H.MA_TINH_THANH,
            A.KNTC_SO_NHA || ', ' || X.TEN_PHUONG_XA || ', ' || H.TEN_QUAN_HUYEN || ', ' || T.TEN_TINH_THANH AS DIA_CHI,
            CASE WHEN A.YEU_CAU_GAP_LD =1 THEN 'Có' else 'Không' end AS GAP_LANH_DAO
        FROM KNTC_HO_SO A,DM_LINH_VUC_KNTC C,CB_CAN_BO D, DM_PHUONG_XA X, DM_QUAN_HUYEN H, DM_TINH_THANH T
        WHERE A.MA_CAN_BO_TIEP_DAN = D.MA_CAN_BO
        AND A.MA_LINH_VUC_KNTC = C.MA_LINH_VUC_KNTC
        AND A.KNTC_MA_PHUONG_XA=X.MA_PHUONG_XA
        AND X.MA_QUAN_HUYEN=H.MA_QUAN_HUYEN
        AND H.MA_TINH_THANH=T.MA_TINH_THANH
        AND A.MA_HO_SO_KNTC = P_MA_HO_SO_KNTC;
  END;
 -------------------------------------------------------------------------------
 PROCEDURE UPDATE_TIEP_DAN(P_VAL OUT NVARCHAR2,
                          P_MA_HO_SO_KNTC INT,
                          P_MA_NGUON_DON_DEN NVARCHAR2,
                          P_NGAY_TIEP_DAN NVARCHAR2,
                          P_VU_VIEC_MOI INT,
                          P_NOI_DUNG_TIEP_DAN NVARCHAR2,
                          P_YEU_CAU_GAP_LD INT,
                          P_NGAY_YCGLD NVARCHAR2,
                          P_MA_LD_TIEP_DAN INT,
                          P_Y_KIEN_LD NVARCHAR2,
                          P_MA_CAN_BO_TIEP_DAN INT,
                          P_MA_CO_QUAN_TIEP_DAN NVARCHAR2,
                          P_MA_LINH_VUC_KNTC NVARCHAR2,
                          P_MA_LOAI_KNTC NVARCHAR2,
                          P_KNTC_MA_LOAI_DT NVARCHAR2,
                          P_KNTC_CMND NVARCHAR2,
                          P_KNTC_HO_VA_TEN NVARCHAR2,
                          P_KNTC_MA_PHUONG_XA NVARCHAR2,
                          P_KNTC_SO_NHA NVARCHAR2,
                          P_KNTC_TEN_CQTC NVARCHAR2,
                          P_KNTC_DIA_CHI_CQTC NVARCHAR2,
                          P_KNTC_SO_NGUOI_DAI_DIEN INT,
                          P_KNTC_TEN_NHUNG_NGUOI_DD NVARCHAR2,
                          P_MA_HO_SO_KNTC_GOC INT,
                          P_MA_DON_VI_XU_LY_CHINH NVARCHAR2
                        ) AS
 V_KNTC_SO_NGUOI_DAI_DIEN INT;
 V_SO_HO_SO_KNTC INT;
 BEGIN
    P_VAL:='THAT_BAI';
    IF P_KNTC_MA_LOAI_DT = 'TC'  OR P_KNTC_MA_LOAI_DT = 'CN' or P_KNTC_SO_NGUOI_DAI_DIEN IS NULL THEN
       V_KNTC_SO_NGUOI_DAI_DIEN:=1;
    ELSE
       V_KNTC_SO_NGUOI_DAI_DIEN:=P_KNTC_SO_NGUOI_DAI_DIEN;
    END IF;
    IF P_MA_HO_SO_KNTC = 0 THEN
                SELECT MAX(SO_HO_SO_KNTC) INTO V_SO_HO_SO_KNTC FROM KNTC_HO_SO;
                IF V_SO_HO_SO_KNTC IS NULL THEN
                   V_SO_HO_SO_KNTC:=1;
                ELSE
                   V_SO_HO_SO_KNTC:= V_SO_HO_SO_KNTC + 1;
                END IF;
                INSERT INTO KNTC_HO_SO(
                                SO_HO_SO_KNTC,
                                NGAY_NHAP,
                                MA_NGUON_DON_DEN,
                                NGAY_TIEP_DAN,
                                VU_VIEC_MOI,
                                NOI_DUNG_TIEP_DAN,
                                YEU_CAU_GAP_LD,
                                NGAY_YCGLD,
                                MA_LD_TIEP_DAN,
                                Y_KIEN_LD,
                                MA_CAN_BO_TIEP_DAN,
                                MA_CO_QUAN_TIEP_DAN,
                                MA_LINH_VUC_KNTC,
                                MA_LOAI_KNTC,
                                KNTC_MA_LOAI_DT,
                                KNTC_CMND,
                                KNTC_HO_VA_TEN,
                                KNTC_MA_PHUONG_XA,
                                KNTC_SO_NHA,
                                KNTC_TEN_CQTC,
                                KNTC_DIA_CHI_CQTC,
                                KNTC_SO_NGUOI_DAI_DIEN,
                                KNTC_TEN_NHUNG_NGUOI_DD,
                                MA_HO_SO_KNTC_GOC,
                                MA_DON_VI_XU_LY_CHINH
                                )
                         VALUES (
                                V_SO_HO_SO_KNTC,
                                SYSDATE,
                                P_MA_NGUON_DON_DEN,
                                P_NGAY_TIEP_DAN,
                                P_VU_VIEC_MOI,
                                P_NOI_DUNG_TIEP_DAN,
                                P_YEU_CAU_GAP_LD,
                                P_NGAY_YCGLD,
                                CASE WHEN P_MA_LD_TIEP_DAN =0 THEN NULL ELSE P_MA_LD_TIEP_DAN END,
                                P_Y_KIEN_LD,
                                P_MA_CAN_BO_TIEP_DAN,
                                P_MA_CO_QUAN_TIEP_DAN,
                                P_MA_LINH_VUC_KNTC,
                                P_MA_LOAI_KNTC,
                                P_KNTC_MA_LOAI_DT,
                                P_KNTC_CMND,
                                P_KNTC_HO_VA_TEN,
                                P_KNTC_MA_PHUONG_XA,
                                P_KNTC_SO_NHA,
                                P_KNTC_TEN_CQTC,
                                P_KNTC_DIA_CHI_CQTC,
                                V_KNTC_SO_NGUOI_DAI_DIEN,
                                P_KNTC_TEN_NHUNG_NGUOI_DD,
                                P_MA_HO_SO_KNTC_GOC,
                                P_MA_DON_VI_XU_LY_CHINH
                                );
    ELSE
                 UPDATE KNTC_HO_SO A SET A.MA_NGUON_DON_DEN=P_MA_NGUON_DON_DEN,
                                         A.NGAY_TIEP_DAN=P_NGAY_TIEP_DAN,
                                         A.VU_VIEC_MOI=P_VU_VIEC_MOI,
                                         A.NOI_DUNG_TIEP_DAN=P_NOI_DUNG_TIEP_DAN,
                                         A.YEU_CAU_GAP_LD=P_YEU_CAU_GAP_LD,
                                         A.NGAY_YCGLD=P_NGAY_YCGLD,
                                         A.MA_LD_TIEP_DAN= CASE WHEN P_MA_LD_TIEP_DAN =0 THEN NULL ELSE P_MA_LD_TIEP_DAN END,
                                         A.Y_KIEN_LD=P_Y_KIEN_LD,
                                         A.MA_LINH_VUC_KNTC=P_MA_LINH_VUC_KNTC,
                                         A.MA_LOAI_KNTC=P_MA_LOAI_KNTC,
                                         A.KNTC_MA_LOAI_DT=P_KNTC_MA_LOAI_DT,
                                         A.KNTC_CMND=P_KNTC_CMND,
                                         A.KNTC_HO_VA_TEN=P_KNTC_HO_VA_TEN,
                                         A.KNTC_MA_PHUONG_XA=P_KNTC_MA_PHUONG_XA,
                                         A.KNTC_SO_NHA=P_KNTC_SO_NHA,
                                         A.KNTC_TEN_CQTC=P_KNTC_TEN_CQTC,
                                         A.KNTC_DIA_CHI_CQTC=P_KNTC_DIA_CHI_CQTC,
                                         A.KNTC_SO_NGUOI_DAI_DIEN=V_KNTC_SO_NGUOI_DAI_DIEN,
                                         A.KNTC_TEN_NHUNG_NGUOI_DD=P_KNTC_TEN_NHUNG_NGUOI_DD,
                                         A.MA_HO_SO_KNTC_GOC=P_MA_HO_SO_KNTC_GOC,
                                         A.MA_DON_VI_XU_LY_CHINH=P_MA_DON_VI_XU_LY_CHINH
              WHERE A.MA_HO_SO_KNTC=P_MA_HO_SO_KNTC;
    END IF;
    P_VAL:='THANH_CONG';
  END;
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_NGUOI_BI_KNTC(P_VAL OUT NVARCHAR2,
                          P_MA_HO_SO_KNTC INT,
                          P_BKNTC_MA_LOAI_DT NVARCHAR2,
                          P_BKNTC_HO_VA_TEN NVARCHAR2,
                          P_BKNTC_DIA_CHI NVARCHAR2,
                          P_BKNTC_TEN_CQTC NVARCHAR2,
                          P_BKNTC_DIA_CHI_CQTC NVARCHAR2
                        ) AS
 BEGIN
    P_VAL:='THAT_BAI';
            UPDATE KNTC_HO_SO A SET A.BKNTC_MA_LOAI_DT=P_BKNTC_MA_LOAI_DT,
                                         A.BKNTC_HO_VA_TEN=P_BKNTC_HO_VA_TEN,
                                         A.BKNTC_DIA_CHI=P_BKNTC_DIA_CHI,
                                         A.BKNTC_TEN_CQTC=P_BKNTC_TEN_CQTC,
                                         A.BKNTC_DIA_CHI_CQTC=P_BKNTC_DIA_CHI_CQTC
              WHERE A.MA_HO_SO_KNTC=P_MA_HO_SO_KNTC;
    P_VAL:='THANH_CONG';
  END;


    -------------------------------------------------------------------------------
  PROCEDURE UPDATE_GIAI_QUYET(P_VAL OUT NVARCHAR2,
                          P_MA_HO_SO_KNTC INT,
                          P_MA_GIAI_QUYET INT,
                          P_MA_CAN_BO INT,
                          P_NGAY_GIAI_QUYET NVARCHAR2,
                          P_LAN_GIAI_QUYET INT,
                          P_MA_HUONG_GIAI_QUYET NVARCHAR2,
                          P_NOI_DUNG_GIAI_QUYET NVARCHAR2,
                          P_TIEN_DO_XU_LY NVARCHAR2,
                          P_SO_KY_HIEU NVARCHAR2,
                          P_TRICH_YEU NVARCHAR2,
                          P_CO_QUAN_BAN_HANH NVARCHAR2,
                          P_SO_BUT_LUC NVARCHAR2,
                          P_SO_TRANG NVARCHAR2,
                          P_NGAY_TRINH_LANH_DAO_KY NVARCHAR2,
                          P_NGAY_LANH_DAO_KY NVARCHAR2,
                          P_NGAY_CHUYEN_VAN_BAN NVARCHAR2,
                          P_MA_LANH_DAO_KY INT,
                          P_FILE_VAN_BAN NVARCHAR2,
                          P_DIEU_KIEN_XU_LY INT,
                          P_THAM_QUYEN_GIAI_QUYET INT
                        ) AS
 BEGIN
    P_VAL:='THAT_BAI';
    IF P_MA_GIAI_QUYET = 0 THEN
       INSERT INTO KNTC_GIAI_QUYET (
                                    MA_HO_SO_KNTC,
                                    MA_CAN_BO,
                                    NGAY_GIAI_QUYET,
                                    MA_HUONG_GIAI_QUYET,
                                    NOI_DUNG_GIAI_QUYET,
                                    TIEN_DO_XU_LY,
                                    SO_KY_HIEU,
                                    TRICH_YEU,
                                    CO_QUAN_BAN_HANH,
                                    SO_BUT_LUC,
                                    SO_TRANG,
                                    LAN_GIAI_QUYET,
                                    NGAY_TRINH_LANH_DAO_KY,
                                    NGAY_LANH_DAO_KY,
                                    NGAY_CHUYEN_VAN_BAN,
                                    MA_LANH_DAO_KY,
                                    FILE_VAN_BAN,
                                    DIEU_KIEN_XU_LY,
                                    THAM_QUYEN_GIAI_QUYET
                                    )
                              VALUES(
                                    P_MA_HO_SO_KNTC,
                                    P_MA_CAN_BO,
                                    P_NGAY_GIAI_QUYET,
                                    P_MA_HUONG_GIAI_QUYET,
                                    P_NOI_DUNG_GIAI_QUYET,
                                    P_TIEN_DO_XU_LY,
                                    P_SO_KY_HIEU,
                                    P_TRICH_YEU,
                                    P_CO_QUAN_BAN_HANH,
                                    P_SO_BUT_LUC,
                                    P_SO_TRANG,
                                    P_LAN_GIAI_QUYET,
                                    P_NGAY_TRINH_LANH_DAO_KY,
                                    P_NGAY_LANH_DAO_KY,
                                    P_NGAY_CHUYEN_VAN_BAN,
                                    P_MA_LANH_DAO_KY,
                                    P_FILE_VAN_BAN,
                                    P_DIEU_KIEN_XU_LY,
                                    P_THAM_QUYEN_GIAI_QUYET
                                    );
    ELSE
       UPDATE KNTC_GIAI_QUYET A SET A.NGAY_GIAI_QUYET     = P_NGAY_GIAI_QUYET,
                                    A.MA_HUONG_GIAI_QUYET = P_MA_HUONG_GIAI_QUYET,
                                    A.NOI_DUNG_GIAI_QUYET = P_NOI_DUNG_GIAI_QUYET,
                                    A.TIEN_DO_XU_LY       = P_TIEN_DO_XU_LY,
                                    A.SO_KY_HIEU          = P_SO_KY_HIEU,
                                    A.TRICH_YEU           = P_TRICH_YEU,
                                    A.CO_QUAN_BAN_HANH    = P_CO_QUAN_BAN_HANH,
                                    A.SO_BUT_LUC          = P_SO_BUT_LUC,
                                    A.SO_TRANG            = P_SO_TRANG,
                                    A.LAN_GIAI_QUYET      = P_LAN_GIAI_QUYET,
                                    A.NGAY_TRINH_LANH_DAO_KY= P_NGAY_TRINH_LANH_DAO_KY,
                                    A.NGAY_LANH_DAO_KY      = P_NGAY_LANH_DAO_KY,
                                    A.NGAY_CHUYEN_VAN_BAN   = P_NGAY_CHUYEN_VAN_BAN,
                                    A.MA_LANH_DAO_KY        = P_MA_LANH_DAO_KY,
                                    A.FILE_VAN_BAN          = P_FILE_VAN_BAN,
                                    A.DIEU_KIEN_XU_LY       = P_DIEU_KIEN_XU_LY,
                                    A.THAM_QUYEN_GIAI_QUYET = P_THAM_QUYEN_GIAI_QUYET
                              WHERE A.MA_GIAI_QUYET=P_MA_GIAI_QUYET;
    END IF;
    P_VAL:='THANH_CONG';
  END;
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_GIAI_QUYET(P_VAL OUT NVARCHAR2, P_MA_GIAI_QUYET INT) AS
  BEGIN
    P_VAL:='THAT_BAI';
    DELETE KNTC_GIAI_QUYET A WHERE A.MA_GIAI_QUYET = P_MA_GIAI_QUYET;
    P_VAL:='THANH_CONG';
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_GIAI_QUYET(P_CUR IN OUT MYCUR, P_MA_HO_SO_KNTC INT) AS
  V_MAX_LAN_GIAI_QUYET INT;
  BEGIN
    SELECT MAX(LAN_GIAI_QUYET) INTO V_MAX_LAN_GIAI_QUYET FROM KNTC_GIAI_QUYET A WHERE A.MA_HO_SO_KNTC = P_MA_HO_SO_KNTC;
    IF V_MAX_LAN_GIAI_QUYET IS NULL THEN
       V_MAX_LAN_GIAI_QUYET:=0;
    END IF;
    OPEN P_CUR FOR
     SELECT A.*,
            B.TEN_HUONG_GIAI_QUYET,
            V_MAX_LAN_GIAI_QUYET AS MAX_LAN_GIAI_QUYET
        FROM KNTC_GIAI_QUYET A, DM_HUONG_GIAI_QUYET B
        WHERE A.MA_HO_SO_KNTC = P_MA_HO_SO_KNTC
          AND A.MA_HUONG_GIAI_QUYET = B.MA_HUONG_GIAI_QUYET
          ORDER BY A.LAN_GIAI_QUYET;
  END;

 PROCEDURE UPDATE_FILE_GIAI_QUYET(P_VAL OUT NVARCHAR2, P_MA_GIAI_QUYET NVARCHAR2, P_FILE_VAN_BAN NVARCHAR2) AS
   BEGIN
      UPDATE KNTC_GIAI_QUYET A SET A.FILE_VAN_BAN          = P_FILE_VAN_BAN
                              WHERE A.MA_GIAI_QUYET=P_MA_GIAI_QUYET;
      P_VAL:='TC';
   END;
/*  -----------------------------------------------------------------------------
  PROCEDURE UPDATE_TIEP_DAN_CO_DON(P_VAL OUT NVARCHAR2,
                          P_MA_HO_SO_KNTC INT,
                          P_MA_NGUON_DON_DEN NVARCHAR2,
                          P_NGAY_TIEP_DAN NVARCHAR2,
                          P_VU_VIEC_MOI INT,
                          P_NOI_DUNG_TIEP_DAN NVARCHAR2,
                          P_YEU_CAU_GAP_LD INT,
                          P_MA_LD_TIEP_DAN INT,
                          P_Y_KIEN_LD NVARCHAR2,
                          P_MA_CAN_BO_TIEP_DAN INT,
                          P_MA_CO_QUAN_TIEP_DAN NVARCHAR2,
                          P_MA_LINH_VUC_KNTC NVARCHAR2,
                          P_MA_LOAI_KNTC NVARCHAR2,
                          P_KNTC_MA_LOAI_DT NVARCHAR2,
                          P_KNTC_CMND NVARCHAR2,
                          P_KNTC_HO_VA_TEN NVARCHAR2,
                          P_KNTC_MA_PHUONG_XA NVARCHAR2,
                          P_KNTC_SO_NHA NVARCHAR2,
                          P_KNTC_TEN_CQTC NVARCHAR2,
                          P_KNTC_DIA_CHI_CQTC NVARCHAR2,
                          P_KNTC_SO_NGUOI_DAI_DIEN INT,
                          P_KNTC_TEN_NHUNG_NGUOI_DD NVARCHAR2,
                          P_MA_HO_SO_KNTC_GOC INT,
                          P_MA_DON_VI_XU_LY_CHINH NVARCHAR2,
                          P_MA_TRANG_THAI_GIAI_QUYET  NVARCHAR2
                        ) AS
 V_KNTC_SO_NGUOI_DAI_DIEN INT;
 V_SO_HO_SO_KNTC INT;
 BEGIN
    P_VAL:='THAT_BAI';
    IF P_KNTC_MA_LOAI_DT = 'TC'  OR P_KNTC_MA_LOAI_DT = 'CN' or P_KNTC_SO_NGUOI_DAI_DIEN IS NULL THEN
       V_KNTC_SO_NGUOI_DAI_DIEN:=1;
    ELSE
       V_KNTC_SO_NGUOI_DAI_DIEN:=P_KNTC_SO_NGUOI_DAI_DIEN;
    END IF;
    IF P_MA_HO_SO_KNTC = 0 THEN
                SELECT MAX(SO_HO_SO_KNTC) INTO V_SO_HO_SO_KNTC FROM KNTC_HO_SO;
                IF V_SO_HO_SO_KNTC IS NULL THEN
                   V_SO_HO_SO_KNTC:=1;
                END IF;
                INSERT INTO KNTC_HO_SO(
                                SO_HO_SO_KNTC,
                                NGAY_NHAP,
                                MA_NGUON_DON_DEN,
                                NGAY_TIEP_DAN,
                                VU_VIEC_MOI,
                                NOI_DUNG_TIEP_DAN,
                                YEU_CAU_GAP_LD,
                                MA_LD_TIEP_DAN,
                                Y_KIEN_LD,
                                MA_CAN_BO_TIEP_DAN,
                                MA_CO_QUAN_TIEP_DAN,
                                MA_LINH_VUC_KNTC,
                                MA_LOAI_KNTC,
                                KNTC_MA_LOAI_DT,
                                KNTC_CMND,
                                KNTC_HO_VA_TEN,
                                KNTC_MA_PHUONG_XA,
                                KNTC_SO_NHA,
                                KNTC_TEN_CQTC,
                                KNTC_DIA_CHI_CQTC,
                                KNTC_SO_NGUOI_DAI_DIEN,
                                KNTC_TEN_NHUNG_NGUOI_DD,
                                MA_HO_SO_KNTC_GOC,
                                MA_DON_VI_XU_LY_CHINH,
                                MA_TRANG_THAI_GIAI_QUYET
                                )
                         VALUES (
                                V_SO_HO_SO_KNTC,
                                SYSDATE,
                                P_MA_NGUON_DON_DEN,
                                P_NGAY_TIEP_DAN,
                                P_VU_VIEC_MOI,
                                P_NOI_DUNG_TIEP_DAN,
                                P_YEU_CAU_GAP_LD,
                                CASE WHEN P_MA_LD_TIEP_DAN =0 THEN NULL ELSE P_MA_LD_TIEP_DAN END,
                                P_Y_KIEN_LD,
                                P_MA_CAN_BO_TIEP_DAN,
                                P_MA_CO_QUAN_TIEP_DAN,
                                P_MA_LINH_VUC_KNTC,
                                P_MA_LOAI_KNTC,
                                P_KNTC_MA_LOAI_DT,
                                P_KNTC_CMND,
                                P_KNTC_HO_VA_TEN,
                                P_KNTC_MA_PHUONG_XA,
                                P_KNTC_SO_NHA,
                                P_KNTC_TEN_CQTC,
                                P_KNTC_DIA_CHI_CQTC,
                                V_KNTC_SO_NGUOI_DAI_DIEN,
                                P_KNTC_TEN_NHUNG_NGUOI_DD,
                                P_MA_HO_SO_KNTC_GOC,
                                P_MA_DON_VI_XU_LY_CHINH,
                                P_MA_TRANG_THAI_GIAI_QUYET
                                );
    ELSE
            UPDATE KNTC_HO_SO A SET A.MA_NGUON_DON_DEN=P_MA_NGUON_DON_DEN,
                                         A.NGAY_TIEP_DAN=P_NGAY_TIEP_DAN,
                                         A.VU_VIEC_MOI=P_VU_VIEC_MOI,
                                         A.NOI_DUNG_TIEP_DAN=P_NOI_DUNG_TIEP_DAN,
                                         A.YEU_CAU_GAP_LD=P_YEU_CAU_GAP_LD,
                                         A.MA_LD_TIEP_DAN= CASE WHEN P_MA_LD_TIEP_DAN =0 THEN NULL ELSE P_MA_LD_TIEP_DAN END,
                                         A.Y_KIEN_LD=P_Y_KIEN_LD,
                                         A.MA_LINH_VUC_KNTC=P_MA_LINH_VUC_KNTC,
                                         A.MA_LOAI_KNTC=P_MA_LOAI_KNTC,
                                         A.KNTC_MA_LOAI_DT=P_KNTC_MA_LOAI_DT,
                                         A.KNTC_CMND=P_KNTC_CMND,
                                         A.KNTC_HO_VA_TEN=P_KNTC_HO_VA_TEN,
                                         A.KNTC_MA_PHUONG_XA=P_KNTC_MA_PHUONG_XA,
                                         A.KNTC_SO_NHA=P_KNTC_SO_NHA,
                                         A.KNTC_TEN_CQTC=P_KNTC_TEN_CQTC,
                                         A.KNTC_DIA_CHI_CQTC = P_KNTC_DIA_CHI_CQTC,
                                         A.KNTC_SO_NGUOI_DAI_DIEN=V_KNTC_SO_NGUOI_DAI_DIEN,
                                         A.KNTC_TEN_NHUNG_NGUOI_DD=P_KNTC_TEN_NHUNG_NGUOI_DD,
                                         A.MA_HO_SO_KNTC_GOC=P_MA_HO_SO_KNTC_GOC,
                                         A.MA_DON_VI_XU_LY_CHINH=P_MA_DON_VI_XU_LY_CHINH,
                                         A.MA_TRANG_THAI_GIAI_QUYET=P_MA_TRANG_THAI_GIAI_QUYET
              WHERE A.MA_HO_SO_KNTC=P_MA_HO_SO_KNTC;
    END IF;
    P_VAL:='THANH_CONG';
  END;*/
-------------------------------------------------------------------------------
  PROCEDURE M2A(P_CUR IN OUT MYCUR, P_TU_NGAY NVARCHAR2, P_DEN_NGAY NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR SELECT
    -- tất cả
     --TAT_CA.MA_DON_VI_XU_LY_CHINH AS MA_DON_VI,
     TAT_CA.TEN_DON_VI,
     TAT_CA.TC_SO_LUOT,
     TAT_CA.TC_SO_NGUOI,
     TAT_CA.TC_MOI_PHAT_SINH,
     TAT_CA.TC_VU_VIEC_CU,
     -- tiếp thường xuyên cá nhân
     TXTCCN.TXTCCN_SO_LUOT,
     TXTCCN.TXTCCN_SO_NGUOI,
     TXTCCN.TXTCCN_MOI_PHAT_SINH,
     TXTCCN.TXTCCN_VU_VIEC_CU,
     -- tiếp thường xuyên tập thể, tổ chức
     TXTT.TXTT_SO_LUOT,
     TXTT.TXTT_SO_NGUOI,
     TXTT.TXTT_MOI_PHAT_SINH,
     TXTT.TXTT_VU_VIEC_CU,
     -- tiếp đột xuất lãnh đạo cá nhân
     LDTCCN.LDTCCN_SO_LUOT,
     LDTCCN.LDTCCN_SO_NGUOI,
     LDTCCN.LDTCCN_MOI_PHAT_SINH,
     LDTCCN.LDTCCN_VU_VIEC_CU,
     -- tiếp đột xuất lãnh đạo tập thể, tổ chức
     LDTT.LDTT_SO_LUOT,
     LDTT.LDTT_SO_NGUOI,
     LDTT.LDTT_MOI_PHAT_SINH,
     LDTT.LDTT_VU_VIEC_CU,
     -- các lĩnh vực khiếu nại
     KN_TCDNGT.KN_TCDNGT,
     KN_CS.KN_CS,
     KN_TS.KN_TS,
     KN_CDCC.KN_CDCC,
     KN_TP.KN_TP,
     KN_CTVHXH.KN_CTVHXH,
     -- các lĩnh vực tố cáo
     TC_HC.TC_HC,
     TC_TP.TC_TP,
     TC_TN.TC_TN,
     -- phản ánh kiến nghị khác
     PA_KN_K.PA_KN_K,
     -- kết quả giải quyết
     CGQ.CGQ,
     CCQD.CCQD,
     DCQD.DCQD,
     DCBA.DCBA
     FROM
       (SELECT A.MA_DON_VI_XU_LY_CHINH , B.TEN_DON_VI,
                    COUNT(A.MA_HO_SO_KNTC)                      AS TC_SO_LUOT,
                    SUM(A.KNTC_SO_NGUOI_DAI_DIEN)               AS TC_SO_NGUOI,
                    SUM(A.VU_VIEC_MOI)                          AS TC_MOI_PHAT_SINH,
                    COUNT(A.MA_HO_SO_KNTC) - SUM(A.VU_VIEC_MOI) AS TC_VU_VIEC_CU
                FROM KNTC_HO_SO A, CB_DON_VI B
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_DON_VI_XU_LY_CHINH=B.MA_DON_VI
                GROUP BY A.MA_DON_VI_XU_LY_CHINH, B.TEN_DON_VI
        ) TAT_CA,-- tồng cộng tất cả của đơn vị

       (SELECT A.MA_DON_VI_XU_LY_CHINH,
                    COUNT(A.MA_HO_SO_KNTC)                      AS TXTCCN_SO_LUOT,
                    SUM(A.KNTC_SO_NGUOI_DAI_DIEN)               AS TXTCCN_SO_NGUOI,
                    SUM(A.VU_VIEC_MOI)                          AS TXTCCN_MOI_PHAT_SINH,
                    COUNT(A.MA_HO_SO_KNTC) - SUM(A.VU_VIEC_MOI) AS TXTCCN_VU_VIEC_CU
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                --AND A.KNTC_MA_LOAI_DT <> 'TT'
                AND A.MA_LD_TIEP_DAN IS NULL
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) TXTCCN,-- thường xuyên tiếp cá nhân

        (SELECT A.MA_DON_VI_XU_LY_CHINH,
                    COUNT(A.MA_HO_SO_KNTC)                      AS TXTT_SO_LUOT,
                    SUM(A.KNTC_SO_NGUOI_DAI_DIEN)               AS TXTT_SO_NGUOI,
                    SUM(A.VU_VIEC_MOI)                          AS TXTT_MOI_PHAT_SINH,
                    COUNT(A.MA_HO_SO_KNTC) - SUM(A.VU_VIEC_MOI) AS TXTT_VU_VIEC_CU
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.KNTC_MA_LOAI_DT = 'TT'
                AND A.MA_LD_TIEP_DAN IS NULL
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) TXTT,-- thường xuyên tiếp tập thể

        (SELECT A.MA_DON_VI_XU_LY_CHINH,
                    COUNT(A.MA_HO_SO_KNTC)                      AS LDTCCN_SO_LUOT,
                    SUM(A.KNTC_SO_NGUOI_DAI_DIEN)               AS LDTCCN_SO_NGUOI,
                    SUM(A.VU_VIEC_MOI)                          AS LDTCCN_MOI_PHAT_SINH,
                    COUNT(A.MA_HO_SO_KNTC) - SUM(A.VU_VIEC_MOI) AS LDTCCN_VU_VIEC_CU
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.KNTC_MA_LOAI_DT <> 'TT'
                AND A.MA_LD_TIEP_DAN IS NOT NULL
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
         ) LDTCCN,-- lãnh đạo  tiếp cá nhân

        (SELECT A.MA_DON_VI_XU_LY_CHINH,
                    COUNT(A.MA_HO_SO_KNTC)                      AS LDTT_SO_LUOT,
                    SUM(A.KNTC_SO_NGUOI_DAI_DIEN)               AS LDTT_SO_NGUOI,
                    SUM(A.VU_VIEC_MOI)                          AS LDTT_MOI_PHAT_SINH,
                    COUNT(A.MA_HO_SO_KNTC) - SUM(A.VU_VIEC_MOI) AS LDTT_VU_VIEC_CU
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.KNTC_MA_LOAI_DT = 'TT'
                AND A.MA_LD_TIEP_DAN IS NOT NULL
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) LDTT,-- lãnh đạo tiếp tập thể

        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS KN_TCDNGT
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'TC'
                AND A.MA_LOAI_KNTC = 'KN'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) KN_TCDNGT,-- HIẾU NẠI-- Về tranh chấp, đòi đất cũ, đền bù, giải tỏa

        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS KN_CS
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'CS'
                AND A.MA_LOAI_KNTC = 'KN'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) KN_CS,-- KHIẾU NẠI-- Về chính sách

        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS KN_TS
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'TS'
                AND A.MA_LOAI_KNTC = 'KN'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) KN_TS,-- KHIẾU NẠI-- Về tài sản

        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS KN_CDCC
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'TC'
                AND A.MA_LOAI_KNTC = 'KN'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) KN_CDCC,-- KHIẾU NẠI-- Về chế dộ công chức viên chức

        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS KN_TP
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'TP'
                AND A.MA_LOAI_KNTC = 'KN'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) KN_TP,-- KHIẾU NẠI-- về tư pháp

        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS KN_CTVHXH
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'CTVHXH'
                AND A.MA_LOAI_KNTC = 'KN'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) KN_CTVHXH,-- KHIẾU NẠI-- về chính trị văn hóa xã hội khác

        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS TC_HC
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'HC'
                AND A.MA_LOAI_KNTC = 'TC'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) TC_HC,-- TỐ CÁO-- Về hành chính

        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS TC_TP
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'TP'
                AND A.MA_LOAI_KNTC = 'TC'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) TC_TP,-- TỐ CÁO-- Về tư pháp

        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS TC_TN
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'TN'
                AND A.MA_LOAI_KNTC = 'TC'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) TC_TN,-- TỐ CÁO-- về tham nhũng

        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS PA_KN_K
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                  AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                  AND A.MA_NGUON_DON_DEN IS NULL
                  AND A.MA_LOAI_KNTC = 'K'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) PA_KN_K,-- Phản ánh kiến nghị khác

        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS CGQ
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_TRANG_THAI_GIAI_QUYET = 'CGQ'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) CGQ,-- chua giai quyet

        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS CCQD
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                  AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                  AND A.MA_NGUON_DON_DEN IS NULL
                  AND A.MA_TRANG_THAI_GIAI_QUYET = 'CCQD'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) CCQD,-- chua co quyet dinh
        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS DCQD
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                  AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                  AND A.MA_NGUON_DON_DEN IS NULL
                  AND A.MA_TRANG_THAI_GIAI_QUYET = 'DCQD'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) DCQD,-- da co quyet dinh

        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS DCBA
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                  AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                  AND A.MA_NGUON_DON_DEN IS NULL
                  AND A.MA_TRANG_THAI_GIAI_QUYET = 'DCBA'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) DCBA-- da co ban an


        WHERE TAT_CA.MA_DON_VI_XU_LY_CHINH = TXTCCN.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = TXTT.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = LDTT.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = LDTCCN.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = KN_TCDNGT.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = KN_CS.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = KN_TS.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = KN_CDCC.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = KN_TP.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = KN_CTVHXH.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = TC_HC.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = TC_TP.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = TC_TN.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = PA_KN_K.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = CGQ.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = CCQD.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = DCQD.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = DCBA.MA_DON_VI_XU_LY_CHINH(+)
          ;
  END;
  -----------------------------------------------------------------------------
  PROCEDURE M2B(P_CUR IN OUT MYCUR, P_TU_NGAY NVARCHAR2, P_DEN_NGAY NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR SELECT
     TAT_CA.MA_DON_VI_XU_LY_CHINH AS MA_DON_VI,
     TAT_CA.TC_SO_DON,
     TNTK.TNTK_NHIEU_NGUOI,
     TAT_CA.TC_SO_DON - TNTK.TNTK_NHIEU_NGUOI AS TNTK_MOT_NGUOI
     FROM
       (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS TC_SO_DON
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NOT NULL
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) TAT_CA,

       (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS TNTK_NHIEU_NGUOI
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NOT NULL
                AND A.KNTC_SO_NGUOI_DAI_DIEN > 0
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) TNTK -- tiếp nhận trong kỳ

        WHERE TAT_CA.MA_DON_VI_XU_LY_CHINH = TNTK.MA_DON_VI_XU_LY_CHINH(+)
          ;
  END;
END KNTC;
/

prompt
prompt Creating package body KNTC_BK
prompt =============================
prompt
CREATE OR REPLACE PACKAGE BODY HAI.KNTC_BK IS
  -------------------------------------------------------------------------------
  PROCEDURE SO_TIEP_DAN( P_CUR IN OUT MYCUR,
                                  P_SO_HO_SO_KNTC NVARCHAR2,
                                  P_MA_LINH_VUC_KNTC NVARCHAR2,
                                  P_MA_LOAI_KNTC NVARCHAR2,
                                  P_KNTC_MA_LOAI_DT NVARCHAR2,
                                  P_NGAY_TIEP_NHAN NVARCHAR2,
                                  P_NOI_DUNG_TIEP_DAN NVARCHAR2,
                                  P_DIA_CHI NVARCHAR2,
                                  P_YEU_CAU_GAP_LD INT  
                                  ) AS
  P_NGAY_TIEP_NHAN_UPPER NVARCHAR2(200);
  P_NOI_DUNG_TIEP_DAN_UPPER NVARCHAR2(200);
  BEGIN 
     P_NGAY_TIEP_NHAN_UPPER:= UPPER(P_NGAY_TIEP_NHAN);
     P_NOI_DUNG_TIEP_DAN_UPPER:= UPPER(P_NOI_DUNG_TIEP_DAN);
     OPEN P_CUR FOR SELECT A.*, 
                           D.TEN_CAN_BO, 
                           C.TEN_LINH_VUC_KNTC, 
                           DT.TEN_LOAI_DTKNTC,
                           A.KNTC_SO_NHA || ', ' || X.TEN_PHUONG_XA || ', ' || H.TEN_QUAN_HUYEN || ', ' || T.TEN_TINH_THANH AS DIA_CHI,
                           CASE WHEN A.YEU_CAU_GAP_LD =1 THEN 'Có' else 'Không' end AS GAP_LANH_DAO
                    FROM KNTC_HO_SO A,
                         DM_LINH_VUC_KNTC C,
                         CB_CAN_BO D, 
                         DM_PHUONG_XA X, 
                         DM_QUAN_HUYEN H, 
                         DM_TINH_THANH T,
                         DM_LOAI_DTKNTC DT
                    WHERE A.MA_CAN_BO_TIEP_DAN = D.MA_CAN_BO
                    AND A.KNTC_MA_PHUONG_XA=X.MA_PHUONG_XA
                    AND X.MA_QUAN_HUYEN=H.MA_QUAN_HUYEN
                    AND H.MA_TINH_THANH=T.MA_TINH_THANH
                    AND A.KNTC_MA_LOAI_DT=DT.MA_LOAI_DTKNTC
                    AND (P_SO_HO_SO_KNTC IS NULL OR A.SO_HO_SO_KNTC = P_SO_HO_SO_KNTC)
                    AND (P_NGAY_TIEP_NHAN IS NULL OR UPPER(A.NGAY_TIEP_DAN) LIKE P_NGAY_TIEP_NHAN_UPPER)
                    AND A.MA_LINH_VUC_KNTC=C.MA_LINH_VUC_KNTC
                    AND (P_MA_LINH_VUC_KNTC IS NULL OR A.MA_LINH_VUC_KNTC= P_MA_LINH_VUC_KNTC)
                    AND (P_MA_LOAI_KNTC IS NULL OR A.MA_LOAI_KNTC=P_MA_LOAI_KNTC)
                    AND (P_KNTC_MA_LOAI_DT IS NULL OR A.KNTC_MA_LOAI_DT = P_KNTC_MA_LOAI_DT)
                    AND (P_NOI_DUNG_TIEP_DAN IS NULL 
                      OR UPPER(A.NOI_DUNG_TIEP_DAN) LIKE P_NOI_DUNG_TIEP_DAN_UPPER 
                      OR UPPER(A.KNTC_HO_VA_TEN)    LIKE P_NOI_DUNG_TIEP_DAN_UPPER
                      OR UPPER(A.KNTC_CMND)         LIKE P_NOI_DUNG_TIEP_DAN_UPPER
                      )
                    AND (P_DIA_CHI IS NULL 
                         OR UPPER(A.KNTC_SO_NHA || ', ' || X.TEN_PHUONG_XA || ', ' || H.TEN_QUAN_HUYEN || ', ' || T.TEN_TINH_THANH) LIKE UPPER('%'||P_DIA_CHI||'%'))
                    AND (P_YEU_CAU_GAP_LD =-1 OR A.YEU_CAU_GAP_LD = P_YEU_CAU_GAP_LD)
                    ORDER BY A.SO_HO_SO_KNTC DESC, A.NGAY_TIEP_DAN DESC, A.NGAY_NHAP DESC;
  END;
-------------------------------------------------------------------------------
  PROCEDURE SELECT_TIEP_DAN_DETAIL(P_CUR IN OUT MYCUR, P_MA_HO_SO_KNTC INT) AS
  V_MAX_LAN_GIAI_QUYET INT;
  BEGIN
    SELECT MAX(LAN_GIAI_QUYET) INTO V_MAX_LAN_GIAI_QUYET FROM KNTC_GIAI_QUYET A WHERE A.MA_HO_SO_KNTC = P_MA_HO_SO_KNTC;
    IF V_MAX_LAN_GIAI_QUYET IS NULL THEN
       V_MAX_LAN_GIAI_QUYET:=0;
    END IF; 
    OPEN P_CUR FOR
     SELECT A.*,
            V_MAX_LAN_GIAI_QUYET AS MAX_LAN_GIAI_QUYET,
            D.TEN_CAN_BO, 
            C.TEN_LINH_VUC_KNTC, 
            H.MA_QUAN_HUYEN,
            H.MA_TINH_THANH,
            A.KNTC_SO_NHA || ', ' || X.TEN_PHUONG_XA || ', ' || H.TEN_QUAN_HUYEN || ', ' || T.TEN_TINH_THANH AS DIA_CHI,
            CASE WHEN A.YEU_CAU_GAP_LD =1 THEN 'Có' else 'Không' end AS GAP_LANH_DAO
        FROM KNTC_HO_SO A,DM_LINH_VUC_KNTC C,CB_CAN_BO D, DM_PHUONG_XA X, DM_QUAN_HUYEN H, DM_TINH_THANH T
        WHERE A.MA_CAN_BO_TIEP_DAN = D.MA_CAN_BO
        AND A.MA_LINH_VUC_KNTC = C.MA_LINH_VUC_KNTC
        AND A.KNTC_MA_PHUONG_XA=X.MA_PHUONG_XA
        AND X.MA_QUAN_HUYEN=H.MA_QUAN_HUYEN
        AND H.MA_TINH_THANH=T.MA_TINH_THANH
        AND A.MA_HO_SO_KNTC = P_MA_HO_SO_KNTC;
  END;
 -------------------------------------------------------------------------------
 PROCEDURE UPDATE_TIEP_DAN(P_VAL OUT NVARCHAR2,
                          P_MA_HO_SO_KNTC INT,
                          P_MA_NGUON_DON_DEN NVARCHAR2,
                          P_NGAY_TIEP_DAN NVARCHAR2,
                          P_VU_VIEC_MOI INT,
                          P_NOI_DUNG_TIEP_DAN NVARCHAR2,
                          P_YEU_CAU_GAP_LD INT,
                          P_MA_LD_TIEP_DAN INT,
                          P_Y_KIEN_LD NVARCHAR2,
                          P_MA_CAN_BO_TIEP_DAN INT,
                          P_MA_CO_QUAN_TIEP_DAN NVARCHAR2,
                          P_MA_LINH_VUC_KNTC NVARCHAR2,   
                          P_MA_LOAI_KNTC NVARCHAR2,
                          P_KNTC_MA_LOAI_DT NVARCHAR2,
                          P_KNTC_CMND NVARCHAR2,
                          P_KNTC_HO_VA_TEN NVARCHAR2,
                          P_KNTC_MA_PHUONG_XA NVARCHAR2,
                          P_KNTC_SO_NHA NVARCHAR2,
                          P_KNTC_TEN_CQTC NVARCHAR2,
                          P_KNTC_DIA_CHI_CQTC NVARCHAR2,
                          P_KNTC_SO_NGUOI_DAI_DIEN INT,
                          P_KNTC_TEN_NHUNG_NGUOI_DD NVARCHAR2,
                          P_MA_HO_SO_KNTC_GOC INT,
                          P_MA_DON_VI_XU_LY_CHINH NVARCHAR2
                        ) AS
 V_KNTC_SO_NGUOI_DAI_DIEN INT;
 V_SO_HO_SO_KNTC INT;
 BEGIN
    P_VAL:='THAT_BAI';
    IF P_KNTC_MA_LOAI_DT = 'TC'  OR P_KNTC_MA_LOAI_DT = 'CN' or P_KNTC_SO_NGUOI_DAI_DIEN IS NULL THEN
       V_KNTC_SO_NGUOI_DAI_DIEN:=1;
    ELSE 
       V_KNTC_SO_NGUOI_DAI_DIEN:=P_KNTC_SO_NGUOI_DAI_DIEN;
    END IF;
    IF P_MA_HO_SO_KNTC = 0 THEN
                SELECT MAX(SO_HO_SO_KNTC) INTO V_SO_HO_SO_KNTC FROM KNTC_HO_SO;
                IF V_SO_HO_SO_KNTC IS NULL THEN
                   V_SO_HO_SO_KNTC:=1;
                ELSE
                   V_SO_HO_SO_KNTC:= V_SO_HO_SO_KNTC + 1;
                END IF;
                INSERT INTO KNTC_HO_SO(
                                SO_HO_SO_KNTC,
                                NGAY_NHAP,
                                MA_NGUON_DON_DEN,
                                NGAY_TIEP_DAN,
                                VU_VIEC_MOI,
                                NOI_DUNG_TIEP_DAN,
                                YEU_CAU_GAP_LD,
                                MA_LD_TIEP_DAN,
                                Y_KIEN_LD,
                                MA_CAN_BO_TIEP_DAN,
                                MA_CO_QUAN_TIEP_DAN,
                                MA_LINH_VUC_KNTC,   
                                MA_LOAI_KNTC,
                                KNTC_MA_LOAI_DT,
                                KNTC_CMND,
                                KNTC_HO_VA_TEN,
                                KNTC_MA_PHUONG_XA,
                                KNTC_SO_NHA,
                                KNTC_TEN_CQTC,
                                KNTC_DIA_CHI_CQTC,
                                KNTC_SO_NGUOI_DAI_DIEN,
                                KNTC_TEN_NHUNG_NGUOI_DD,
                                MA_HO_SO_KNTC_GOC,
                                MA_DON_VI_XU_LY_CHINH
                                )
                         VALUES (
                                V_SO_HO_SO_KNTC,
                                SYSDATE,
                                P_MA_NGUON_DON_DEN,
                                P_NGAY_TIEP_DAN,
                                P_VU_VIEC_MOI,
                                P_NOI_DUNG_TIEP_DAN,
                                P_YEU_CAU_GAP_LD,
                                CASE WHEN P_MA_LD_TIEP_DAN =0 THEN NULL ELSE P_MA_LD_TIEP_DAN END,
                                P_Y_KIEN_LD,
                                P_MA_CAN_BO_TIEP_DAN,
                                P_MA_CO_QUAN_TIEP_DAN,
                                P_MA_LINH_VUC_KNTC,   
                                P_MA_LOAI_KNTC,
                                P_KNTC_MA_LOAI_DT,
                                P_KNTC_CMND,
                                P_KNTC_HO_VA_TEN,
                                P_KNTC_MA_PHUONG_XA,
                                P_KNTC_SO_NHA,
                                P_KNTC_TEN_CQTC,
                                P_KNTC_DIA_CHI_CQTC,
                                V_KNTC_SO_NGUOI_DAI_DIEN,
                                P_KNTC_TEN_NHUNG_NGUOI_DD,
                                P_MA_HO_SO_KNTC_GOC,
                                P_MA_DON_VI_XU_LY_CHINH
                                );
    ELSE
                 UPDATE KNTC_HO_SO A SET A.MA_NGUON_DON_DEN=P_MA_NGUON_DON_DEN,
                                         A.NGAY_TIEP_DAN=P_NGAY_TIEP_DAN,
                                         A.VU_VIEC_MOI=P_VU_VIEC_MOI,
                                         A.NOI_DUNG_TIEP_DAN=P_NOI_DUNG_TIEP_DAN,
                                         A.YEU_CAU_GAP_LD=P_YEU_CAU_GAP_LD,
                                         A.MA_LD_TIEP_DAN= CASE WHEN P_MA_LD_TIEP_DAN =0 THEN NULL ELSE P_MA_LD_TIEP_DAN END,
                                         A.Y_KIEN_LD=P_Y_KIEN_LD,
                                         A.MA_LINH_VUC_KNTC=P_MA_LINH_VUC_KNTC,
                                         A.MA_LOAI_KNTC=P_MA_LOAI_KNTC,
                                         A.KNTC_MA_LOAI_DT=P_KNTC_MA_LOAI_DT,
                                         A.KNTC_CMND=P_KNTC_CMND,
                                         A.KNTC_HO_VA_TEN=P_KNTC_HO_VA_TEN,
                                         A.KNTC_MA_PHUONG_XA=P_KNTC_MA_PHUONG_XA,
                                         A.KNTC_SO_NHA=P_KNTC_SO_NHA,
                                         A.KNTC_TEN_CQTC=P_KNTC_TEN_CQTC,
                                         A.KNTC_DIA_CHI_CQTC=P_KNTC_DIA_CHI_CQTC,
                                         A.KNTC_SO_NGUOI_DAI_DIEN=V_KNTC_SO_NGUOI_DAI_DIEN,
                                         A.KNTC_TEN_NHUNG_NGUOI_DD=P_KNTC_TEN_NHUNG_NGUOI_DD,
                                         A.MA_HO_SO_KNTC_GOC=P_MA_HO_SO_KNTC_GOC,
                                         A.MA_DON_VI_XU_LY_CHINH=P_MA_DON_VI_XU_LY_CHINH
              WHERE A.MA_HO_SO_KNTC=P_MA_HO_SO_KNTC;
    END IF;
    P_VAL:='THANH_CONG';
  END;
  -------------------------------------------------------------------------------
  PROCEDURE UPDATE_NGUOI_BI_KNTC(P_VAL OUT NVARCHAR2,
                          P_MA_HO_SO_KNTC INT,
                          P_BKNTC_MA_LOAI_DT NVARCHAR2,
                          P_BKNTC_HO_VA_TEN NVARCHAR2,
                          P_BKNTC_DIA_CHI NVARCHAR2,
                          P_BKNTC_TEN_CQTC NVARCHAR2,
                          P_BKNTC_DIA_CHI_CQTC NVARCHAR2
                        ) AS
 BEGIN
    P_VAL:='THAT_BAI';
            UPDATE KNTC_HO_SO A SET A.BKNTC_MA_LOAI_DT=P_BKNTC_MA_LOAI_DT,
                                         A.BKNTC_HO_VA_TEN=P_BKNTC_HO_VA_TEN,
                                         A.BKNTC_DIA_CHI=P_BKNTC_DIA_CHI,
                                         A.BKNTC_TEN_CQTC=P_BKNTC_TEN_CQTC,
                                         A.BKNTC_DIA_CHI_CQTC=P_BKNTC_DIA_CHI_CQTC
              WHERE A.MA_HO_SO_KNTC=P_MA_HO_SO_KNTC;
    P_VAL:='THANH_CONG';
  END;


    -------------------------------------------------------------------------------
  PROCEDURE UPDATE_GIAI_QUYET(P_VAL OUT NVARCHAR2,
                          P_MA_HO_SO_KNTC INT,
                          P_MA_GIAI_QUYET INT,
                          P_MA_CAN_BO INT,
                          P_NGAY_GIAI_QUYET NVARCHAR2,
                          P_LAN_GIAI_QUYET INT,
                          P_MA_HUONG_GIAI_QUYET NVARCHAR2,
                          P_NOI_DUNG_GIAI_QUYET NVARCHAR2,
                          P_SO_KY_HIEU NVARCHAR2,
                          P_TRICH_YEU NVARCHAR2,
                          P_CO_QUAN_BAN_HANH NVARCHAR2,
                          P_SO_BUT_LUC NVARCHAR2,
                          P_SO_TRANG NVARCHAR2,
                          P_NGAY_TRINH_LANH_DAO_KY NVARCHAR2,
                          P_NGAY_LANH_DAO_KY NVARCHAR2,
                          P_NGAY_CHUYEN_VAN_BAN NVARCHAR2,
                          P_MA_LANH_DAO_KY INT,
                          P_FILE_VAN_BAN NVARCHAR2
                        ) AS
 BEGIN
    P_VAL:='THAT_BAI';
    IF P_MA_GIAI_QUYET = 0 THEN
       INSERT INTO KNTC_GIAI_QUYET (
                                    MA_HO_SO_KNTC,
                                    MA_CAN_BO,
                                    NGAY_GIAI_QUYET,
                                    MA_HUONG_GIAI_QUYET,
                                    NOI_DUNG_GIAI_QUYET,
                                    SO_KY_HIEU,
                                    TRICH_YEU,
                                    CO_QUAN_BAN_HANH,
                                    SO_BUT_LUC,
                                    SO_TRANG,
                                    LAN_GIAI_QUYET,
                                    NGAY_TRINH_LANH_DAO_KY,
                                    NGAY_LANH_DAO_KY,
                                    NGAY_CHUYEN_VAN_BAN,
                                    MA_LANH_DAO_KY,
                                    FILE_VAN_BAN
                                    )
                              VALUES(
                                    P_MA_HO_SO_KNTC,
                                    P_MA_CAN_BO,
                                    P_NGAY_GIAI_QUYET,
                                    P_MA_HUONG_GIAI_QUYET,
                                    P_NOI_DUNG_GIAI_QUYET,
                                    P_SO_KY_HIEU,
                                    P_TRICH_YEU,
                                    P_CO_QUAN_BAN_HANH,
                                    P_SO_BUT_LUC,
                                    P_SO_TRANG,
                                    P_LAN_GIAI_QUYET,
                                    P_NGAY_TRINH_LANH_DAO_KY,
                                    P_NGAY_LANH_DAO_KY,
                                    P_NGAY_CHUYEN_VAN_BAN,
                                    P_MA_LANH_DAO_KY,
                                    P_FILE_VAN_BAN
                                    );
    ELSE
       UPDATE KNTC_GIAI_QUYET A SET A.NGAY_GIAI_QUYET     = P_NGAY_GIAI_QUYET,
                                    A.MA_HUONG_GIAI_QUYET = P_MA_HUONG_GIAI_QUYET,
                                    A.NOI_DUNG_GIAI_QUYET = P_NOI_DUNG_GIAI_QUYET,
                                    A.SO_KY_HIEU          = P_SO_KY_HIEU,
                                    A.TRICH_YEU           = P_TRICH_YEU,
                                    A.CO_QUAN_BAN_HANH    = P_CO_QUAN_BAN_HANH,
                                    A.SO_BUT_LUC          = P_SO_BUT_LUC,
                                    A.SO_TRANG            = P_SO_TRANG,
                                    A.LAN_GIAI_QUYET      = P_LAN_GIAI_QUYET,
                                    A.NGAY_TRINH_LANH_DAO_KY= P_NGAY_TRINH_LANH_DAO_KY,
                                    A.NGAY_LANH_DAO_KY      = P_NGAY_LANH_DAO_KY,
                                    A.NGAY_CHUYEN_VAN_BAN   = P_NGAY_CHUYEN_VAN_BAN,
                                    A.MA_LANH_DAO_KY        = P_MA_LANH_DAO_KY,
                                    A.FILE_VAN_BAN          = P_FILE_VAN_BAN
                              WHERE A.MA_GIAI_QUYET=P_MA_GIAI_QUYET;
    END IF;        
    P_VAL:='THANH_CONG';
  END;
  -------------------------------------------------------------------------------
  PROCEDURE DELETE_GIAI_QUYET(P_VAL OUT NVARCHAR2, P_MA_GIAI_QUYET INT) AS
  BEGIN
    P_VAL:='THAT_BAI';
    DELETE KNTC_GIAI_QUYET A WHERE A.MA_GIAI_QUYET = P_MA_GIAI_QUYET;      
    P_VAL:='THANH_CONG';
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_GIAI_QUYET(P_CUR IN OUT MYCUR, P_MA_HO_SO_KNTC INT) AS
  V_MAX_LAN_GIAI_QUYET INT;
  BEGIN
    SELECT MAX(LAN_GIAI_QUYET) INTO V_MAX_LAN_GIAI_QUYET FROM KNTC_GIAI_QUYET A WHERE A.MA_HO_SO_KNTC = P_MA_HO_SO_KNTC;
    IF V_MAX_LAN_GIAI_QUYET IS NULL THEN
       V_MAX_LAN_GIAI_QUYET:=0;
    END IF; 
    OPEN P_CUR FOR
     SELECT A.*,
            B.TEN_HUONG_GIAI_QUYET, 
            V_MAX_LAN_GIAI_QUYET AS MAX_LAN_GIAI_QUYET
        FROM KNTC_GIAI_QUYET A, DM_HUONG_GIAI_QUYET B
        WHERE A.MA_HO_SO_KNTC = P_MA_HO_SO_KNTC
          AND A.MA_HUONG_GIAI_QUYET = B.MA_HUONG_GIAI_QUYET
          ORDER BY A.LAN_GIAI_QUYET;
  END;
  
 PROCEDURE UPDATE_FILE_GIAI_QUYET(P_VAL OUT NVARCHAR2, P_MA_GIAI_QUYET NVARCHAR2, P_FILE_VAN_BAN NVARCHAR2) AS
   BEGIN
      UPDATE KNTC_GIAI_QUYET A SET A.FILE_VAN_BAN          = P_FILE_VAN_BAN
                              WHERE A.MA_GIAI_QUYET=P_MA_GIAI_QUYET;
      P_VAL:='TC';
   END;
/*  -----------------------------------------------------------------------------
  PROCEDURE UPDATE_TIEP_DAN_CO_DON(P_VAL OUT NVARCHAR2,
                          P_MA_HO_SO_KNTC INT,
                          P_MA_NGUON_DON_DEN NVARCHAR2,
                          P_NGAY_TIEP_DAN NVARCHAR2,
                          P_VU_VIEC_MOI INT,
                          P_NOI_DUNG_TIEP_DAN NVARCHAR2,
                          P_YEU_CAU_GAP_LD INT,
                          P_MA_LD_TIEP_DAN INT,
                          P_Y_KIEN_LD NVARCHAR2,
                          P_MA_CAN_BO_TIEP_DAN INT,
                          P_MA_CO_QUAN_TIEP_DAN NVARCHAR2,
                          P_MA_LINH_VUC_KNTC NVARCHAR2,   
                          P_MA_LOAI_KNTC NVARCHAR2,
                          P_KNTC_MA_LOAI_DT NVARCHAR2,
                          P_KNTC_CMND NVARCHAR2,
                          P_KNTC_HO_VA_TEN NVARCHAR2,
                          P_KNTC_MA_PHUONG_XA NVARCHAR2,
                          P_KNTC_SO_NHA NVARCHAR2,
                          P_KNTC_TEN_CQTC NVARCHAR2,
                          P_KNTC_DIA_CHI_CQTC NVARCHAR2,
                          P_KNTC_SO_NGUOI_DAI_DIEN INT,
                          P_KNTC_TEN_NHUNG_NGUOI_DD NVARCHAR2,
                          P_MA_HO_SO_KNTC_GOC INT,
                          P_MA_DON_VI_XU_LY_CHINH NVARCHAR2,
                          P_MA_TRANG_THAI_GIAI_QUYET  NVARCHAR2
                        ) AS
 V_KNTC_SO_NGUOI_DAI_DIEN INT;
 V_SO_HO_SO_KNTC INT;
 BEGIN
    P_VAL:='THAT_BAI';
    IF P_KNTC_MA_LOAI_DT = 'TC'  OR P_KNTC_MA_LOAI_DT = 'CN' or P_KNTC_SO_NGUOI_DAI_DIEN IS NULL THEN
       V_KNTC_SO_NGUOI_DAI_DIEN:=1;
    ELSE 
       V_KNTC_SO_NGUOI_DAI_DIEN:=P_KNTC_SO_NGUOI_DAI_DIEN;
    END IF;
    IF P_MA_HO_SO_KNTC = 0 THEN
                SELECT MAX(SO_HO_SO_KNTC) INTO V_SO_HO_SO_KNTC FROM KNTC_HO_SO;
                IF V_SO_HO_SO_KNTC IS NULL THEN
                   V_SO_HO_SO_KNTC:=1;
                END IF;
                INSERT INTO KNTC_HO_SO(
                                SO_HO_SO_KNTC,
                                NGAY_NHAP,
                                MA_NGUON_DON_DEN,
                                NGAY_TIEP_DAN,
                                VU_VIEC_MOI,
                                NOI_DUNG_TIEP_DAN,
                                YEU_CAU_GAP_LD,
                                MA_LD_TIEP_DAN,
                                Y_KIEN_LD,
                                MA_CAN_BO_TIEP_DAN,
                                MA_CO_QUAN_TIEP_DAN,
                                MA_LINH_VUC_KNTC,   
                                MA_LOAI_KNTC,
                                KNTC_MA_LOAI_DT,
                                KNTC_CMND,
                                KNTC_HO_VA_TEN,
                                KNTC_MA_PHUONG_XA,
                                KNTC_SO_NHA,
                                KNTC_TEN_CQTC,
                                KNTC_DIA_CHI_CQTC,
                                KNTC_SO_NGUOI_DAI_DIEN,
                                KNTC_TEN_NHUNG_NGUOI_DD,
                                MA_HO_SO_KNTC_GOC,
                                MA_DON_VI_XU_LY_CHINH,
                                MA_TRANG_THAI_GIAI_QUYET
                                )
                         VALUES (
                                V_SO_HO_SO_KNTC,
                                SYSDATE,
                                P_MA_NGUON_DON_DEN,
                                P_NGAY_TIEP_DAN,
                                P_VU_VIEC_MOI,
                                P_NOI_DUNG_TIEP_DAN,
                                P_YEU_CAU_GAP_LD,
                                CASE WHEN P_MA_LD_TIEP_DAN =0 THEN NULL ELSE P_MA_LD_TIEP_DAN END,
                                P_Y_KIEN_LD,
                                P_MA_CAN_BO_TIEP_DAN,
                                P_MA_CO_QUAN_TIEP_DAN,
                                P_MA_LINH_VUC_KNTC,   
                                P_MA_LOAI_KNTC,
                                P_KNTC_MA_LOAI_DT,
                                P_KNTC_CMND,
                                P_KNTC_HO_VA_TEN,
                                P_KNTC_MA_PHUONG_XA,
                                P_KNTC_SO_NHA,
                                P_KNTC_TEN_CQTC,
                                P_KNTC_DIA_CHI_CQTC,
                                V_KNTC_SO_NGUOI_DAI_DIEN,
                                P_KNTC_TEN_NHUNG_NGUOI_DD,
                                P_MA_HO_SO_KNTC_GOC,
                                P_MA_DON_VI_XU_LY_CHINH,
                                P_MA_TRANG_THAI_GIAI_QUYET
                                );
    ELSE
            UPDATE KNTC_HO_SO A SET A.MA_NGUON_DON_DEN=P_MA_NGUON_DON_DEN,
                                         A.NGAY_TIEP_DAN=P_NGAY_TIEP_DAN,
                                         A.VU_VIEC_MOI=P_VU_VIEC_MOI,
                                         A.NOI_DUNG_TIEP_DAN=P_NOI_DUNG_TIEP_DAN,
                                         A.YEU_CAU_GAP_LD=P_YEU_CAU_GAP_LD,
                                         A.MA_LD_TIEP_DAN= CASE WHEN P_MA_LD_TIEP_DAN =0 THEN NULL ELSE P_MA_LD_TIEP_DAN END,
                                         A.Y_KIEN_LD=P_Y_KIEN_LD,
                                         A.MA_LINH_VUC_KNTC=P_MA_LINH_VUC_KNTC,
                                         A.MA_LOAI_KNTC=P_MA_LOAI_KNTC,
                                         A.KNTC_MA_LOAI_DT=P_KNTC_MA_LOAI_DT,
                                         A.KNTC_CMND=P_KNTC_CMND,
                                         A.KNTC_HO_VA_TEN=P_KNTC_HO_VA_TEN,
                                         A.KNTC_MA_PHUONG_XA=P_KNTC_MA_PHUONG_XA,
                                         A.KNTC_SO_NHA=P_KNTC_SO_NHA,
                                         A.KNTC_TEN_CQTC=P_KNTC_TEN_CQTC,
                                         A.KNTC_DIA_CHI_CQTC = P_KNTC_DIA_CHI_CQTC,
                                         A.KNTC_SO_NGUOI_DAI_DIEN=V_KNTC_SO_NGUOI_DAI_DIEN,
                                         A.KNTC_TEN_NHUNG_NGUOI_DD=P_KNTC_TEN_NHUNG_NGUOI_DD,
                                         A.MA_HO_SO_KNTC_GOC=P_MA_HO_SO_KNTC_GOC,
                                         A.MA_DON_VI_XU_LY_CHINH=P_MA_DON_VI_XU_LY_CHINH,
                                         A.MA_TRANG_THAI_GIAI_QUYET=P_MA_TRANG_THAI_GIAI_QUYET
              WHERE A.MA_HO_SO_KNTC=P_MA_HO_SO_KNTC;
    END IF;
    P_VAL:='THANH_CONG';
  END;*/
-------------------------------------------------------------------------------
  PROCEDURE M2A(P_CUR IN OUT MYCUR, P_TU_NGAY NVARCHAR2, P_DEN_NGAY NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR SELECT 
    -- tất cả
     --TAT_CA.MA_DON_VI_XU_LY_CHINH AS MA_DON_VI,
     TAT_CA.TEN_DON_VI,
     TAT_CA.TC_SO_LUOT,
     TAT_CA.TC_SO_NGUOI,
     TAT_CA.TC_MOI_PHAT_SINH,
     TAT_CA.TC_VU_VIEC_CU,
     -- tiếp thường xuyên cá nhân
     TXTCCN.TXTCCN_SO_LUOT,
     TXTCCN.TXTCCN_SO_NGUOI,
     TXTCCN.TXTCCN_MOI_PHAT_SINH,
     TXTCCN.TXTCCN_VU_VIEC_CU,
     -- tiếp thường xuyên tập thể, tổ chức
     TXTT.TXTT_SO_LUOT,
     TXTT.TXTT_SO_NGUOI,
     TXTT.TXTT_MOI_PHAT_SINH,
     TXTT.TXTT_VU_VIEC_CU,
     -- tiếp đột xuất lãnh đạo cá nhân
     LDTCCN.LDTCCN_SO_LUOT,
     LDTCCN.LDTCCN_SO_NGUOI,
     LDTCCN.LDTCCN_MOI_PHAT_SINH,
     LDTCCN.LDTCCN_VU_VIEC_CU,
     -- tiếp đột xuất lãnh đạo tập thể, tổ chức
     LDTT.LDTT_SO_LUOT,
     LDTT.LDTT_SO_NGUOI,
     LDTT.LDTT_MOI_PHAT_SINH,
     LDTT.LDTT_VU_VIEC_CU,
     -- các lĩnh vực khiếu nại
     KN_TCDNGT.KN_TCDNGT,
     KN_CS.KN_CS,
     KN_TS.KN_TS,
     KN_CDCC.KN_CDCC,
     KN_TP.KN_TP,
     KN_CTVHXH.KN_CTVHXH,
     -- các lĩnh vực tố cáo
     TC_HC.TC_HC,
     TC_TP.TC_TP,
     TC_TN.TC_TN,
     -- phản ánh kiến nghị khác
     PA_KN_K.PA_KN_K,
     -- kết quả giải quyết
     CGQ.CGQ,
     CCQD.CCQD,
     DCQD.DCQD,
     DCBA.DCBA
     FROM 
       (SELECT A.MA_DON_VI_XU_LY_CHINH , B.TEN_DON_VI, 
                    COUNT(A.MA_HO_SO_KNTC)                      AS TC_SO_LUOT,
                    SUM(A.KNTC_SO_NGUOI_DAI_DIEN)               AS TC_SO_NGUOI,
                    SUM(A.VU_VIEC_MOI)                          AS TC_MOI_PHAT_SINH,
                    COUNT(A.MA_HO_SO_KNTC) - SUM(A.VU_VIEC_MOI) AS TC_VU_VIEC_CU
                FROM KNTC_HO_SO A, CB_DON_VI B
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_DON_VI_XU_LY_CHINH=B.MA_DON_VI
                GROUP BY A.MA_DON_VI_XU_LY_CHINH, B.TEN_DON_VI
        ) TAT_CA,-- tồng cộng tất cả của đơn vị
        
       (SELECT A.MA_DON_VI_XU_LY_CHINH, 
                    COUNT(A.MA_HO_SO_KNTC)                      AS TXTCCN_SO_LUOT,
                    SUM(A.KNTC_SO_NGUOI_DAI_DIEN)               AS TXTCCN_SO_NGUOI,
                    SUM(A.VU_VIEC_MOI)                          AS TXTCCN_MOI_PHAT_SINH,
                    COUNT(A.MA_HO_SO_KNTC) - SUM(A.VU_VIEC_MOI) AS TXTCCN_VU_VIEC_CU
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                --AND A.KNTC_MA_LOAI_DT <> 'TT'
                AND A.MA_LD_TIEP_DAN IS NULL
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) TXTCCN,-- thường xuyên tiếp cá nhân
        
        (SELECT A.MA_DON_VI_XU_LY_CHINH, 
                    COUNT(A.MA_HO_SO_KNTC)                      AS TXTT_SO_LUOT,
                    SUM(A.KNTC_SO_NGUOI_DAI_DIEN)               AS TXTT_SO_NGUOI,
                    SUM(A.VU_VIEC_MOI)                          AS TXTT_MOI_PHAT_SINH,
                    COUNT(A.MA_HO_SO_KNTC) - SUM(A.VU_VIEC_MOI) AS TXTT_VU_VIEC_CU
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.KNTC_MA_LOAI_DT = 'TT'
                AND A.MA_LD_TIEP_DAN IS NULL
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) TXTT,-- thường xuyên tiếp tập thể
        
        (SELECT A.MA_DON_VI_XU_LY_CHINH, 
                    COUNT(A.MA_HO_SO_KNTC)                      AS LDTCCN_SO_LUOT,
                    SUM(A.KNTC_SO_NGUOI_DAI_DIEN)               AS LDTCCN_SO_NGUOI,
                    SUM(A.VU_VIEC_MOI)                          AS LDTCCN_MOI_PHAT_SINH,
                    COUNT(A.MA_HO_SO_KNTC) - SUM(A.VU_VIEC_MOI) AS LDTCCN_VU_VIEC_CU
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.KNTC_MA_LOAI_DT <> 'TT'
                AND A.MA_LD_TIEP_DAN IS NOT NULL
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
         ) LDTCCN,-- lãnh đạo  tiếp cá nhân
         
        (SELECT A.MA_DON_VI_XU_LY_CHINH, 
                    COUNT(A.MA_HO_SO_KNTC)                      AS LDTT_SO_LUOT,
                    SUM(A.KNTC_SO_NGUOI_DAI_DIEN)               AS LDTT_SO_NGUOI,
                    SUM(A.VU_VIEC_MOI)                          AS LDTT_MOI_PHAT_SINH,
                    COUNT(A.MA_HO_SO_KNTC) - SUM(A.VU_VIEC_MOI) AS LDTT_VU_VIEC_CU
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.KNTC_MA_LOAI_DT = 'TT'
                AND A.MA_LD_TIEP_DAN IS NOT NULL
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) LDTT,-- lãnh đạo tiếp tập thể
        
        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS KN_TCDNGT
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'TC'
                AND A.MA_LOAI_KNTC = 'KN'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) KN_TCDNGT,-- HIẾU NẠI-- Về tranh chấp, đòi đất cũ, đền bù, giải tỏa
        
        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS KN_CS
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'CS'
                AND A.MA_LOAI_KNTC = 'KN'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) KN_CS,-- KHIẾU NẠI-- Về chính sách
        
        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS KN_TS
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'TS'
                AND A.MA_LOAI_KNTC = 'KN'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) KN_TS,-- KHIẾU NẠI-- Về tài sản
        
        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS KN_CDCC
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'TC'
                AND A.MA_LOAI_KNTC = 'KN'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) KN_CDCC,-- KHIẾU NẠI-- Về chế dộ công chức viên chức
        
        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS KN_TP
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'TP'
                AND A.MA_LOAI_KNTC = 'KN'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) KN_TP,-- KHIẾU NẠI-- về tư pháp
        
        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS KN_CTVHXH
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'CTVHXH'
                AND A.MA_LOAI_KNTC = 'KN'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) KN_CTVHXH,-- KHIẾU NẠI-- về chính trị văn hóa xã hội khác
        
        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS TC_HC
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'HC'
                AND A.MA_LOAI_KNTC = 'TC'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) TC_HC,-- TỐ CÁO-- Về hành chính
        
        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS TC_TP
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'TP'
                AND A.MA_LOAI_KNTC = 'TC'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) TC_TP,-- TỐ CÁO-- Về tư pháp
        
        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS TC_TN
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_LINH_VUC_KNTC = 'TN'
                AND A.MA_LOAI_KNTC = 'TC'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) TC_TN,-- TỐ CÁO-- về tham nhũng
        
        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS PA_KN_K
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                  AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                  AND A.MA_NGUON_DON_DEN IS NULL
                  AND A.MA_LOAI_KNTC = 'K'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) PA_KN_K,-- Phản ánh kiến nghị khác
        
        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS CGQ
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NULL
                AND A.MA_TRANG_THAI_GIAI_QUYET = 'CGQ'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) CGQ,-- chua giai quyet
        
        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS CCQD
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                  AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                  AND A.MA_NGUON_DON_DEN IS NULL
                  AND A.MA_TRANG_THAI_GIAI_QUYET = 'CCQD'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) CCQD,-- chua co quyet dinh
        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS DCQD
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                  AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                  AND A.MA_NGUON_DON_DEN IS NULL
                  AND A.MA_TRANG_THAI_GIAI_QUYET = 'DCQD'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) DCQD,-- da co quyet dinh
        
        (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS DCBA
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                  AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                  AND A.MA_NGUON_DON_DEN IS NULL
                  AND A.MA_TRANG_THAI_GIAI_QUYET = 'DCBA'
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) DCBA-- da co ban an
        
        
        WHERE TAT_CA.MA_DON_VI_XU_LY_CHINH = TXTCCN.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = TXTT.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = LDTT.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = LDTCCN.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = KN_TCDNGT.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = KN_CS.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = KN_TS.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = KN_CDCC.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = KN_TP.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = KN_CTVHXH.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = TC_HC.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = TC_TP.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = TC_TN.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = PA_KN_K.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = CGQ.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = CCQD.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = DCQD.MA_DON_VI_XU_LY_CHINH(+)
          AND TAT_CA.MA_DON_VI_XU_LY_CHINH = DCBA.MA_DON_VI_XU_LY_CHINH(+)
          ;
  END;   
  -----------------------------------------------------------------------------
  PROCEDURE M2B(P_CUR IN OUT MYCUR, P_TU_NGAY NVARCHAR2, P_DEN_NGAY NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR SELECT 
     TAT_CA.MA_DON_VI_XU_LY_CHINH AS MA_DON_VI,
     TAT_CA.TC_SO_DON,
     TNTK.TNTK_NHIEU_NGUOI,
     TAT_CA.TC_SO_DON - TNTK.TNTK_NHIEU_NGUOI AS TNTK_MOT_NGUOI
     FROM 
       (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS TC_SO_DON
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NOT NULL
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) TAT_CA,
        
       (SELECT A.MA_DON_VI_XU_LY_CHINH, COUNT(A.MA_HO_SO_KNTC) AS TNTK_NHIEU_NGUOI
                FROM KNTC_HO_SO A
                WHERE TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') >= TO_DATE(P_TU_NGAY,'DD/MM/YYYY')
                AND TO_DATE(A.NGAY_TIEP_DAN,'DD/MM/YYYY') <= TO_DATE(P_DEN_NGAY,'DD/MM/YYYY')
                AND A.MA_NGUON_DON_DEN IS NOT NULL
                AND A.KNTC_SO_NGUOI_DAI_DIEN > 0
                GROUP BY A.MA_DON_VI_XU_LY_CHINH
        ) TNTK -- tiếp nhận trong kỳ
        
        WHERE TAT_CA.MA_DON_VI_XU_LY_CHINH = TNTK.MA_DON_VI_XU_LY_CHINH(+)
          ;
  END;    
END KNTC_BK;
/

prompt
prompt Creating package body KNTC_DM
prompt =============================
prompt
create or replace package body hai.KNTC_DM is

   ---------------------------------------------DM_HUONG_GIAI_QUYET----------------------------------
  PROCEDURE SELECT_HUONG_GIAI_QUYET(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_HUONG_GIAI_QUYET = 0 THEN
                'Mở'
               ELSE
                'Ðóng'
             END AS TEN_TRANG_THAI
        FROM DM_HUONG_GIAI_QUYET A
       ORDER BY A.STT_HUONG_GIAI_QUYET , A.TEN_HUONG_GIAI_QUYET;
  END;
  -------------------------------------------------------------------------------
    PROCEDURE SELECT_HUONG_GIAI_QUYET_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_HUONG_GIAI_QUYET NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_HUONG_GIAI_QUYET = 0 THEN
                'Mở'
               ELSE
                'Ðóng'
             END AS TEN_TRANG_THAI
        FROM DM_HUONG_GIAI_QUYET A
       WHERE A.MA_HUONG_GIAI_QUYET LIKE P_MA_HUONG_GIAI_QUYET;
  END;
    -------------------------------------------------------------------------------
 
  PROCEDURE UPDATE_HUONG_GIAI_QUYET(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_HUONG_GIAI_QUYET     NVARCHAR2,
                           P_TEN_HUONG_GIAI_QUYET    NVARCHAR2,
                           P_STT_HUONG_GIAI_QUYET    INT,
                           P_TT_HUONG_GIAI_QUYET     INT) AS
    V_TON_TAI_MA  INT;
    V_TON_TAI_TEN INT;
  BEGIN
    P_VAL := 'CO_LOI';
  
    IF P_UPDATE_TYPE = 'THEM_MOI' THEN
      SELECT COUNT(MA_HUONG_GIAI_QUYET)
        INTO V_TON_TAI_MA
        FROM DM_HUONG_GIAI_QUYET
       WHERE UPPER(MA_HUONG_GIAI_QUYET) LIKE UPPER(P_MA_HUONG_GIAI_QUYET);
      SELECT COUNT(MA_HUONG_GIAI_QUYET)
        INTO V_TON_TAI_TEN
        FROM DM_HUONG_GIAI_QUYET
       WHERE UPPER(TEN_HUONG_GIAI_QUYET) LIKE UPPER(P_TEN_HUONG_GIAI_QUYET);
      IF V_TON_TAI_MA > 0 OR P_MA_HUONG_GIAI_QUYET = '0' THEN
        -- kiem tra trung ma , khong cho them ma='0'
        P_VAL := 'TON_TAI_MA';
      ELSIF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten   
        P_VAL := 'TON_TAI_TEN';
      ELSE
        INSERT INTO DM_HUONG_GIAI_QUYET
          (MA_HUONG_GIAI_QUYET,
           TEN_HUONG_GIAI_QUYET,
           STT_HUONG_GIAI_QUYET,
           TT_HUONG_GIAI_QUYET)
        VALUES
          (P_MA_HUONG_GIAI_QUYET,
           P_TEN_HUONG_GIAI_QUYET,
           P_STT_HUONG_GIAI_QUYET,
           P_TT_HUONG_GIAI_QUYET);
        P_VAL := 'THANH_CONG';
      END IF;
    ELSE
      SELECT COUNT(MA_HUONG_GIAI_QUYET)
        INTO V_TON_TAI_TEN
        FROM DM_HUONG_GIAI_QUYET
       WHERE UPPER(TEN_HUONG_GIAI_QUYET) LIKE UPPER(P_TEN_HUONG_GIAI_QUYET)
         AND MA_HUONG_GIAI_QUYET NOT LIKE P_MA_HUONG_GIAI_QUYET;
      IF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten khac no
        P_VAL := 'TON_TAI_TEN';
      ELSE
        UPDATE DM_HUONG_GIAI_QUYET
           SET TEN_HUONG_GIAI_QUYET    = P_TEN_HUONG_GIAI_QUYET,
               STT_HUONG_GIAI_QUYET    = P_STT_HUONG_GIAI_QUYET,
               TT_HUONG_GIAI_QUYET     = P_TT_HUONG_GIAI_QUYET
         WHERE MA_HUONG_GIAI_QUYET LIKE P_MA_HUONG_GIAI_QUYET;
        P_VAL := 'THANH_CONG';
      END IF;
    END IF;
  
  END;
   -------------------------------------------------------------------------------
  PROCEDURE DELETE_HUONG_GIAI_QUYET(P_VAL   OUT NVARCHAR2, P_MA_HUONG_GIAI_QUYET NVARCHAR2) AS
  BEGIN
    P_VAL := 'CO_LOI';
    DELETE FROM DM_HUONG_GIAI_QUYET WHERE MA_HUONG_GIAI_QUYET LIKE P_MA_HUONG_GIAI_QUYET;
    P_VAL := 'THANH_CONG';
   END;  
   ---------------------------------------------DM_HUONG_GIAI_QUYET----------------------------------
  
  PROCEDURE SELECT_TT_GIAI_QUYET(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_TRANG_THAI_GIAI_QUYET = 0 THEN
                'Mở'
               ELSE
                'Ðóng'
             END AS TEN_TRANG_THAI
        FROM DM_TRANG_THAI_GIAI_QUYET A
       ORDER BY A.STT_TRANG_THAI_GIAI_QUYET , A.TEN_TRANG_THAI_GIAI_QUYET;
  END;
  -------------------------------------------------------------------------------
    PROCEDURE SELECT_TT_GIAI_QUYET_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_TRANG_THAI_GIAI_QUYET NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_TRANG_THAI_GIAI_QUYET = 0 THEN
                'Mở'
               ELSE
                'Ðóng'
             END AS TEN_TRANG_THAI
        FROM DM_TRANG_THAI_GIAI_QUYET A
       WHERE A.MA_TRANG_THAI_GIAI_QUYET LIKE P_MA_TRANG_THAI_GIAI_QUYET;
  END;
    -------------------------------------------------------------------------------
 
  PROCEDURE UPDATE_TT_GIAI_QUYET(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_TRANG_THAI_GIAI_QUYET     NVARCHAR2,
                           P_TEN_TRANG_THAI_GIAI_QUYET    NVARCHAR2,
                           P_STT_TRANG_THAI_GIAI_QUYET    INT,
                           P_TT_TRANG_THAI_GIAI_QUYET     INT) AS
    V_TON_TAI_MA  INT;
    V_TON_TAI_TEN INT;
  BEGIN
    P_VAL := 'CO_LOI';
  
    IF P_UPDATE_TYPE = 'THEM_MOI' THEN
      SELECT COUNT(MA_TRANG_THAI_GIAI_QUYET)
        INTO V_TON_TAI_MA
        FROM DM_TRANG_THAI_GIAI_QUYET
       WHERE UPPER(MA_TRANG_THAI_GIAI_QUYET) LIKE UPPER(P_MA_TRANG_THAI_GIAI_QUYET);
      SELECT COUNT(MA_TRANG_THAI_GIAI_QUYET)
        INTO V_TON_TAI_TEN
        FROM DM_TRANG_THAI_GIAI_QUYET
       WHERE UPPER(TEN_TRANG_THAI_GIAI_QUYET) LIKE UPPER(P_TEN_TRANG_THAI_GIAI_QUYET);
      IF V_TON_TAI_MA > 0 OR P_MA_TRANG_THAI_GIAI_QUYET = '0' THEN
        -- kiem tra trung ma , khong cho them ma='0'
        P_VAL := 'TON_TAI_MA';
      ELSIF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten   
        P_VAL := 'TON_TAI_TEN';
      ELSE
        INSERT INTO DM_TRANG_THAI_GIAI_QUYET
          (MA_TRANG_THAI_GIAI_QUYET,
           TEN_TRANG_THAI_GIAI_QUYET,
           STT_TRANG_THAI_GIAI_QUYET,
           TT_TRANG_THAI_GIAI_QUYET)
        VALUES
          (P_MA_TRANG_THAI_GIAI_QUYET,
           P_TEN_TRANG_THAI_GIAI_QUYET,
           P_STT_TRANG_THAI_GIAI_QUYET,
           P_TT_TRANG_THAI_GIAI_QUYET);
        P_VAL := 'THANH_CONG';
      END IF;
    ELSE
      SELECT COUNT(MA_TRANG_THAI_GIAI_QUYET)
        INTO V_TON_TAI_TEN
        FROM DM_TRANG_THAI_GIAI_QUYET
       WHERE UPPER(TEN_TRANG_THAI_GIAI_QUYET) LIKE UPPER(P_TEN_TRANG_THAI_GIAI_QUYET)
         AND MA_TRANG_THAI_GIAI_QUYET NOT LIKE P_MA_TRANG_THAI_GIAI_QUYET;
      IF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten khac no
        P_VAL := 'TON_TAI_TEN';
      ELSE
        UPDATE DM_TRANG_THAI_GIAI_QUYET
           SET TEN_TRANG_THAI_GIAI_QUYET    = P_TEN_TRANG_THAI_GIAI_QUYET,
               STT_TRANG_THAI_GIAI_QUYET    = P_STT_TRANG_THAI_GIAI_QUYET,
               TT_TRANG_THAI_GIAI_QUYET     = P_TT_TRANG_THAI_GIAI_QUYET
         WHERE MA_TRANG_THAI_GIAI_QUYET LIKE P_MA_TRANG_THAI_GIAI_QUYET;
        P_VAL := 'THANH_CONG';
      END IF;
    END IF;
  
  END;
   -------------------------------------------------------------------------------
  PROCEDURE DELETE_TT_GIAI_QUYET(P_VAL   OUT NVARCHAR2, P_MA_TRANG_THAI_GIAI_QUYET NVARCHAR2) AS
  BEGIN
    P_VAL := 'CO_LOI';
    DELETE FROM DM_TRANG_THAI_GIAI_QUYET WHERE MA_TRANG_THAI_GIAI_QUYET LIKE P_MA_TRANG_THAI_GIAI_QUYET;
    P_VAL := 'THANH_CONG';
   END;  
   -------------------------------------DM_LINH_VUC_KNTC------------------------------------------
PROCEDURE SELECT_LINH_VUC_KNTC(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_LINH_VUC_KNTC = 0 THEN
                'Mở'
               ELSE
                'Ðóng'
             END AS TEN_TRANG_THAI
        FROM DM_LINH_VUC_KNTC A
       ORDER BY A.STT_LINH_VUC_KNTC , A.TEN_LINH_VUC_KNTC;
  END;
  -------------------------------------------------------------------------------
    PROCEDURE SELECT_LINH_VUC_KNTC_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_LINH_VUC_KNTC NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_LINH_VUC_KNTC = 0 THEN
                'Mở'
               ELSE
                'Ðóng'
             END AS TEN_TRANG_THAI
        FROM DM_LINH_VUC_KNTC A
       WHERE A.MA_LINH_VUC_KNTC LIKE P_MA_LINH_VUC_KNTC;
  END;
    -------------------------------------------------------------------------------
 
  PROCEDURE UPDATE_LINH_VUC_KNTC(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_LINH_VUC_KNTC     NVARCHAR2,
                           P_TEN_LINH_VUC_KNTC    NVARCHAR2,
                           P_STT_LINH_VUC_KNTC    INT,
                           P_TT_LINH_VUC_KNTC     INT) AS
    V_TON_TAI_MA  INT;
    V_TON_TAI_TEN INT;
  BEGIN
    P_VAL := 'CO_LOI';
  
    IF P_UPDATE_TYPE = 'THEM_MOI' THEN
      SELECT COUNT(MA_LINH_VUC_KNTC)
        INTO V_TON_TAI_MA
        FROM DM_LINH_VUC_KNTC
       WHERE UPPER(MA_LINH_VUC_KNTC) LIKE UPPER(P_MA_LINH_VUC_KNTC);
      SELECT COUNT(MA_LINH_VUC_KNTC)
        INTO V_TON_TAI_TEN
        FROM DM_LINH_VUC_KNTC
       WHERE UPPER(TEN_LINH_VUC_KNTC) LIKE UPPER(P_TEN_LINH_VUC_KNTC);
      IF V_TON_TAI_MA > 0 OR P_MA_LINH_VUC_KNTC = '0' THEN
        -- kiem tra trung ma , khong cho them ma='0'
        P_VAL := 'TON_TAI_MA';
      ELSIF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten   
        P_VAL := 'TON_TAI_TEN';
      ELSE
        INSERT INTO DM_LINH_VUC_KNTC
          (MA_LINH_VUC_KNTC,
           TEN_LINH_VUC_KNTC,
           STT_LINH_VUC_KNTC,
           TT_LINH_VUC_KNTC)
        VALUES
          (P_MA_LINH_VUC_KNTC,
           P_TEN_LINH_VUC_KNTC,
           P_STT_LINH_VUC_KNTC,
           P_TT_LINH_VUC_KNTC);
        P_VAL := 'THANH_CONG';
      END IF;
    ELSE
      SELECT COUNT(MA_LINH_VUC_KNTC)
        INTO V_TON_TAI_TEN
        FROM DM_LINH_VUC_KNTC
       WHERE UPPER(TEN_LINH_VUC_KNTC) LIKE UPPER(P_TEN_LINH_VUC_KNTC)
         AND MA_LINH_VUC_KNTC NOT LIKE P_MA_LINH_VUC_KNTC;
      IF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten khac no
        P_VAL := 'TON_TAI_TEN';
      ELSE
        UPDATE DM_LINH_VUC_KNTC
           SET TEN_LINH_VUC_KNTC    = P_TEN_LINH_VUC_KNTC,
               STT_LINH_VUC_KNTC    = P_STT_LINH_VUC_KNTC,
               TT_LINH_VUC_KNTC     = P_TT_LINH_VUC_KNTC
         WHERE MA_LINH_VUC_KNTC LIKE P_MA_LINH_VUC_KNTC;
        P_VAL := 'THANH_CONG';
      END IF;
    END IF;
  
  END;
   -------------------------------------------------------------------------------
  PROCEDURE DELETE_LINH_VUC_KNTC(P_VAL   OUT NVARCHAR2, P_MA_LINH_VUC_KNTC NVARCHAR2) AS
  BEGIN
    P_VAL := 'CO_LOI';
    DELETE FROM DM_LINH_VUC_KNTC WHERE MA_LINH_VUC_KNTC LIKE P_MA_LINH_VUC_KNTC;
    P_VAL := 'THANH_CONG';
   END;  
   
   --------------------------------DM_LOAI_DTBKNTC-----------------------------------------------
   
   PROCEDURE SELECT_LOAI_DTBKNTC(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_LOAI_DTBKNTC = 0 THEN
                'Mở'
               ELSE
                'Ðóng'
             END AS TEN_TRANG_THAI
        FROM DM_LOAI_DTBKNTC A
       ORDER BY A.STT_LOAI_DTBKNTC , A.TEN_LOAI_DTBKNTC;
  END;
  -------------------------------------------------------------------------------
    PROCEDURE SELECT_LOAI_DTBKNTC_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_LOAI_DTBKNTC NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_LOAI_DTBKNTC = 0 THEN
                'Mở'
               ELSE
                'Ðóng'
             END AS TEN_TRANG_THAI
        FROM DM_LOAI_DTBKNTC A
       WHERE A.MA_LOAI_DTBKNTC LIKE P_MA_LOAI_DTBKNTC;
  END;
    -------------------------------------------------------------------------------
 
  PROCEDURE UPDATE_LOAI_DTBKNTC(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_LOAI_DTBKNTC     NVARCHAR2,
                           P_TEN_LOAI_DTBKNTC    NVARCHAR2,
                           P_STT_LOAI_DTBKNTC    INT,
                           P_TT_LOAI_DTBKNTC     INT) AS
    V_TON_TAI_MA  INT;
    V_TON_TAI_TEN INT;
  BEGIN
    P_VAL := 'CO_LOI';
  
    IF P_UPDATE_TYPE = 'THEM_MOI' THEN
      SELECT COUNT(MA_LOAI_DTBKNTC)
        INTO V_TON_TAI_MA
        FROM DM_LOAI_DTBKNTC
       WHERE UPPER(MA_LOAI_DTBKNTC) LIKE UPPER(P_MA_LOAI_DTBKNTC);
      SELECT COUNT(MA_LOAI_DTBKNTC)
        INTO V_TON_TAI_TEN
        FROM DM_LOAI_DTBKNTC
       WHERE UPPER(TEN_LOAI_DTBKNTC) LIKE UPPER(P_TEN_LOAI_DTBKNTC);
      IF V_TON_TAI_MA > 0 OR P_MA_LOAI_DTBKNTC = '0' THEN
        -- kiem tra trung ma , khong cho them ma='0'
        P_VAL := 'TON_TAI_MA';
      ELSIF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten   
        P_VAL := 'TON_TAI_TEN';
      ELSE
        INSERT INTO DM_LOAI_DTBKNTC
          (MA_LOAI_DTBKNTC,
           TEN_LOAI_DTBKNTC,
           STT_LOAI_DTBKNTC,
           TT_LOAI_DTBKNTC)
        VALUES
          (P_MA_LOAI_DTBKNTC,
           P_TEN_LOAI_DTBKNTC,
           P_STT_LOAI_DTBKNTC,
           P_TT_LOAI_DTBKNTC);
        P_VAL := 'THANH_CONG';
      END IF;
    ELSE
      SELECT COUNT(MA_LOAI_DTBKNTC)
        INTO V_TON_TAI_TEN
        FROM DM_LOAI_DTBKNTC
       WHERE UPPER(TEN_LOAI_DTBKNTC) LIKE UPPER(P_TEN_LOAI_DTBKNTC)
         AND MA_LOAI_DTBKNTC NOT LIKE P_MA_LOAI_DTBKNTC;
      IF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten khac no
        P_VAL := 'TON_TAI_TEN';
      ELSE
        UPDATE DM_LOAI_DTBKNTC
           SET TEN_LOAI_DTBKNTC    = P_TEN_LOAI_DTBKNTC,
               STT_LOAI_DTBKNTC    = P_STT_LOAI_DTBKNTC,
               TT_LOAI_DTBKNTC     = P_TT_LOAI_DTBKNTC
         WHERE MA_LOAI_DTBKNTC LIKE P_MA_LOAI_DTBKNTC;
        P_VAL := 'THANH_CONG';
      END IF;
    END IF;
  
  END;
   -------------------------------------------------------------------------------
  PROCEDURE DELETE_LOAI_DTBKNTC(P_VAL   OUT NVARCHAR2, P_MA_LOAI_DTBKNTC NVARCHAR2) AS
  BEGIN
    P_VAL := 'CO_LOI';
    DELETE FROM DM_LOAI_DTBKNTC WHERE MA_LOAI_DTBKNTC LIKE P_MA_LOAI_DTBKNTC;
    P_VAL := 'THANH_CONG';
   END;  

 --------------------------------DM_LOAI_DTKNTC-----------------------------------------------
   
   PROCEDURE SELECT_LOAI_DTKNTC(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_LOAI_DTKNTC = 0 THEN
                'Mở'
               ELSE
                'Ðóng'
             END AS TEN_TRANG_THAI
        FROM DM_LOAI_DTKNTC A
       ORDER BY A.STT_LOAI_DTKNTC , A.TEN_LOAI_DTKNTC;
  END;
  -------------------------------------------------------------------------------
    PROCEDURE SELECT_LOAI_DTKNTC_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_LOAI_DTKNTC NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_LOAI_DTKNTC = 0 THEN
                'Mở'
               ELSE
                'Ðóng'
             END AS TEN_TRANG_THAI
        FROM DM_LOAI_DTKNTC A
       WHERE A.MA_LOAI_DTKNTC LIKE P_MA_LOAI_DTKNTC;
  END;
    -------------------------------------------------------------------------------
 
  PROCEDURE UPDATE_LOAI_DTKNTC(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_LOAI_DTKNTC     NVARCHAR2,
                           P_TEN_LOAI_DTKNTC    NVARCHAR2,
                           P_STT_LOAI_DTKNTC    INT,
                           P_TT_LOAI_DTKNTC     INT) AS
    V_TON_TAI_MA  INT;
    V_TON_TAI_TEN INT;
  BEGIN
    P_VAL := 'CO_LOI';
  
    IF P_UPDATE_TYPE = 'THEM_MOI' THEN
      SELECT COUNT(MA_LOAI_DTKNTC)
        INTO V_TON_TAI_MA
        FROM DM_LOAI_DTKNTC
       WHERE UPPER(MA_LOAI_DTKNTC) LIKE UPPER(P_MA_LOAI_DTKNTC);
      SELECT COUNT(MA_LOAI_DTKNTC)
        INTO V_TON_TAI_TEN
        FROM DM_LOAI_DTKNTC
       WHERE UPPER(TEN_LOAI_DTKNTC) LIKE UPPER(P_TEN_LOAI_DTKNTC);
      IF V_TON_TAI_MA > 0 OR P_MA_LOAI_DTKNTC = '0' THEN
        -- kiem tra trung ma , khong cho them ma='0'
        P_VAL := 'TON_TAI_MA';
      ELSIF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten   
        P_VAL := 'TON_TAI_TEN';
      ELSE
        INSERT INTO DM_LOAI_DTKNTC
          (MA_LOAI_DTKNTC,
           TEN_LOAI_DTKNTC,
           STT_LOAI_DTKNTC,
           TT_LOAI_DTKNTC)
        VALUES
          (P_MA_LOAI_DTKNTC,
           P_TEN_LOAI_DTKNTC,
           P_STT_LOAI_DTKNTC,
           P_TT_LOAI_DTKNTC);
        P_VAL := 'THANH_CONG';
      END IF;
    ELSE
      SELECT COUNT(MA_LOAI_DTKNTC)
        INTO V_TON_TAI_TEN
        FROM DM_LOAI_DTKNTC
       WHERE UPPER(TEN_LOAI_DTKNTC) LIKE UPPER(P_TEN_LOAI_DTKNTC)
         AND MA_LOAI_DTKNTC NOT LIKE P_MA_LOAI_DTKNTC;
      IF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten khac no
        P_VAL := 'TON_TAI_TEN';
      ELSE
        UPDATE DM_LOAI_DTKNTC
           SET TEN_LOAI_DTKNTC    = P_TEN_LOAI_DTKNTC,
               STT_LOAI_DTKNTC    = P_STT_LOAI_DTKNTC,
               TT_LOAI_DTKNTC     = P_TT_LOAI_DTKNTC
         WHERE MA_LOAI_DTKNTC LIKE P_MA_LOAI_DTKNTC;
        P_VAL := 'THANH_CONG';
      END IF;
    END IF;
  
  END;
   -------------------------------------------------------------------------------
  PROCEDURE DELETE_LOAI_DTKNTC(P_VAL   OUT NVARCHAR2, P_MA_LOAI_DTKNTC NVARCHAR2) AS
  BEGIN
    P_VAL := 'CO_LOI';
    DELETE FROM DM_LOAI_DTKNTC WHERE MA_LOAI_DTKNTC LIKE P_MA_LOAI_DTKNTC;
    P_VAL := 'THANH_CONG';
   END;  
----------------------------------------------------------------------------------
--------------------------------DM_LOAI_KET_QUA-----------------------------------------------
   
   PROCEDURE SELECT_LOAI_KET_QUA(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_LOAI_KET_QUA = 0 THEN
                'Mở'
               ELSE
                'Ðóng'
             END AS TEN_TRANG_THAI
        FROM DM_LOAI_KET_QUA A
       ORDER BY A.STT_LOAI_KET_QUA , A.TEN_LOAI_KET_QUA;
  END;
  -------------------------------------------------------------------------------
    PROCEDURE SELECT_LOAI_KET_QUA_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_LOAI_KET_QUA NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_LOAI_KET_QUA = 0 THEN
                'Mở'
               ELSE
                'Ðóng'
             END AS TEN_TRANG_THAI
        FROM DM_LOAI_KET_QUA A
       WHERE A.MA_LOAI_KET_QUA LIKE P_MA_LOAI_KET_QUA;
  END;
    -------------------------------------------------------------------------------
 
  PROCEDURE UPDATE_LOAI_KET_QUA(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_LOAI_KET_QUA     NVARCHAR2,
                           P_TEN_LOAI_KET_QUA    NVARCHAR2,
                           P_STT_LOAI_KET_QUA    INT,
                           P_TT_LOAI_KET_QUA     INT) AS
    V_TON_TAI_MA  INT;
    V_TON_TAI_TEN INT;
  BEGIN
    P_VAL := 'CO_LOI';
  
    IF P_UPDATE_TYPE = 'THEM_MOI' THEN
      SELECT COUNT(MA_LOAI_KET_QUA)
        INTO V_TON_TAI_MA
        FROM DM_LOAI_KET_QUA
       WHERE UPPER(MA_LOAI_KET_QUA) LIKE UPPER(P_MA_LOAI_KET_QUA);
      SELECT COUNT(MA_LOAI_KET_QUA)
        INTO V_TON_TAI_TEN
        FROM DM_LOAI_KET_QUA
       WHERE UPPER(TEN_LOAI_KET_QUA) LIKE UPPER(P_TEN_LOAI_KET_QUA);
      IF V_TON_TAI_MA > 0 OR P_MA_LOAI_KET_QUA = '0' THEN
        -- kiem tra trung ma , khong cho them ma='0'
        P_VAL := 'TON_TAI_MA';
      ELSIF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten   
        P_VAL := 'TON_TAI_TEN';
      ELSE
        INSERT INTO DM_LOAI_KET_QUA
          (MA_LOAI_KET_QUA,
           TEN_LOAI_KET_QUA,
           STT_LOAI_KET_QUA,
           TT_LOAI_KET_QUA)
        VALUES
          (P_MA_LOAI_KET_QUA,
           P_TEN_LOAI_KET_QUA,
           P_STT_LOAI_KET_QUA,
           P_TT_LOAI_KET_QUA);
        P_VAL := 'THANH_CONG';
      END IF;
    ELSE
      SELECT COUNT(MA_LOAI_KET_QUA)
        INTO V_TON_TAI_TEN
        FROM DM_LOAI_KET_QUA
       WHERE UPPER(TEN_LOAI_KET_QUA) LIKE UPPER(P_TEN_LOAI_KET_QUA)
         AND MA_LOAI_KET_QUA NOT LIKE P_MA_LOAI_KET_QUA;
      IF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten khac no
        P_VAL := 'TON_TAI_TEN';
      ELSE
        UPDATE DM_LOAI_KET_QUA
           SET TEN_LOAI_KET_QUA    = P_TEN_LOAI_KET_QUA,
               STT_LOAI_KET_QUA    = P_STT_LOAI_KET_QUA,
               TT_LOAI_KET_QUA     = P_TT_LOAI_KET_QUA
         WHERE MA_LOAI_KET_QUA LIKE P_MA_LOAI_KET_QUA;
        P_VAL := 'THANH_CONG';
      END IF;
    END IF;
  
  END;
   -------------------------------------------------------------------------------
  PROCEDURE DELETE_LOAI_KET_QUA(P_VAL   OUT NVARCHAR2, P_MA_LOAI_KET_QUA NVARCHAR2) AS
  BEGIN
    P_VAL := 'CO_LOI';
    DELETE FROM DM_LOAI_KET_QUA WHERE MA_LOAI_KET_QUA LIKE P_MA_LOAI_KET_QUA;
    P_VAL := 'THANH_CONG';
   END;  
------------------------------DM_NGUON_DON_DEN------------------------------------------
PROCEDURE SELECT_NGUON_DON_DEN(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_NGUON_DON_DEN = 0 THEN
                'Mở'
               ELSE
                'Đóng'
             END AS TEN_TRANG_THAI
        FROM DM_NGUON_DON_DEN A
       ORDER BY A.STT_NGUON_DON_DEN , A.Ten_NGUON_DON_DEN;
  END;
   -------------------------------------------------------------------------------
    PROCEDURE SELECT_NGUON_DON_DEN_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_NGUON_DON_DEN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_NGUON_DON_DEN = 0 THEN
                'Mở'
               ELSE
                'Đóng'
             END AS TEN_TRANG_THAI
        FROM DM_NGUON_DON_DEN A
       WHERE A.MA_NGUON_DON_DEN LIKE P_MA_NGUON_DON_DEN;
  END;
    -------------------------------------------------------------------------------
 
  PROCEDURE UPDATE_NGUON_DON_DEN(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_NGUON_DON_DEN     NVARCHAR2,
                           P_TEN_NGUON_DON_DEN    NVARCHAR2,
                           P_STT_NGUON_DON_DEN    INT,
                           P_TT_NGUON_DON_DEN     INT) AS
    V_TON_TAI_MA  INT;
    V_TON_TAI_TEN INT;
  BEGIN
    P_VAL := 'CO_LOI';
  
    IF P_UPDATE_TYPE = 'THEM_MOI' THEN
      SELECT COUNT(MA_NGUON_DON_DEN)
        INTO V_TON_TAI_MA
        FROM DM_NGUON_DON_DEN
       WHERE UPPER(MA_NGUON_DON_DEN) LIKE UPPER(P_MA_NGUON_DON_DEN);
      SELECT COUNT(MA_NGUON_DON_DEN)
        INTO V_TON_TAI_TEN
        FROM DM_NGUON_DON_DEN
       WHERE UPPER(TEN_NGUON_DON_DEN) LIKE UPPER(P_TEN_NGUON_DON_DEN);
      IF V_TON_TAI_MA > 0 OR P_MA_NGUON_DON_DEN = '0' THEN
        -- kiem tra trung ma , khong cho them ma='0'
        P_VAL := 'TON_TAI_MA';
      ELSIF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten   
        P_VAL := 'TON_TAI_TEN';
      ELSE
        INSERT INTO DM_NGUON_DON_DEN
          (MA_NGUON_DON_DEN,
           TEN_NGUON_DON_DEN,
           STT_NGUON_DON_DEN,
           TT_NGUON_DON_DEN)
        VALUES
          (P_MA_NGUON_DON_DEN,
           P_TEN_NGUON_DON_DEN,
           P_STT_NGUON_DON_DEN,
           P_TT_NGUON_DON_DEN);
        P_VAL := 'THANH_CONG';
      END IF;
    ELSE
      SELECT COUNT(MA_NGUON_DON_DEN)
        INTO V_TON_TAI_TEN
        FROM DM_NGUON_DON_DEN
       WHERE UPPER(TEN_NGUON_DON_DEN) LIKE UPPER(P_TEN_NGUON_DON_DEN)
         AND MA_NGUON_DON_DEN NOT LIKE P_MA_NGUON_DON_DEN;
      IF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten khac no
        P_VAL := 'TON_TAI_TEN';
      ELSE
        UPDATE DM_NGUON_DON_DEN
           SET TEN_NGUON_DON_DEN    = P_TEN_NGUON_DON_DEN,
               STT_NGUON_DON_DEN    = P_STT_NGUON_DON_DEN,
               TT_NGUON_DON_DEN     = P_TT_NGUON_DON_DEN
         WHERE MA_NGUON_DON_DEN LIKE P_MA_NGUON_DON_DEN;
        P_VAL := 'THANH_CONG';
      END IF;
    END IF;
  
  END;
   -------------------------------------------------------------------------------
  PROCEDURE DELETE_NGUON_DON_DEN(P_VAL   OUT NVARCHAR2, P_MA_NGUON_DON_DEN NVARCHAR2) AS
  BEGIN
    P_VAL := 'CO_LOI';
    DELETE FROM DM_NGUON_DON_DEN WHERE MA_NGUON_DON_DEN LIKE P_MA_NGUON_DON_DEN;
    P_VAL := 'THANH_CONG';
   END;

 ------------------------------DM_LOAI_KNTC------------------------------------------
PROCEDURE SELECT_LOAI_KNTC(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_LOAI_KNTC = 0 THEN
                'Mở'
               ELSE
                'Đóng'
             END AS TEN_TRANG_THAI
        FROM DM_LOAI_KNTC A
       ORDER BY A.STT_LOAI_KNTC , A.Ten_LOAI_KNTC;
  END;
   -------------------------------------------------------------------------------
    PROCEDURE SELECT_LOAI_KNTC_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_LOAI_KNTC NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_LOAI_KNTC = 0 THEN
                'Mở'
               ELSE
                'Đóng'
             END AS TEN_TRANG_THAI
        FROM DM_LOAI_KNTC A
       WHERE A.MA_LOAI_KNTC LIKE P_MA_LOAI_KNTC;
  END;
    -------------------------------------------------------------------------------
 
  PROCEDURE UPDATE_LOAI_KNTC(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_LOAI_KNTC     NVARCHAR2,
                           P_TEN_LOAI_KNTC    NVARCHAR2,
                           P_STT_LOAI_KNTC    INT,
                           P_TT_LOAI_KNTC     INT) AS
    V_TON_TAI_MA  INT;
    V_TON_TAI_TEN INT;
  BEGIN
    P_VAL := 'CO_LOI';
  
    IF P_UPDATE_TYPE = 'THEM_MOI' THEN
      SELECT COUNT(MA_LOAI_KNTC)
        INTO V_TON_TAI_MA
        FROM DM_LOAI_KNTC
       WHERE UPPER(MA_LOAI_KNTC) LIKE UPPER(P_MA_LOAI_KNTC);
      SELECT COUNT(MA_LOAI_KNTC)
        INTO V_TON_TAI_TEN
        FROM DM_LOAI_KNTC
       WHERE UPPER(TEN_LOAI_KNTC) LIKE UPPER(P_TEN_LOAI_KNTC);
      IF V_TON_TAI_MA > 0 OR P_MA_LOAI_KNTC = '0' THEN
        -- kiem tra trung ma , khong cho them ma='0'
        P_VAL := 'TON_TAI_MA';
      ELSIF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten   
        P_VAL := 'TON_TAI_TEN';
      ELSE
        INSERT INTO DM_LOAI_KNTC
          (MA_LOAI_KNTC,
           TEN_LOAI_KNTC,
           STT_LOAI_KNTC,
           TT_LOAI_KNTC)
        VALUES
          (P_MA_LOAI_KNTC,
           P_TEN_LOAI_KNTC,
           P_STT_LOAI_KNTC,
           P_TT_LOAI_KNTC);
        P_VAL := 'THANH_CONG';
      END IF;
    ELSE
      SELECT COUNT(MA_LOAI_KNTC)
        INTO V_TON_TAI_TEN
        FROM DM_LOAI_KNTC
       WHERE UPPER(TEN_LOAI_KNTC) LIKE UPPER(P_TEN_LOAI_KNTC)
         AND MA_LOAI_KNTC NOT LIKE P_MA_LOAI_KNTC;
      IF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten khac no
        P_VAL := 'TON_TAI_TEN';
      ELSE
        UPDATE DM_LOAI_KNTC
           SET TEN_LOAI_KNTC    = P_TEN_LOAI_KNTC,
               STT_LOAI_KNTC    = P_STT_LOAI_KNTC,
               TT_LOAI_KNTC     = P_TT_LOAI_KNTC
         WHERE MA_LOAI_KNTC LIKE P_MA_LOAI_KNTC;
        P_VAL := 'THANH_CONG';
      END IF;
    END IF;
  
  END;
   -------------------------------------------------------------------------------
  PROCEDURE DELETE_LOAI_KNTC(P_VAL   OUT NVARCHAR2, P_MA_LOAI_KNTC NVARCHAR2) AS
  BEGIN
    P_VAL := 'CO_LOI';
    DELETE FROM DM_LOAI_KNTC WHERE MA_LOAI_KNTC LIKE P_MA_LOAI_KNTC;
    P_VAL := 'THANH_CONG';
   END;
------------------------------DM_THAM_QUYEN------------------------------------------
PROCEDURE SELECT_THAM_QUYEN(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_THAM_QUYEN = 0 THEN
                'C'
               ELSE
                'Đóng'
             END AS TEN_TRANG_THAI
        FROM DM_THAM_QUYEN A
       ORDER BY A.STT_THAM_QUYEN , A.Ten_THAM_QUYEN;
  END;
   -------------------------------------------------------------------------------
    PROCEDURE SELECT_THAM_QUYEN_DETAIL(P_CUR  IN OUT MYCUR,
                                  P_MA_THAM_QUYEN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.*,
             CASE
               WHEN A.TT_THAM_QUYEN = 0 THEN
                'Mở'
               ELSE
                'Đóng'
             END AS TEN_TRANG_THAI
        FROM DM_THAM_QUYEN A
       WHERE A.MA_THAM_QUYEN LIKE P_MA_THAM_QUYEN;
  END;
    -------------------------------------------------------------------------------
 
  PROCEDURE UPDATE_THAM_QUYEN(P_VAL            OUT NVARCHAR2,
                           P_UPDATE_TYPE    NVARCHAR2,
                           P_MA_THAM_QUYEN     NVARCHAR2,
                           P_TEN_THAM_QUYEN    NVARCHAR2,
                           P_STT_THAM_QUYEN    INT,
                           P_TT_THAM_QUYEN     INT) AS
    V_TON_TAI_MA  INT;
    V_TON_TAI_TEN INT;
  BEGIN
    P_VAL := 'CO_LOI';
  
    IF P_UPDATE_TYPE = 'THEM_MOI' THEN
      SELECT COUNT(MA_THAM_QUYEN)
        INTO V_TON_TAI_MA
        FROM DM_THAM_QUYEN
       WHERE UPPER(MA_THAM_QUYEN) LIKE UPPER(P_MA_THAM_QUYEN);
      SELECT COUNT(MA_THAM_QUYEN)
        INTO V_TON_TAI_TEN
        FROM DM_THAM_QUYEN
       WHERE UPPER(TEN_THAM_QUYEN) LIKE UPPER(P_TEN_THAM_QUYEN);
      IF V_TON_TAI_MA > 0 OR P_MA_THAM_QUYEN = '0' THEN
        -- kiem tra trung ma , khong cho them ma='0'
        P_VAL := 'TON_TAI_MA';
      ELSIF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten   
        P_VAL := 'TON_TAI_TEN';
      ELSE
        INSERT INTO DM_THAM_QUYEN
          (MA_THAM_QUYEN,
           TEN_THAM_QUYEN,
           STT_THAM_QUYEN,
           TT_THAM_QUYEN)
        VALUES
          (P_MA_THAM_QUYEN,
           P_TEN_THAM_QUYEN,
           P_STT_THAM_QUYEN,
           P_TT_THAM_QUYEN);
        P_VAL := 'THANH_CONG';
      END IF;
    ELSE
      SELECT COUNT(MA_THAM_QUYEN)
        INTO V_TON_TAI_TEN
        FROM DM_THAM_QUYEN
       WHERE UPPER(TEN_THAM_QUYEN) LIKE UPPER(P_TEN_THAM_QUYEN)
         AND MA_THAM_QUYEN NOT LIKE P_MA_THAM_QUYEN;
      IF V_TON_TAI_TEN > 0 THEN
        -- kiem tra trung ten khac no
        P_VAL := 'TON_TAI_TEN';
      ELSE
        UPDATE DM_THAM_QUYEN
           SET TEN_THAM_QUYEN    = P_TEN_THAM_QUYEN,
               STT_THAM_QUYEN    = P_STT_THAM_QUYEN,
               TT_THAM_QUYEN     = P_TT_THAM_QUYEN
         WHERE MA_THAM_QUYEN LIKE P_MA_THAM_QUYEN;
        P_VAL := 'THANH_CONG';
      END IF;
    END IF;
  
  END;
   -------------------------------------------------------------------------------
  PROCEDURE DELETE_THAM_QUYEN(P_VAL   OUT NVARCHAR2, P_MA_THAM_QUYEN NVARCHAR2) AS
  BEGIN
    P_VAL := 'CO_LOI';
    DELETE FROM DM_THAM_QUYEN WHERE MA_THAM_QUYEN LIKE P_MA_THAM_QUYEN;
    P_VAL := 'THANH_CONG';
   END;

end KNTC_DM;
/

prompt
prompt Creating package body KNTC_SELECT
prompt =================================
prompt
create or replace package body hai.KNTC_SELECT is
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_NGUON_DON_DEN(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_NGUON_DON_DEN,
             A.TEN_NGUON_DON_DEN,
             A.STT_NGUON_DON_DEN
      FROM DM_NGUON_DON_DEN A
      UNION 
      SELECT N'' AS MA_NGUON_DON_DEN,
             P_TYPE AS TEN_NGUON_DON_DEN,
             -1 AS STT_NGUON_DON_DEN
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_NGUON_DON_DEN,TEN_NGUON_DON_DEN;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_CHUC_VU(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_CHUC_VU,
             A.TEN_CHUC_VU,
             A.STT_CHUC_VU
      FROM DM_CHUC_VU A
      UNION 
      SELECT N'' AS MA_CHUC_VU,
             P_TYPE AS TEN_CHUC_VU,
             -1 AS STT_CHUC_VU
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_CHUC_VU,TEN_CHUC_VU;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_DAN_TOC(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_DAN_TOC,
             A.TEN_DAN_TOC,
             A.STT_DAN_TOC
      FROM DM_DAN_TOC A
      UNION 
      SELECT N'' AS MA_DAN_TOC,
             P_TYPE AS TEN_DAN_TOC,
             -1 AS STT_DAN_TOC
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_DAN_TOC,TEN_DAN_TOC;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUOC_TICH(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_QUOC_TICH,
             A.TEN_QUOC_TICH,
             A.STT_QUOC_TICH
      FROM DM_QUOC_TICH A
      UNION 
      SELECT N'' AS MA_QUOC_TICH,
             P_TYPE AS TEN_QUOC_TICH,
             -1 AS STT_QUOC_TICH
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_QUOC_TICH,TEN_QUOC_TICH;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_TON_GIAO(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_TON_GIAO,
             A.TEN_TON_GIAO,
             A.STT_TON_GIAO
      FROM DM_TON_GIAO A
      UNION 
      SELECT N'' AS MA_TON_GIAO,
             P_TYPE AS TEN_TON_GIAO,
             -1 AS STT_TON_GIAO
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_TON_GIAO,TEN_TON_GIAO;
  END;

  -------------------------------------------------------------------------------
  PROCEDURE SELECT_THAM_QUYEN(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_THAM_QUYEN,
             A.TEN_THAM_QUYEN,
             A.STT_THAM_QUYEN
      FROM DM_THAM_QUYEN A
      UNION 
      SELECT N'' AS MA_THAM_QUYEN,
             P_TYPE AS TEN_THAM_QUYEN,
             -1 AS STT_THAM_QUYEN
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_THAM_QUYEN,TEN_THAM_QUYEN;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAI_KNTC(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LOAI_KNTC,
             A.TEN_LOAI_KNTC,
             A.STT_LOAI_KNTC
      FROM DM_LOAI_KNTC A
      UNION 
      SELECT N'' AS MA_LOAI_KNTC,
             P_TYPE AS TEN_LOAI_KNTC,
             -1 AS STT_LOAI_KNTC
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_LOAI_KNTC,TEN_LOAI_KNTC;
  END;
  -------------------------------------------------------------------------------
  /*PROCEDURE SELECT_LINH_VUC_KNTC(P_CUR IN OUT MYCUR, P_MA_CO_QUAN NVARCHAR2, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LINH_VUC_KNTC,
             A.TEN_LINH_VUC_KNTC,
             A.STT_LINH_VUC_KNTC
      FROM DM_LINH_VUC_KNTC A, KNTC_HO_SO_KNTC B
      WHERE B.MA_CO_QUAN_TIEP_DAN=P_MA_CO_QUAN
      UNION
      SELECT N'' AS MA_LINH_VUC_KNTC,
             P_TYPE AS TEN_LINH_VUC_KNTC,
             -1 AS STT_LINH_VUC_KNTC
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_LINH_VUC_KNTC,TEN_LINH_VUC_KNTC;
  END;*/
  ------------------------------------------------------------------------------
  PROCEDURE SELECT_LINH_VUC_KNTC(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LINH_VUC_KNTC,
             A.TEN_LINH_VUC_KNTC,
             A.STT_LINH_VUC_KNTC
      FROM DM_LINH_VUC_KNTC A
    
      UNION
      SELECT N'' AS MA_LINH_VUC_KNTC,
             P_TYPE AS TEN_LINH_VUC_KNTC,
             -1 AS STT_LINH_VUC_KNTC
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_LINH_VUC_KNTC,TEN_LINH_VUC_KNTC;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAI_KET_QUA(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LOAI_KET_QUA,
             A.TEN_LOAI_KET_QUA,
             A.STT_LOAI_KET_QUA
      FROM DM_LOAI_KET_QUA A
      UNION 
      SELECT N'' AS MA_LOAI_KET_QUA,
             P_TYPE AS TEN_LOAI_KET_QUA,
             -1 AS STT_LOAI_KET_QUA
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_LOAI_KET_QUA,TEN_LOAI_KET_QUA;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAI_VAN_BAN(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LOAI_VAN_BAN,
             A.TEN_LOAI_VAN_BAN,
             A.STT_LOAI_VAN_BAN
      FROM DM_LOAI_VAN_BAN A
      UNION 
      SELECT N'' AS MA_LOAI_VAN_BAN,
             P_TYPE AS TEN_LOAI_VAN_BAN,
             -1 AS STT_LOAI_VAN_BAN
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_LOAI_VAN_BAN,TEN_LOAI_VAN_BAN;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_TINH_THANH(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_TINH_THANH,
             A.TEN_TINH_THANH,
             A.STT_TINH_THANH
      FROM DM_TINH_THANH A
      UNION 
      SELECT N'' AS MA_TINH_THANH,
             P_TYPE AS TEN_TINH_THANH,
             -1 AS STT_TINH_THANH
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_TINH_THANH,TEN_TINH_THANH;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUAN_HUYEN(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_QUAN_HUYEN,
             A.TEN_QUAN_HUYEN,
             A.STT_QUAN_HUYEN
      FROM DM_QUAN_HUYEN A
      UNION 
      SELECT N'' AS MA_QUAN_HUYEN,
             P_TYPE AS TEN_QUAN_HUYEN,
             -1 AS STT_QUAN_HUYEN
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_QUAN_HUYEN,TEN_QUAN_HUYEN;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUAN_HUYEN_CUA_TINH(P_CUR IN OUT MYCUR, P_MA_TINH_THANH NVARCHAR2, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_QUAN_HUYEN,
             A.TEN_QUAN_HUYEN,
             A.STT_QUAN_HUYEN
      FROM DM_QUAN_HUYEN A WHERE A.MA_TINH_THANH=P_MA_TINH_THANH
      UNION 
      SELECT N'' AS MA_QUAN_HUYEN,
             P_TYPE AS TEN_QUAN_HUYEN,
             -1 AS STT_QUAN_HUYEN
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_QUAN_HUYEN,TEN_QUAN_HUYEN;
  END;  
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_PHUONG_XA(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_PHUONG_XA,
             A.TEN_PHUONG_XA,
             A.STT_PHUONG_XA
      FROM DM_PHUONG_XA A
      UNION 
      SELECT N'' AS MA_PHUONG_XA,
             P_TYPE AS TEN_PHUONG_XA,
             -1 AS STT_PHUONG_XA
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_PHUONG_XA,TEN_PHUONG_XA;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_PHUONG_XA_CUA_HUYEN(P_CUR IN OUT MYCUR, P_MA_QUAN_HUYEN NVARCHAR2, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_PHUONG_XA,
             A.TEN_PHUONG_XA,
             A.STT_PHUONG_XA
      FROM DM_PHUONG_XA A WHERE A.MA_QUAN_HUYEN=P_MA_QUAN_HUYEN
      UNION 
      SELECT N'' AS MA_PHUONG_XA,
             P_TYPE AS TEN_PHUONG_XA,
             -1 AS STT_PHUONG_XA
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_PHUONG_XA,TEN_PHUONG_XA;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAI_DTKNTC(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LOAI_DTKNTC,
             A.TEN_LOAI_DTKNTC,
             A.STT_LOAI_DTKNTC
      FROM DM_LOAI_DTKNTC A
      UNION 
      SELECT N'' AS MA_LOAI_DTKNTC,
             P_TYPE AS TEN_LOAI_DTKNTC,
             -1 AS STT_LOAI_DTKNTC
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_LOAI_DTKNTC,TEN_LOAI_DTKNTC;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAI_DTBKNTC(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LOAI_DTBKNTC,
             A.TEN_LOAI_DTBKNTC,
             A.STT_LOAI_DTBKNTC
      FROM DM_LOAI_DTBKNTC A
      UNION 
      SELECT N'' AS MA_LOAI_DTBKNTC,
             P_TYPE AS TEN_LOAI_DTBKNTC,
             -1 AS STT_LOAI_DTBKNTC
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_LOAI_DTBKNTC,TEN_LOAI_DTBKNTC;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_HUONG_GIAI_QUYET(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_HUONG_GIAI_QUYET,
             A.TEN_HUONG_GIAI_QUYET,
             A.STT_HUONG_GIAI_QUYET
      FROM DM_HUONG_GIAI_QUYET A
      UNION 
      SELECT N'' AS MA_HUONG_GIAI_QUYET,
             P_TYPE AS TEN_HUONG_GIAI_QUYET,
             -1 AS STT_HUONG_GIAI_QUYET
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_HUONG_GIAI_QUYET,TEN_HUONG_GIAI_QUYET;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_TRANG_THAI_GIAI_QUYET(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_TRANG_THAI_GIAI_QUYET,
             A.TEN_TRANG_THAI_GIAI_QUYET,
             A.STT_TRANG_THAI_GIAI_QUYET
      FROM DM_TRANG_THAI_GIAI_QUYET A
      UNION 
      SELECT N'' AS MA_TRANG_THAI_GIAI_QUYET,
             P_TYPE AS TEN_TRANG_THAI_GIAI_QUYET,
             -1 AS STT_TRANG_THAI_GIAI_QUYET
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_TRANG_THAI_GIAI_QUYET,TEN_TRANG_THAI_GIAI_QUYET;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_CO_QUAN(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_CO_QUAN,
             A.TEN_CO_QUAN,
             A.STT_CO_QUAN         
      FROM CB_CO_QUAN A
      UNION 
      SELECT N'' AS MA_CO_QUAN,
             P_TYPE AS TEN_CO_QUAN,
             -1 AS STT_CO_QUAN
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_CO_QUAN,TEN_CO_QUAN;
  END;
  --------------------------------------------------------------------------------
  PROCEDURE SELECT_CAN_BO(P_CUR IN OUT MYCUR, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_CAN_BO,
             A.TEN_CAN_BO,
             A.STT_CAN_BO         
      FROM CB_CAN_BO A
      UNION 
      SELECT 0 AS MA_CAN_BO,
             P_TYPE AS TEN_CAN_BO,
             -1 AS STT_CAN_BO
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_CAN_BO,TEN_CAN_BO;
  END;
 
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_DON_VI_CUA_CQ(P_CUR IN OUT MYCUR, P_MA_CO_QUAN NVARCHAR2, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_DON_VI,
             A.TEN_DON_VI,
             A.STT_DON_VI
      FROM CB_DON_VI A WHERE A.MA_CO_QUAN=P_MA_CO_QUAN
      UNION 
      SELECT N'' AS MA_DON_VI,
             P_TYPE AS TEN_DON_VI,
             -1 AS STT_DON_VI
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_DON_VI,TEN_DON_VI;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LANH_DAO_CUA_CQ(P_CUR IN OUT MYCUR, P_MA_CO_QUAN NVARCHAR2, P_TYPE NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT DISTINCT
             A.MA_CAN_BO,
             A.TEN_CAN_BO,
             A.STT_CAN_BO
      FROM CB_CAN_BO A, CB_THUOC_TO_CHUYEN_MON B
      WHERE A.MA_CO_QUAN=P_MA_CO_QUAN
        --AND A.MA_CAN_BO=B.MA_CAN_BO
       -- AND B.DEN_NGAY IS NULL
      UNION 
      SELECT 0 AS MA_CAN_BO,
             P_TYPE AS TEN_CAN_BO,
             -1 AS STT_CAN_BO
      FROM DUAL WHERE P_TYPE IS NOT NULL
       ORDER BY STT_CAN_BO,TEN_CAN_BO;
  END;         
end KNTC_SELECT;
/

prompt
prompt Creating package body LIB_DM
prompt ============================
prompt
CREATE OR REPLACE PACKAGE BODY HAI.LIB_DM IS
 
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_DONVI_nothing(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_DON_VI,
             A.TEN_DON_VI
        FROM CB_DON_VI A
       ORDER BY A.STT_DON_VI,A.TEN_DON_VI;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_DONVI_tatca(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_DON_VI,
             A.TEN_DON_VI,
             A.STT_DON_VI
      FROM CB_DON_VI A
      UNION 
      SELECT N'' AS MA_DON_VI,
             N'Tất cả' AS TEN_DON_VI,
             -1 AS STT_DON_VI
      FROM DUAL
       ORDER BY STT_DON_VI,TEN_DON_VI;
  END;  
  

  -------------------------------------------------------------------------------
  PROCEDURE SELECT_DONVI_chon(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_DON_VI,
             A.TEN_DON_VI,
             A.STT_DON_VI
      FROM CB_DON_VI A
      UNION 
      SELECT N'' AS MA_DON_VI,
             N'Chọn đơn vị' AS TEN_DON_VI,
             -1 AS STT_DON_VI
      FROM DUAL
       ORDER BY STT_DON_VI,TEN_DON_VI;
  END; 
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_DONVI_phuongxa(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_DON_VI,
             A.TEN_DON_VI,
             A.STT_DON_VI
      FROM CB_DON_VI A WHERE A.MA_PHUONG_XA IS NOT NULL
      UNION 
      SELECT N'' AS MA_DON_VI,
             N'Chọn đơn vị' AS TEN_DON_VI,
             -1 AS STT_DON_VI
      FROM DUAL
       ORDER BY STT_DON_VI,TEN_DON_VI;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_DONVI_motcuaxa(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_DON_VI,
             A.TEN_DON_VI,
             A.STT_DON_VI
      FROM CB_DON_VI A WHERE A.MA_PHUONG_XA IS NOT NULL
      AND A.MA_LOAI_DON_VI LIKE 'BO_PHAN_TN_VA_TKQ_CAP_XA'
      UNION 
      SELECT N'' AS MA_DON_VI,
             N'Chọn đơn vị' AS TEN_DON_VI,
             -1 AS STT_DON_VI
      FROM DUAL
       ORDER BY STT_DON_VI,TEN_DON_VI;
  END;

  -------------------------------------------------------------------------------
  PROCEDURE SELECT_DONVI_motcuaxa2(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_DON_VI,
             A.TEN_DON_VI,
             A.STT_DON_VI
      FROM CB_DON_VI A WHERE A.MA_PHUONG_XA IS NOT NULL
      AND A.MA_LOAI_DON_VI LIKE 'BO_PHAN_TN_VA_TKQ_CAP_XA'
      UNION 
      SELECT N'TOAN_HUYEN' AS MA_DON_VI,
             N'Toàn huyện' AS TEN_DON_VI,
             -1 AS STT_DON_VI
      FROM DUAL
       ORDER BY STT_DON_VI,TEN_DON_VI;
  END;  
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_DONVI_CUA_CQ_nothing(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_DON_VI,
             A.TEN_DON_VI,
             A.STT_DON_VI
      FROM CB_DON_VI A WHERE A.MA_CO_QUAN=P_MA_CO_QUAN
       ORDER BY STT_DON_VI,TEN_DON_VI;
  END; 
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_DONVI_CUA_CQ_tatca(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_DON_VI,
             A.TEN_DON_VI,
             A.STT_DON_VI
      FROM CB_DON_VI A WHERE A.MA_CO_QUAN=P_MA_CO_QUAN
      UNION 
      SELECT N'' AS MA_DON_VI,
             N'Tất cả' AS TEN_DON_VI,
             -1 AS STT_DON_VI
      FROM DUAL
       ORDER BY STT_DON_VI,TEN_DON_VI;
  END; 
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_DONVI_CUA_CQ_chon(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_DON_VI,
             A.TEN_DON_VI,
             A.STT_DON_VI
      FROM CB_DON_VI A WHERE A.MA_CO_QUAN=P_MA_CO_QUAN
      UNION 
      SELECT N'' AS MA_DON_VI,
             N'Chọn đơn vị' AS TEN_DON_VI,
             -1 AS STT_DON_VI
      FROM DUAL
       ORDER BY STT_DON_VI,TEN_DON_VI;
  END;   
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_DONVI_tiepnhan(P_CUR IN OUT MYCUR,P_MA_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_DON_VI,
             A.TEN_DON_VI,
             1 AS STT_DON_VI
      FROM CB_DON_VI A 
      WHERE A.MA_CO_QUAN=P_MA_CO_QUAN
      UNION 
      SELECT N'' AS MA_DON_VI,
             N'Tất cả' AS TEN_DON_VI,
             -1 AS STT_DON_VI
      FROM DUAL
       ORDER BY STT_DON_VI,TEN_DON_VI;
  END;   
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_TOCHUYENMON_nothing(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_TO_CHUYEN_MON,
             A.TEN_TO_CHUYEN_MON
        FROM CB_TO_CHUYEN_MON A
       ORDER BY A.STT_TO_CHUYEN_MON,A.TEN_TO_CHUYEN_MON;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_TOCHUYENMON_tatca(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_TO_CHUYEN_MON,
             A.TEN_TO_CHUYEN_MON,
             A.STT_TO_CHUYEN_MON
      FROM CB_TO_CHUYEN_MON A
      UNION 
      SELECT 0 AS MA_TO_CHUYEN_MON,
             N'Tất cả' AS TEN_TO_CHUYEN_MON,
             -1 AS STT_TO_CHUYEN_MON
      FROM DUAL
       ORDER BY STT_TO_CHUYEN_MON,TEN_TO_CHUYEN_MON;
  END;  
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_TOCHUYENMON_chon(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_TO_CHUYEN_MON,
             A.TEN_TO_CHUYEN_MON,
             A.STT_TO_CHUYEN_MON
      FROM CB_TO_CHUYEN_MON A
      UNION 
      SELECT 0 AS MA_TO_CHUYEN_MON,
             N'Chọn tổ chuyên môn' AS TEN_TO_CHUYEN_MON,
             -1 AS STT_TO_CHUYEN_MON
      FROM DUAL
       ORDER BY STT_TO_CHUYEN_MON,TEN_TO_CHUYEN_MON;
  END;  
   -------------------------------------------------------------------------------
  PROCEDURE SELECT_TOCHUYENMON_null(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT 0 AS MA_TO_CHUYEN_MON,
             N'Chọn tổ chuyên môn' AS TEN_TO_CHUYEN_MON,
             -1 AS STT_TO_CHUYEN_MON
      FROM DUAL;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_TOCHUYENMON_by_mdv(P_CUR IN OUT MYCUR,P_MA_DON_VI NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_TO_CHUYEN_MON,
             A.TEN_TO_CHUYEN_MON,
             A.STT_TO_CHUYEN_MON
      FROM CB_TO_CHUYEN_MON A
      WHERE A.MA_DON_VI = P_MA_DON_VI
      UNION
      SELECT 0 AS MA_TO_CHUYEN_MON,
             N'Chọn tổ chuyên môn' AS TEN_TO_CHUYEN_MON,
             -1 AS STT_TO_CHUYEN_MON
      FROM DUAL
      ORDER BY STT_TO_CHUYEN_MON,TEN_TO_CHUYEN_MON;
  END;    
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_DONVICHUQUAN_nothing(P_CUR IN OUT MYCUR, P_MA_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_DON_VI AS MA_DON_VI_CHU_QUAN,
             A.TEN_DON_VI AS TEN_DON_VI_CHU_QUAN
        FROM CB_DON_VI A
        WHERE A.MA_CO_QUAN=P_MA_CO_QUAN
        --WHERE EXISTS (SELECT 1 FROM CB_DON_VI B WHERE B.MA_DON_VI_CHU_QUAN=A.MA_DON_VI)
       ORDER BY A.STT_DON_VI,TEN_DON_VI_CHU_QUAN;
  END;
 -------------------------------------------------------------------------------
   PROCEDURE SELECT_DONVICHUQUAN_tatca(P_CUR IN OUT MYCUR, P_MA_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_DON_VI AS MA_DON_VI_CHU_QUAN,
             A.TEN_DON_VI AS TEN_DON_VI_CHU_QUAN,
             A.STT_DON_VI
        FROM CB_DON_VI A
        WHERE A.MA_CO_QUAN=P_MA_CO_QUAN
        --WHERE EXISTS (SELECT 1 FROM CB_DON_VI B WHERE B.MA_DON_VI_CHU_QUAN=A.MA_DON_VI)
      UNION 
      SELECT N'' AS MA_DON_VI_CHU_QUAN,
            N'Tất cả' AS TEN_DON_VI_CHU_QUAN,
            -1 AS STT_DON_VI
           FROM DUAL
       ORDER BY STT_DON_VI,TEN_DON_VI_CHU_QUAN;
  END; -------------------------------------------------------------------------------
   PROCEDURE SELECT_DONVICHUQUAN_chon(P_CUR IN OUT MYCUR, P_MA_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_DON_VI AS MA_DON_VI_CHU_QUAN,
             A.TEN_DON_VI AS TEN_DON_VI_CHU_QUAN,
             A.STT_DON_VI
        FROM CB_DON_VI A
        WHERE A.MA_CO_QUAN=P_MA_CO_QUAN
        --WHERE EXISTS (SELECT 1 FROM CB_DON_VI B WHERE B.MA_DON_VI_CHU_QUAN=A.MA_DON_VI)
      UNION 
      SELECT N'' AS MA_DON_VI_CHU_QUAN,
            N'Chọn đơn vị chủ quản' AS TEN_DON_VI_CHU_QUAN,
            -1 AS STT_DON_VI
           FROM DUAL
       ORDER BY STT_DON_VI,TEN_DON_VI_CHU_QUAN;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_PHUONGXA_nothing(P_CUR IN OUT MYCUR, P_MA_QUAN_HUYEN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_PHUONG_XA,
             A.TEN_PHUONG_XA
        FROM DM_PHUONG_XA A
        WHERE A.MA_QUAN_HUYEN=P_MA_QUAN_HUYEN
       ORDER BY A.STT_PHUONG_XA,A.TEN_PHUONG_XA;
  END;
 -------------------------------------------------------------------------------
  PROCEDURE SELECT_PHUONGXA_NULL(P_CUR IN OUT MYCUR, P_MA_QUAN_HUYEN NVARCHAR2) AS
 V_KT INT;
  V_MA_QUAN_HUYEN NVARCHAR2(100);
  BEGIN
        SELECT COUNT(1) INTO V_KT FROM DM_QUAN_HUYEN C 
    WHERE  C.MA_QUAN_HUYEN=P_MA_QUAN_HUYEN;
    IF V_KT=0 THEN
      V_MA_QUAN_HUYEN:='';
     ELSE
      V_MA_QUAN_HUYEN:=P_MA_QUAN_HUYEN;
    END IF;
    IF V_MA_QUAN_HUYEN IS NOT NULL THEN

    OPEN P_CUR FOR
      SELECT A.MA_PHUONG_XA,
             A.TEN_PHUONG_XA
        FROM DM_PHUONG_XA A
        WHERE A.MA_QUAN_HUYEN=P_MA_QUAN_HUYEN
       ORDER BY A.STT_PHUONG_XA,A.TEN_PHUONG_XA;
       ELSE
           OPEN P_CUR FOR
      SELECT A.MA_PHUONG_XA,
             A.TEN_PHUONG_XA
        FROM DM_PHUONG_XA A
        WHERE A.MA_QUAN_HUYEN IN (SELECT E.MA_QUAN_HUYEN FROM DM_QUAN_HUYEN E WHERE ROWNUM=1 )
       ORDER BY A.STT_PHUONG_XA,A.TEN_PHUONG_XA;
       END IF;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_PHUONGXA_tatca(P_CUR IN OUT MYCUR, P_MA_QUAN_HUYEN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_PHUONG_XA,
             A.TEN_PHUONG_XA,
             A.STT_PHUONG_XA
        FROM DM_PHUONG_XA A
        WHERE A.MA_QUAN_HUYEN=P_MA_QUAN_HUYEN
      UNION 
      SELECT N'' AS MA_PHUONG_XA,
            N'Tất cả' AS TEN_PHUONG_XA,
            -1 AS STT_DON_VI
           FROM DUAL
       ORDER BY STT_PHUONG_XA,TEN_PHUONG_XA;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_PHUONGXA_chon(P_CUR IN OUT MYCUR, P_MA_QUAN_HUYEN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_PHUONG_XA,
             A.TEN_PHUONG_XA,
             A.STT_PHUONG_XA
        FROM DM_PHUONG_XA A
        WHERE A.MA_QUAN_HUYEN=P_MA_QUAN_HUYEN
      UNION 
      SELECT N'' AS MA_PHUONG_XA,
            N'Chọn phường xã' AS TEN_PHUONG_XA,
            -1 AS STT_DON_VI
           FROM DUAL
       ORDER BY STT_PHUONG_XA,TEN_PHUONG_XA;
  END;  
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAIDONVI_nothing(P_CUR IN OUT MYCUR, P_MA_LOAI_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LOAI_DON_VI,
             A.TEN_LOAI_DON_VI
        FROM CB_LOAI_DON_VI A
        WHERE A.MA_LOAI_CO_QUAN=P_MA_LOAI_CO_QUAN
       ORDER BY A.TEN_LOAI_DON_VI;
  END;
     -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAIDONVI_nothing_cuacq(P_CUR IN OUT MYCUR, P_MA_LOAI_CO_QUAN NVARCHAR2, P_MA_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT DISTINCT A.MA_LOAI_DON_VI,
             A.TEN_LOAI_DON_VI,
             100 AS STT_LOAI_DON_VI
        FROM CB_LOAI_DON_VI A, CB_DON_VI B
        WHERE A.MA_LOAI_CO_QUAN=P_MA_LOAI_CO_QUAN
        AND A.MA_LOAI_DON_VI = B.MA_LOAI_DON_VI
        AND B.MA_CO_QUAN=P_MA_CO_QUAN
       ORDER BY STT_LOAI_DON_VI,TEN_LOAI_DON_VI;
  END;
    -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAIDONVI_tatca(P_CUR IN OUT MYCUR, P_MA_LOAI_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LOAI_DON_VI,
             A.TEN_LOAI_DON_VI,
             100 AS STT_LOAI_DON_VI
        FROM CB_LOAI_DON_VI A
        WHERE A.MA_LOAI_CO_QUAN=P_MA_LOAI_CO_QUAN
      UNION 
      SELECT N'' AS MA_LOAI_DON_VI,
            N'Tất cả' AS TEN_LOAI_DON_VI,
            -1 AS STT_LOAI_DON_VI
           FROM DUAL
       ORDER BY STT_LOAI_DON_VI,TEN_LOAI_DON_VI;
  END;
    -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAIDONVI_tatca_cuacq(P_CUR IN OUT MYCUR, P_MA_LOAI_CO_QUAN NVARCHAR2, P_MA_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LOAI_DON_VI,
             A.TEN_LOAI_DON_VI,
             100 AS STT_LOAI_DON_VI
        FROM CB_LOAI_DON_VI A, CB_DON_VI B
        WHERE A.MA_LOAI_CO_QUAN=P_MA_LOAI_CO_QUAN
        AND A.MA_LOAI_DON_VI = B.MA_LOAI_DON_VI
        AND B.MA_CO_QUAN=P_MA_CO_QUAN
      UNION 
      SELECT N'' AS MA_LOAI_DON_VI,
            N'Tất cả' AS TEN_LOAI_DON_VI,
            -1 AS STT_LOAI_DON_VI
           FROM DUAL
       ORDER BY STT_LOAI_DON_VI,TEN_LOAI_DON_VI;
  END;

 
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAIDONVI_chon(P_CUR IN OUT MYCUR, P_MA_LOAI_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LOAI_DON_VI,
             A.TEN_LOAI_DON_VI,
             100 AS STT_LOAI_DON_VI
        FROM CB_LOAI_DON_VI A
        WHERE A.MA_LOAI_CO_QUAN=P_MA_LOAI_CO_QUAN
      UNION 
      SELECT N'' AS MA_LOAI_DON_VI,
            N'Chọn loại đơn vị' AS TEN_LOAI_DON_VI,
            -1 AS STT_LOAI_DON_VI
           FROM DUAL
       ORDER BY STT_LOAI_DON_VI,TEN_LOAI_DON_VI;
  END;
     -------------------------------------------------------------------------------
   PROCEDURE SELECT_LOAIDONVI_chon_cuacq(P_CUR IN OUT MYCUR, P_MA_LOAI_CO_QUAN NVARCHAR2, P_MA_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT DISTINCT A.MA_LOAI_DON_VI,
             A.TEN_LOAI_DON_VI,
             100 AS STT_LOAI_DON_VI
        FROM CB_LOAI_DON_VI A, CB_DON_VI B
        WHERE A.MA_LOAI_CO_QUAN=P_MA_LOAI_CO_QUAN
        AND A.MA_LOAI_DON_VI = B.MA_LOAI_DON_VI
        AND B.MA_CO_QUAN=P_MA_CO_QUAN
       UNION 
      SELECT N'' AS MA_LINH_VUC_THU_TUC,
             N'Chọn loại đơn vị' AS TEN_LINH_VUC_THU_TUC,
             -1 AS STT_LOAI_DON_VI
      FROM DUAL 
       ORDER BY STT_LOAI_DON_VI,TEN_LOAI_DON_VI;
  END; 
 
 -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAINHOMNSD_nothing(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LOAI_NHOM_NSD,
             A.TEN_LOAI_NHOM_NSD
        FROM CB_LOAI_NHOM_NSD A
       ORDER BY A.STT_LOAI_NHOM_NSD,A.TEN_LOAI_NHOM_NSD;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAINHOMNSD_tatca(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LOAI_NHOM_NSD,
             A.TEN_LOAI_NHOM_NSD,
             A.STT_LOAI_NHOM_NSD
        FROM CB_LOAI_NHOM_NSD A
      UNION 
      SELECT N'' AS MA_LOAI_NHOM_NSD,
            N'Tất cả' AS TEN_LOAI_NHOM_NSD,
            -1 AS STT_LOAI_NHOM_NSD
           FROM DUAL
       ORDER BY STT_LOAI_NHOM_NSD,TEN_LOAI_NHOM_NSD;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAINHOMNSD_chon(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LOAI_NHOM_NSD,
             A.TEN_LOAI_NHOM_NSD,
             A.STT_LOAI_NHOM_NSD
        FROM CB_LOAI_NHOM_NSD A
      UNION 
      SELECT N'' AS MA_LOAI_NHOM_NSD,
            N'Chọn nhóm NSD' AS TEN_LOAI_NHOM_NSD,
            -1 AS STT_LOAI_NHOM_NSD
           FROM DUAL
       ORDER BY STT_LOAI_NHOM_NSD,TEN_LOAI_NHOM_NSD;
  END;
  -------------------------------------------------------------------------------
  --khong the su dung ham nay khi P_MA_TO_CHUYEN_MON=0
  PROCEDURE SELECT_LOAINHOMNSD_CBX_BY_MDV(P_CUR IN OUT MYCUR,P_MA_TO_CHUYEN_MON INT,P_MA_DON_VI NVARCHAR2) AS
  V_MA_LOAI_DON_VI NVARCHAR2(100);
  V_MA_LOAI_NHOM_NSD NVARCHAR2(100);
  BEGIN
   SELECT MA_LOAI_DON_VI INTO V_MA_LOAI_DON_VI FROM CB_DON_VI WHERE MA_DON_VI LIKE P_MA_DON_VI;
   
   IF P_MA_TO_CHUYEN_MON =0 THEN
     
      OPEN P_CUR FOR
      SELECT A.MA_LOAI_NHOM_NSD,
             A.TEN_LOAI_NHOM_NSD,
             A.STT_LOAI_NHOM_NSD,
             0 AS SELECTED
        FROM CB_LOAI_NHOM_NSD A
        WHERE UPPER('%'||NVL(A.MA_LOAI_DON_VI,'')||'%')=UPPER('%'||NVL(V_MA_LOAI_DON_VI,'')||'%')
       ORDER BY STT_LOAI_NHOM_NSD,TEN_LOAI_NHOM_NSD;
   
   
    ELSE
    SELECT MA_LOAI_NHOM_NSD INTO V_MA_LOAI_NHOM_NSD FROM CB_TO_CHUYEN_MON WHERE MA_TO_CHUYEN_MON = P_MA_TO_CHUYEN_MON;  
    OPEN P_CUR FOR
      SELECT DISTINCT A.MA_LOAI_NHOM_NSD,
             A.TEN_LOAI_NHOM_NSD,
             A.STT_LOAI_NHOM_NSD,
             CASE WHEN B.MA_LOAI_NHOM_NSD LIKE V_MA_LOAI_NHOM_NSD THEN 1 ELSE 0 END AS SELECTED
        FROM CB_LOAI_NHOM_NSD A, CB_TO_CHUYEN_MON B
        WHERE UPPER('%'||NVL(A.MA_LOAI_DON_VI,'')||'%')=UPPER('%'||NVL(V_MA_LOAI_DON_VI,'')||'%')
        AND A.MA_LOAI_NHOM_NSD=B.MA_LOAI_NHOM_NSD(+)
       ORDER BY STT_LOAI_NHOM_NSD,TEN_LOAI_NHOM_NSD;
   
    END IF;   
  END;  
  -------------------------------------------------------------------------------
  --khong the su dung ham nay khi P_MA_TO_CHUYEN_MON=0
  PROCEDURE SELECT_LOAINHOMNSD_CBX_BY_MT(P_CUR IN OUT MYCUR,P_MA_TO_CHUYEN_MON INT) AS
  V_MA_LOAI_DON_VI NVARCHAR2(100);
  V_MA_LOAI_NHOM_NSD NVARCHAR2(100);
  V_MA_DON_VI NVARCHAR2(100);
  BEGIN
   SELECT MA_DON_VI INTO V_MA_DON_VI FROM CB_TO_CHUYEN_MON WHERE MA_TO_CHUYEN_MON LIKE P_MA_TO_CHUYEN_MON;
   SELECT MA_LOAI_DON_VI INTO V_MA_LOAI_DON_VI FROM CB_DON_VI WHERE MA_DON_VI LIKE V_MA_DON_VI;
   IF P_MA_TO_CHUYEN_MON =0 THEN
      OPEN P_CUR FOR
      SELECT A.MA_LOAI_NHOM_NSD,
             A.TEN_LOAI_NHOM_NSD,
             A.STT_LOAI_NHOM_NSD,
             0 AS SELECTED
        FROM CB_LOAI_NHOM_NSD A
        WHERE UPPER('%'||NVL(A.MA_LOAI_DON_VI,'')||'%')=UPPER('%'||NVL(V_MA_LOAI_DON_VI,'')||'%')
       ORDER BY STT_LOAI_NHOM_NSD,TEN_LOAI_NHOM_NSD;
   
    ELSE
    SELECT MA_LOAI_NHOM_NSD INTO V_MA_LOAI_NHOM_NSD FROM CB_TO_CHUYEN_MON WHERE MA_TO_CHUYEN_MON = P_MA_TO_CHUYEN_MON;  
    OPEN P_CUR FOR
      SELECT DISTINCT A.MA_LOAI_NHOM_NSD,
             A.TEN_LOAI_NHOM_NSD,
             A.STT_LOAI_NHOM_NSD,
             CASE WHEN B.MA_LOAI_NHOM_NSD LIKE V_MA_LOAI_NHOM_NSD THEN 1 ELSE 0 END AS SELECTED
        FROM CB_LOAI_NHOM_NSD A, CB_TO_CHUYEN_MON B
        WHERE UPPER('%'||NVL(A.MA_LOAI_DON_VI,'')||'%')=UPPER('%'||NVL(V_MA_LOAI_DON_VI,'')||'%')
        AND A.MA_LOAI_NHOM_NSD=B.MA_LOAI_NHOM_NSD(+)
       ORDER BY STT_LOAI_NHOM_NSD,TEN_LOAI_NHOM_NSD;
   
    END IF;   
  END;  
    -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAINHOMNSD_BY_MLDV(P_CUR IN OUT MYCUR,P_MA_LOAI_DON_VI NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LOAI_NHOM_NSD,
             A.TEN_LOAI_NHOM_NSD
        FROM CB_LOAI_NHOM_NSD A
        WHERE A.MA_LOAI_DON_VI LIKE P_MA_LOAI_DON_VI
       ORDER BY A.STT_LOAI_NHOM_NSD,A.TEN_LOAI_NHOM_NSD;
  END;
    -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAINHOMNSD_BY_MLDVchon(P_CUR IN OUT MYCUR,P_MA_LOAI_DON_VI NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LOAI_NHOM_NSD,
             A.TEN_LOAI_NHOM_NSD,
             A.STT_LOAI_NHOM_NSD
        FROM CB_LOAI_NHOM_NSD A
        WHERE A.MA_LOAI_DON_VI LIKE P_MA_LOAI_DON_VI
      UNION 
      SELECT N'' AS MA_LOAI_NHOM_NSD,
            N'Chọn bộ phận xác nhận' AS TEN_LOAI_NHOM_NSD,
            -1 AS STT_LOAI_NHOM_NSD
           FROM DUAL
       ORDER BY STT_LOAI_NHOM_NSD,TEN_LOAI_NHOM_NSD;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_MENU_nothing(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_MENU,
             A.TEN_MENU
        FROM PQ_MENU A
       ORDER BY A.STT_MENU,A.TEN_MENU;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_MENU_tatca(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_MENU,
             A.TEN_MENU,
             A.STT_MENU
        FROM PQ_MENU A
      UNION 
      SELECT N'' AS MA_MENU,
            N'Tất cả' AS TEN_MENU,
            -1 AS STT_MENU
           FROM DUAL
       ORDER BY STT_MENU,TEN_MENU;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_MENU_chon(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_MENU,
             A.TEN_MENU,
             A.STT_MENU
        FROM PQ_MENU A
      UNION 
      SELECT N'' AS MA_MENU,
            N'Chọn menu' AS TEN_MENU,
            -1 AS STT_MENU
           FROM DUAL
       ORDER BY STT_MENU,TEN_MENU;
  END; 
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUYEN_nothing(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_QUYEN,
             A.TEN_QUYEN
        FROM PQ_QUYEN A
       ORDER BY A.STT_QUYEN,A.TEN_QUYEN;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUYEN_tatca(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_QUYEN,
             A.TEN_QUYEN,
             A.STT_QUYEN
        FROM PQ_QUYEN A
      UNION 
      SELECT N'' AS MA_QUYEN,
            N'Tất cả' AS TEN_QUYEN,
            -1 AS STT_QUYEN
           FROM DUAL
       ORDER BY STT_QUYEN,TEN_QUYEN;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUYEN_chon(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_QUYEN,
             A.TEN_QUYEN,
             A.STT_QUYEN
        FROM PQ_QUYEN A
      UNION 
      SELECT N'' AS MA_QUYEN,
            N'Chọn quyền' AS TEN_QUYEN,
            -1 AS STT_QUYEN
           FROM DUAL
       ORDER BY STT_QUYEN,TEN_QUYEN;
  END;   

-------------------------------------------------------------------------------
  PROCEDURE SELECT_CHUCVU_nothing(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_CHUC_VU,
             A.TEN_CHUC_VU
        FROM DM_CHUC_VU A
       ORDER BY A.STT_CHUC_VU,A.TEN_CHUC_VU;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_CHUCVU_tatca(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_CHUC_VU,
             A.TEN_CHUC_VU,
             A.STT_CHUC_VU
        FROM DM_CHUC_VU A
      UNION 
      SELECT N'' AS MA_CHUC_VU,
            N'Tất cả' AS TEN_CHUC_VU,
            -1 AS STT_CHUC_VU
           FROM DUAL
       ORDER BY STT_CHUC_VU,TEN_CHUC_VU;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_CHUCVU_chon(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_CHUC_VU,
             A.TEN_CHUC_VU,
             A.STT_CHUC_VU
        FROM DM_CHUC_VU A
      UNION 
      SELECT N'' AS MA_CHUC_VU,
            N'Chọn chức vụ' AS TEN_CHUC_VU,
            -1 AS STT_CHUC_VU
           FROM DUAL
       ORDER BY STT_CHUC_VU,TEN_CHUC_VU;
  END;
-------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAICOQUAN_nothing(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LOAI_CO_QUAN,
             A.TEN_LOAI_CO_QUAN
        FROM CB_LOAI_CO_QUAN A
       ORDER BY A.STT_LOAI_CO_QUAN,A.TEN_LOAI_CO_QUAN;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAICOQUAN_tatca(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LOAI_CO_QUAN,
             A.TEN_LOAI_CO_QUAN,
             A.STT_LOAI_CO_QUAN
        FROM CB_LOAI_CO_QUAN A
      UNION 
      SELECT N'' AS MA_LOAI_CO_QUAN,
            N'Tất cả' AS TEN_LOAI_CO_QUAN,
            -1 AS STT_LOAI_CO_QUAN
           FROM DUAL
       ORDER BY STT_LOAI_CO_QUAN,TEN_LOAI_CO_QUAN;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_LOAICOQUAN_chon(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_LOAI_CO_QUAN,
             A.TEN_LOAI_CO_QUAN,
             A.STT_LOAI_CO_QUAN
        FROM CB_LOAI_CO_QUAN A
      UNION 
      SELECT N'' AS MA_LOAI_CO_QUAN,
            N'Chọn loại cơ quan' AS TEN_LOAI_CO_QUAN,
            -1 AS STT_LOAI_CO_QUAN
           FROM DUAL
       ORDER BY STT_LOAI_CO_QUAN,TEN_LOAI_CO_QUAN;
  END; 
  ---------------------------------------------
  PROCEDURE SELECT_UBND_HUYEN(P_CUR IN OUT MYCUR) AS
    BEGIN 
      OPEN P_CUR FOR
      SELECT A.MA_CO_QUAN,
      A.TEN_CO_QUAN,A.STT_CO_QUAN
      FROM CB_CO_QUAN A
      WHERE A.MA_LOAI_CO_QUAN='UBND_HUYEN'
      ORDER BY A.STT_CO_QUAN,A.TEN_CO_QUAN;
    END;
-------------------------------------------------------------------------------
  PROCEDURE SELECT_COQUAN_nothing(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_CO_QUAN,
             A.TEN_CO_QUAN
        FROM CB_CO_QUAN A
       ORDER BY A.TEN_CO_QUAN;
  END;
-------------------------------------------------------------------------------
  PROCEDURE SELECT_COQUAN_nothing_desc(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_CO_QUAN,
             A.TEN_CO_QUAN
        FROM CB_CO_QUAN A
       ORDER BY A.TEN_CO_QUAN DESC;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_COQUAN_tatca(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_CO_QUAN,
             A.TEN_CO_QUAN,
             A.STT_CO_QUAN
        FROM CB_CO_QUAN A
      UNION 
      SELECT N'' AS MA_CO_QUAN,
            N'Tất cả' AS TEN_CO_QUAN,
            -1 AS STT_CO_QUAN
           FROM DUAL
       ORDER BY STT_CO_QUAN,TEN_CO_QUAN;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_COQUAN_chon(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_CO_QUAN,
             A.TEN_CO_QUAN,
             A.STT_CO_QUAN
        FROM CB_CO_QUAN A
      UNION 
      SELECT N'' AS MA_CO_QUAN,
            N'Chọn cơ quan' AS TEN_CO_QUAN,
            -1 AS STT_CO_QUAN
           FROM DUAL
       ORDER BY STT_CO_QUAN,TEN_CO_QUAN;
  END;        
-------------------------------------------------------------------------------
  PROCEDURE SELECT_COQUAN_BY_LCQ_nothing(P_CUR IN OUT MYCUR,P_MA_LOAI_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_CO_QUAN,
             A.TEN_CO_QUAN
        FROM CB_CO_QUAN A WHERE A.MA_LOAI_CO_QUAN=P_MA_LOAI_CO_QUAN
       ORDER BY A.STT_CO_QUAN,A.TEN_CO_QUAN;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_COQUAN_BY_LCQ_tatca(P_CUR IN OUT MYCUR,P_MA_LOAI_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_CO_QUAN,
             A.TEN_CO_QUAN,
             A.STT_CO_QUAN
        FROM CB_CO_QUAN A WHERE A.MA_LOAI_CO_QUAN=P_MA_LOAI_CO_QUAN
      UNION 
      SELECT N'' AS MA_CO_QUAN,
            N'Tất cả' AS TEN_CO_QUAN,
            -1 AS STT_CO_QUAN
           FROM DUAL
       ORDER BY STT_CO_QUAN,TEN_CO_QUAN;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_COQUAN_BY_LCQ_chon(P_CUR IN OUT MYCUR,P_MA_LOAI_CO_QUAN NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_CO_QUAN,
             A.TEN_CO_QUAN,
             A.STT_CO_QUAN
        FROM CB_CO_QUAN A WHERE A.MA_LOAI_CO_QUAN=P_MA_LOAI_CO_QUAN
      UNION 
      SELECT N'' AS MA_CO_QUAN,
            N'Chọn cơ quan' AS TEN_CO_QUAN,
            -1 AS STT_CO_QUAN
           FROM DUAL
       ORDER BY STT_CO_QUAN,TEN_CO_QUAN;
  END;        

  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUANHUYEN_nothing(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_QUAN_HUYEN,
             A.TEN_QUAN_HUYEN
        FROM DM_QUAN_HUYEN A
       ORDER BY A.STT_QUAN_HUYEN,A.TEN_QUAN_HUYEN;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUANHUYEN_tatca(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_QUAN_HUYEN,
             A.TEN_QUAN_HUYEN,
             A.STT_QUAN_HUYEN
        FROM DM_QUAN_HUYEN A
      UNION 
      SELECT N'' AS MA_QUAN_HUYEN,
            N'Tất cả' AS TEN_QUAN_HUYEN,
            -1 AS STT_QUAN_HUYEN
           FROM DUAL
       ORDER BY STT_QUAN_HUYEN,TEN_QUAN_HUYEN;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUANHUYEN_chon(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_QUAN_HUYEN,
             A.TEN_QUAN_HUYEN,
             A.STT_QUAN_HUYEN
        FROM DM_QUAN_HUYEN A
      UNION 
      SELECT N'' AS MA_QUAN_HUYEN,
            N'Chọn quận huyện' AS TEN_QUAN_HUYEN,
            -1 AS STT_QUAN_HUYEN
           FROM DUAL
       ORDER BY STT_QUAN_HUYEN,TEN_QUAN_HUYEN;
  END;
PROCEDURE SELECT_QUANHUYEN_Select(P_CUR IN OUT MYCUR, P_MA_TINH_THANH NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_QUAN_HUYEN,
             A.TEN_QUAN_HUYEN,
             A.STT_QUAN_HUYEN
        FROM DM_QUAN_HUYEN A
        WHERE  A.MA_TINH_THANH=P_MA_TINH_THANH
      UNION 
      SELECT N'' AS MA_QUAN_HUYEN,
            N'Tất cả' AS TEN_QUAN_HUYEN,
            -1 AS STT_QUAN_HUYEN
           FROM DUAL
       ORDER BY STT_QUAN_HUYEN,TEN_QUAN_HUYEN;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUANHUYEN_tinh(P_CUR IN OUT MYCUR, P_MA_TINH_THANH NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_QUAN_HUYEN,
             A.TEN_QUAN_HUYEN
        FROM DM_QUAN_HUYEN A
        WHERE A.MA_TINH_THANH=P_MA_TINH_THANH;
       --ORDER BY A.STT_QUAN_HUYEN,A.TEN_QUAN_HUYEN;
  END; 
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_QUANHUYEN_ORDER(P_CUR IN OUT MYCUR, P_MA_TINH_THANH NVARCHAR2) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_QUAN_HUYEN,
             A.TEN_QUAN_HUYEN
        FROM DM_QUAN_HUYEN A
        WHERE A.MA_TINH_THANH=P_MA_TINH_THANH
      ORDER BY MA_QUAN_HUYEN;
  END; 
   -------------------------------------------------------------------------------
  PROCEDURE SELECT_TINHTHANH_nothing(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_TINH_THANH,
             A.TEN_TINH_THANH
        FROM DM_TINH_THANH A
       ORDER BY A.TEN_TINH_THANH;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_TINHTHANH_tatca(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_TINH_THANH,
             A.TEN_TINH_THANH,
             A.STT_TINH_THANH
        FROM DM_TINH_THANH A
      UNION 
      SELECT N'' AS MA_TINH_THANH,
            N'Tất cả' AS TEN_TINH_THANH,
            -1 AS STT_TINH_THANH
           FROM DUAL
       ORDER BY TEN_TINH_THANH;
  END;
  -------------------------------------------------------------------------------
  PROCEDURE SELECT_TINHTHANH_chon(P_CUR IN OUT MYCUR) AS
  BEGIN
    OPEN P_CUR FOR
      SELECT A.MA_TINH_THANH,
             A.TEN_TINH_THANH,
             A.STT_TINH_THANH
        FROM DM_TINH_THANH A
      UNION 
      SELECT N'' AS MA_TINH_THANH,
            N'Chọn tỉnh thành' AS TEN_TINH_THANH,
            -1 AS STT_TINH_THANH
           FROM DUAL
       ORDER BY TEN_TINH_THANH;
  END;

  END LIB_DM;
/

prompt
prompt Creating package body LIB_FUN
prompt =============================
prompt
CREATE OR REPLACE PACKAGE BODY HAI.LIB_FUN IS
 
   -------------------------------------------------------------------------------
  FUNCTION GET_SO_LUONG_CBHT_CUA_DV(P_MA_DON_VI NVARCHAR2) RETURN INT 
  AS RS INT;
  
  BEGIN
    SELECT COUNT(1) INTO RS FROM CB_TO_CHUYEN_MON B, 
                                 CB_THUOC_TO_CHUYEN_MON C
                           WHERE B.MA_DON_VI = P_MA_DON_VI
                           AND B.MA_TO_CHUYEN_MON=C.MA_TO_CHUYEN_MON
                           AND C.DEN_NGAY IS NULL;
    RETURN RS;
  END; 
     -------------------------------------------------------------------------------
  FUNCTION GET_SO_LUONG_TO_CUA_DV(P_MA_DON_VI NVARCHAR2) RETURN INT 
  AS RS INT;
  
  BEGIN
    SELECT COUNT(DISTINCT B.MA_TO_CHUYEN_MON) INTO RS FROM CB_TO_CHUYEN_MON B, 
                                 CB_THUOC_TO_CHUYEN_MON C
                           WHERE B.MA_DON_VI = P_MA_DON_VI
                           AND B.MA_TO_CHUYEN_MON=C.MA_TO_CHUYEN_MON
                           AND C.DEN_NGAY IS NULL;
    RETURN RS;
  END; 
    -------------------------------------------------------------------------------
  FUNCTION GET_SO_LUONG_CBHT_CUA_TO(P_MA_TO_CHUYEN_MON INT) RETURN INT 
  AS RS INT;
  BEGIN
    SELECT COUNT(1) INTO RS FROM CB_THUOC_TO_CHUYEN_MON A
                           WHERE A.MA_TO_CHUYEN_MON = P_MA_TO_CHUYEN_MON
                           AND A.DEN_NGAY IS NULL;
    RETURN RS;
  END; 

  END LIB_FUN;
/

prompt
prompt Creating package body LIB_NOTABLE
prompt =================================
prompt
