写在开头:
其实,我已经很难用脑子记住什么了,所以写在这里,以免自己忘记。
下面这个是
in_xxx_MMClaims_GeneralInfo.sql的内容
这个脚本负责把一个数据文件导入数据库,并且实现
(1)日期格式从 m/dd/yyy 导入到 yyyy/mm/dd
(2)对于数据文件中为空的,经过步骤(1)被变成0000-00-00,要还原成null
执行方法
mysql -h localhost -upmis -p666666 < E:\test\in_xxx_MMClaims_GeneralInfo.sql
use xxx_2020
load data local infile “e:\test\MMClaims_GeneralInfo_20191126_1.txt”
into table mmclaims_generalinfo
fields terminated by’|’
enclosed by ‘"’
(Operation
,Mining Claim Key
,Claim Name
,Mining Claim ID
,List of Owners
,
Claim Status
,Claim Status as Reported
,Agency Claim ID
,Claim Type
,Claim Type as Reported
,Commodities
,
@Application Date
,@Date Granted
,@Expiry Date
,@Source As Of Date
,
Source
,Claim Area
,Country Name
,SNL Global Region
)
set
Application Date
=str_to_date(@Application Date
,’%m/%d/%Y’),
Date Granted
=str_to_date(@Date Granted
,’%m/%d/%Y’),
Expiry Date
=str_to_date(@Expiry Date
,’%m/%d/%Y’),
Source As Of Date
=str_to_date(@Source As Of Date
,’%m/%d/%Y’);
update mmclaims_generalinfo
SET
Application Date
= NULL where CAST(Application Date
AS CHAR(20)) = ‘0000-00-00’;
update mmclaims_generalinfo
SET
Date Granted
= NULL where CAST(Date Granted
AS CHAR(20)) = ‘0000-00-00’;
update mmclaims_generalinfo
SET
Expiry Date
= NULL where CAST(Expiry Date
AS CHAR(20)) = ‘0000-00-00’;
update mmclaims_generalinfo
SET
Source As Of Date
= NULL where CAST(Source As Of Date
AS CHAR(20)) = ‘0000-00-00’;
注意:csdn的显示略去了一些符号,你看到所有的红颜色的词组
都是由~键下面的那个单引号括住的。