oracle xmltype导入并解析Excel数据 (一)创建表与序

时间:2023-03-08 23:28:20
oracle xmltype导入并解析Excel数据 (一)创建表与序

表说明:

T_EXCEL_IMPORT_DATASRC: Excel数据存储表,(使用了xmltype存储Excel数据)

部分字段说明:

BUSINESSTYPE: Excel模板类型,一个Excel一个模板类型(非空)

EXPANDTYPE: 拓展类型,用于存储一些有用的业务数据,比如组织organ,用于等等.组织通常用来过滤展示数据的

XMLDATA: Excel数据

BUSINESSTYPE_sheet: 某一个Excel文件的第几个Sheet

T_EXCEL_IMPORT_GENERATION: 中间表,解析xmltype后的Excel数据

T_EXCEL_IMPORT_RULES: 规则表,即模板的规则

T_EXCEL_IMPORT_MAPCOLUMN: 字段映射表,Excel某一列对应的是某一Excel数据.比如: Cell1对应名称,Cell2对应性别

T_EXCEL_IMPORT_LOG: 日志记录表,操作错误日志记录表


序的创建:

-- Create sequence --错误日志主键序
create sequence SEQ_EXCEL_LOG
minvalue 1
maxvalue 999999999999999999999999999
start with 61
increment by 1
cache 20;

-- Create sequence --Excel数据序
create sequence SEQ_EXCEL_IMPROT
minvalue 1
maxvalue 9999999999999999999999999999
start with 157981
increment by 1
cache 20;


表的创建

-- Create table
create table T_EXCEL_IMPORT_DATASRC
(
id NUMBER not null,
businesstype VARCHAR2(20) not null,
expandtype VARCHAR2(20),
xmldata XMLTYPE
)
tablespace USERS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64
minextents 1
maxextents unlimited
);
-- Add comments to the table
comment on table T_EXCEL_IMPORT_DATASRC
is 'excel导入数据业务表';
-- Add comments to the columns
comment on column T_EXCEL_IMPORT_DATASRC.id
is '主键';
comment on column T_EXCEL_IMPORT_DATASRC.businesstype
is '业务类型(不同Excel模板使用不同业务类型)';
comment on column T_EXCEL_IMPORT_DATASRC.expandtype
is '拓展类型';
comment on column T_EXCEL_IMPORT_DATASRC.xmldata
is 'Excel转换的xml数据';
-- Create/Recreate primary, unique and foreign key constraints
alter table T_EXCEL_IMPORT_DATASRC
add constraint PRI_EXCEL_IMPORT_DATASRC primary key (ID)
using index
tablespace USERS
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);

-- Create table
create table T_EXCEL_IMPORT_GENERATION
(
id NUMBER not null,
businessid NUMBER not null,
businesstype VARCHAR2(20) not null,
expandtype VARCHAR2(20),
errormsg VARCHAR2(500),
ucn VARCHAR2(500),
cell1 VARCHAR2(4000),
cell2 VARCHAR2(4000),
cell3 VARCHAR2(4000),
cell4 VARCHAR2(4000),
cell5 VARCHAR2(4000),
cell6 VARCHAR2(4000),
cell7 VARCHAR2(4000),
cell8 VARCHAR2(4000),
cell9 VARCHAR2(4000),
cell10 VARCHAR2(4000),
cell11 VARCHAR2(4000),
cell12 VARCHAR2(4000),
cell13 VARCHAR2(4000),
cell14 VARCHAR2(4000),
cell15 VARCHAR2(4000),
cell16 VARCHAR2(4000),
cell17 VARCHAR2(4000),
cell18 VARCHAR2(4000),
cell19 VARCHAR2(4000),
cell20 VARCHAR2(4000),
cell21 VARCHAR2(4000),
cell22 VARCHAR2(4000),
cell23 VARCHAR2(4000),
cell24 VARCHAR2(4000),
cell25 VARCHAR2(4000)
)
tablespace USERS
pctfree 5
initrans 1
maxtrans 255
storage
(
initial 16
minextents 1
maxextents unlimited
);
-- Add comments to the table
comment on table T_EXCEL_IMPORT_GENERATION
is 'T_EXCEL_IMPORT_DATASRC生成的解析数据表';
-- Add comments to the columns
comment on column T_EXCEL_IMPORT_GENERATION.businessid
is '业务ID';
comment on column T_EXCEL_IMPORT_GENERATION.businesstype
is '数据类型=[业务类型+Sheet]';
comment on column T_EXCEL_IMPORT_GENERATION.expandtype
is '拓展类型';
comment on column T_EXCEL_IMPORT_GENERATION.errormsg
is '错误信息';
comment on column T_EXCEL_IMPORT_GENERATION.ucn
is '不同业务不同使用';
comment on column T_EXCEL_IMPORT_GENERATION.cell1
is 'Excel对应的列';
-- Create/Recreate indexes
create index INDEX_EXCEL_IMPORT_GENERA_1 on T_EXCEL_IMPORT_GENERATION (BUSINESSID)
tablespace USERS
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
-- Create/Recreate primary, unique and foreign key constraints
alter table T_EXCEL_IMPORT_GENERATION
add constraint PRI_EXCEL_IMPORT_GENERATION primary key (ID)
using index
tablespace USERS
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);

