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

本文介绍了如何将Excel表格数据高效导入Oracle数据库,并进行数据清洗和校验。通过定位空白单元格、批量填充公式以及使用SQL更新语句处理异常数据,确保数据一致性。同时,展示了创建数据库表结构、去除空格以及修复代码关联错误的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

复制表格到excel

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

90bba2bc4ec4570643887a41ad971785.png

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

effe1baa5fea1c2726df01f6e6f68ddc.png

填充空白单元格

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

931f55f2cfc89807e9cdb3bae6b359bb.png

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

eee2eb4646888857011ef324005671c6.png

写插入数据库语句

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

但Oracle不支持

54bd86c8e53d12cf1bff286b1e3ea7d2.png

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

数据太多直接崩了

b23af248d3d39102f7d13cc24f407529.png

oracle命令行导入sql文件

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

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

--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

pctfree10pctused40initrans1maxtrans255storage

(

initial 64K

next 1M

minextents1maxextents unlimited

);--Add comments to the columns

comment on column INDUSTRY.code1is '1位代码';

comment on column INDUSTRY.code2is '2位代码';

comment on column INDUSTRY.code3is '3位代码';

comment on column INDUSTRY.code4is '4位代码';

comment on column INDUSTRY.code5is '6位代码';

comment on column INDUSTRY.industry_nameis '行业名称';

View Code

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

3.@C:\Users\user\Downloads\6位行业代码插入\2.sql(你的文件的位置)

ed1dcadf2720adbfc396db624a8d52d5.png

dbc91a7b63d5b8a3eba2df4460cdfd8d.png

去除空格

update industry setcode1=trim(code1),

code2=trim(code2),

code3=trim(code3),

code4=trim(code4),

code5=trim(code5),

industry_name= trim(industry_name)

0f0d5c6511ccbfcc6dd507182ae4147e.png

处理不合格数据

1f698359ef5c18fa6c9dbdf4245e92cf.png

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

通过sql找出不合格的数据

select * fromindustrywhere length(code5)=6and (

substr(code5,0,2)!=code2

or substr(code5,0,3)!=code3

or substr(code5,0,4)!=code4

)

9b2f4c36ab0d852094d3ace67aeb9f22.png

执行更新sql

update industry setcode2= substr(code5,0,2),

code3= substr(code5,0,3),

code4= substr(code5,0,4)where length(code5)=6and (

substr(code5,0,2)!=code2

or substr(code5,0,3)!=code3

or substr(code5,0,4)!=code4

)

不合格数据2

select * fromindustrywhere length(code4)=4and (

substr(code4,0,2)!=code2

or substr(code4,0,3)!=code3

)

更正sql

update industry setcode2= substr(code4,0,2),

code3= substr(code4,0,3)where length(code4)=4and (

substr(code4,0,2)!=code2

or substr(code4,0,3)!=code3

)

处理填充过来的标题跟0

select * fromindustrywhere length(code2)!=2or length(code3)!=3or length(code4)!=4or length(code1)!=1

for update

f2ecd909376dcfc499b9adb868a3c20c.png

更正为

6eeb280ab81da202f4f220d4ee4e3822.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值