1. 创建测试表:m_test
SET FOREIGN_KEY_CHECKS=0;
DROP TABLE IF EXISTS `m_test`;
CREATE TABLE `m_test` (
`HST_NO` decimal(12,0) NOT NULL ,
`UPDATE_KIND` varchar(1) NOT NULL ,
`ITEM_ID` varchar(10) NOT NULL ,
`ITEM_TAG` varchar(255) NOT NULL ,
`CREATE_USER_ID` varchar(15) DEFAULT NULL ,
`CREATE_DATE` timestamp NOT NULL DEFAULT '2001-01-01 00:00:00',
`UPDATE_USER_ID` varchar(15) DEFAULT NULL ,
`UPDATE_DATE` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
`LOGICAL_DELETE_FLAG` tinyint(1) DEFAULT '0' ,
PRIMARY KEY (`HST_NO`,`UPDATE_KIND`,`ITEM_ID`,`ITEM_TAG`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
2. aa.csv
"0","I","Y005585","xxx"
"0","I","Y005586","xxx"
"0","I","Y005587","xxx"
"0","I","Y005588","xxx"
3. 读取aa.csv到m_test表
LOAD DATA LOCAL
INFILE 'C:/aa.csv'
INTO TABLE M_TEST
CHARACTER SET 'utf8'
FIELDS
TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
(@hstNo, @updateKind, @itemId, @itemTag)
SET
HST_NO=@hstNo,
UPDATE_KIND=@updateKind,
ITEM_ID=@itemId,
ITEM_TAG=@itemTag,
CREATE_USER_ID='11',
CREATE_DATE=CURRENT_TIMESTAMP,
UPDATE_USER_ID='11',
SET FOREIGN_KEY_CHECKS=0;
DROP TABLE IF EXISTS `m_test`;
CREATE TABLE `m_test` (
`HST_NO` decimal(12,0) NOT NULL ,
`UPDATE_KIND` varchar(1) NOT NULL ,
`ITEM_ID` varchar(10) NOT NULL ,
`ITEM_TAG` varchar(255) NOT NULL ,
`CREATE_USER_ID` varchar(15) DEFAULT NULL ,
`CREATE_DATE` timestamp NOT NULL DEFAULT '2001-01-01 00:00:00',
`UPDATE_USER_ID` varchar(15) DEFAULT NULL ,
`UPDATE_DATE` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
`LOGICAL_DELETE_FLAG` tinyint(1) DEFAULT '0' ,
PRIMARY KEY (`HST_NO`,`UPDATE_KIND`,`ITEM_ID`,`ITEM_TAG`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
2. aa.csv
"0","I","Y005585","xxx"
"0","I","Y005586","xxx"
"0","I","Y005587","xxx"
"0","I","Y005588","xxx"
3. 读取aa.csv到m_test表
LOAD DATA LOCAL
INFILE 'C:/aa.csv'
INTO TABLE M_TEST
CHARACTER SET 'utf8'
FIELDS
TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
(@hstNo, @updateKind, @itemId, @itemTag)
SET
HST_NO=@hstNo,
UPDATE_KIND=@updateKind,
ITEM_ID=@itemId,
ITEM_TAG=@itemTag,
CREATE_USER_ID='11',
CREATE_DATE=CURRENT_TIMESTAMP,
UPDATE_USER_ID='11',
LOGICAL_DELETE_FLAG=IF(@updateKind='D',1,0)
*注意csv文件的换行符是\n 不是\r\n