-- Create table
create table T_EXCEL_IMPORT_RULES
(
id NUMBER not null,
businesstype_sheet VARCHAR2(20) not null,
columnname VARCHAR2(20) not null,
columnenname VARCHAR2(20),
rule_empty VARCHAR2(1),
rule_range VARCHAR2(50),
rule_datetime VARCHAR2(1),
rule_date_customize VARCHAR2(20),
rule_unique VARCHAR2(1),
rule_phone VARCHAR2(1),
rule_number VARCHAR2(1),
rule_func_customize VARCHAR2(30),
rule_func_customize_msg VARCHAR2(200),
rule_idcard VARCHAR2(1),
procedure_name VARCHAR2(100)
)
tablespace USERS
pctfree 5
initrans 1
maxtrans 255
storage
(
initial 16
minextents 1
maxextents unlimited
);
-- Add comments to the table
comment on table T_EXCEL_IMPORT_RULES
is 'Excel导入合法校验规则';
-- Add comments to the columns
comment on column T_EXCEL_IMPORT_RULES.businesstype_sheet
is '数据类型,(=业务类型+ _Sheet数)';
comment on column T_EXCEL_IMPORT_RULES.columnname
is 'Excel模板的列名';
comment on column T_EXCEL_IMPORT_RULES.columnenname
is '列名';
comment on column T_EXCEL_IMPORT_RULES.rule_empty
is '非空判断,1:非空,其余可空';
comment on column T_EXCEL_IMPORT_RULES.rule_range
is '大于另一列的值,格式:>=Excel中文标题名 或 >Excel中文标题名';
comment on column T_EXCEL_IMPORT_RULES.rule_datetime
is '日期/时间格式,1:日期或时间';
comment on column T_EXCEL_IMPORT_RULES.rule_date_customize
is '日期/时间格式, 用户自定义日期格式,如YYYY-MM或YYYY';
comment on column T_EXCEL_IMPORT_RULES.rule_unique
is '字段唯一,(如果有多个列唯一,表示这些列联合确定数据),唯一用来更新数据';
comment on column T_EXCEL_IMPORT_RULES.rule_phone
is '号码格式,1:手机号码,2:固话,3:手机或固话';
comment on column T_EXCEL_IMPORT_RULES.rule_number
is '数字格式:1:整数,2:整数或小数';
comment on column T_EXCEL_IMPORT_RULES.rule_func_customize
is '自定义函数名 (返回值1则表示合法),需要配合RULE_FUNC_CUSTOMIZE_MSG使用';
comment on column T_EXCEL_IMPORT_RULES.rule_func_customize_msg
is '自定义函数名校验不合格提示信息';
comment on column T_EXCEL_IMPORT_RULES.rule_idcard
is '身份证号码,1:合法身份证';
comment on column T_EXCEL_IMPORT_RULES.procedure_name
is '插入业务表数据的存储过程名字(至少得有一个值,多个值也可以,但是只会随机取一条数据)';
-- Create/Recreate primary, unique and foreign key constraints
alter table T_EXCEL_IMPORT_RULES
add constraint PRI_EXCEL_IMPORT_RULES primary key (ID)
using index
tablespace USERS
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
alter table T_EXCEL_IMPORT_RULES
add constraint UNI_EXCEL_IMPORT_RULES_1 unique (BUSINESSTYPE_SHEET, COLUMNNAME)
using index
tablespace USERS
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);

-- Create table
create table T_EXCEL_IMPORT_MAPCOLUMN
(
id NUMBER(10),
businesstype_sheet VARCHAR2(20),
columnenname VARCHAR2(20),
columncnname VARCHAR2(20)
)
tablespace USERS
pctfree 5
initrans 1
maxtrans 255
storage
(
initial 16
minextents 1
maxextents unlimited
);
-- Add comments to the table
comment on table T_EXCEL_IMPORT_MAPCOLUMN
is 'Excel导入表头中文名对应的字段名';
-- Add comments to the columns
comment on column T_EXCEL_IMPORT_MAPCOLUMN.businesstype_sheet
is '规则类型 (业务类型+sheet数 合成的sheet规则类型)';
comment on column T_EXCEL_IMPORT_MAPCOLUMN.columnenname
is 'Excel表头字段对应的列名';
comment on column T_EXCEL_IMPORT_MAPCOLUMN.columncnname
is 'Excel表头字段中文名';

-- Create table
create table T_EXCEL_IMPORT_LOG
(
id NUMBER,
businessid NUMBER,
errorcode VARCHAR2(50),
errormsg VARCHAR2(1000),
errortype VARCHAR2(50),
line_no VARCHAR2(1000),
logdate DATE default sysdate
)
tablespace USERS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64
minextents 1
maxextents unlimited
);
-- Add comments to the table
comment on table T_EXCEL_IMPORT_LOG
is '日志记录表';
-- Add comments to the columns
comment on column T_EXCEL_IMPORT_LOG.businessid
is '业务ID';
comment on column T_EXCEL_IMPORT_LOG.errorcode
is '错误码';
comment on column T_EXCEL_IMPORT_LOG.errormsg
is '错误描述';
comment on column T_EXCEL_IMPORT_LOG.errortype
is '错误类型,默认INFO';
comment on column T_EXCEL_IMPORT_LOG.line_no
is '错误行号';