从word得到表格数据插入数据库(6位行业代码)

复制表格到excel

点击表格左上角选中全部表格,然后crtl+c,再贴到excel中

可以发现,大类代码,单元格往下走,碰到下一个有值的之前,都是上一个的范围

 

填充空白单元格

1.选中前四列,然后ctrl+g定位空白表格

2.按住ctrl,点击有值的下一个单元格,写入等于上一个单元格的公式,然后ctrl+enter

 写插入数据库语句

最好写成insert into values(1, 2, 3), (1, 2, 3);

但Oracle不支持

 最好双击写公式的单元格,然后复制,得到sql如下

数据太多直接崩了

oracle命令行导入sql文件

1.建表,字段值远大于实际值,防止空格这些引起超长度

-- Create table
create table INDUSTRY
(
  code1         VARCHAR2(20),
  code2         VARCHAR2(20),
  code3         VARCHAR2(20),
  code4         VARCHAR2(20),
  code5         VARCHAR2(20),
  industry_name VARCHAR2(500)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
-- Add comments to the columns 
comment on column INDUSTRY.code1
  is '1位代码';
comment on column INDUSTRY.code2
  is '2位代码';
comment on column INDUSTRY.code3
  is '3位代码';
comment on column INDUSTRY.code4
  is '4位代码';
comment on column INDUSTRY.code5
  is '6位代码';
comment on column INDUSTRY.industry_name
  is '行业名称';
View Code

2.打开cmd窗口,输入命令如下:sqlplus username/password@ip:port/实例名

3.@C:UsersuserDownloads6位行业代码插入2.sql(你的文件的位置)

 

去除空格

update industry set 
code1 = trim(code1),
code2 = trim(code2),
code3 = trim(code3),
code4 = trim(code4),
code5 = trim(code5),
industry_name = trim(industry_name)

 

处理不合格数据

可发现,code2,code3,code4应该为code5的前几位

通过sql找出不合格的数据

select * from industry
where length(code5)=6
and (
substr(code5,0,2)!=code2 
or substr(code5,0,3)!=code3
or substr(code5,0,4)!=code4
)

执行更新sql

update industry set
code2 = substr(code5,0,2),
code3 = substr(code5,0,3),
code4 = substr(code5,0,4)
where length(code5)=6
and (
substr(code5,0,2)!=code2 
or substr(code5,0,3)!=code3
or substr(code5,0,4)!=code4
)

不合格数据2

select * from industry
where length(code4)=4
and (
substr(code4,0,2)!=code2 
or substr(code4,0,3)!=code3
)

更正sql

update industry set
code2 = substr(code4,0,2),
code3 = substr(code4,0,3)
where length(code4)=4
and (
substr(code4,0,2)!=code2 
or substr(code4,0,3)!=code3
)

处理填充过来的标题跟0

select * from industry 
where length(code2)!=2
or length(code3)!=3
or length(code4)!=4
or length(code1)!=1 
for update

更正为

原文地址:https://www.cnblogs.com/lurenjia1994/p/9709197.html