LOAD语句:利用MSSQL中的xp_cmdshell功能,将指定文件夹下的指定文件,生成mysql的LOAD语句
declare @sql varchar(4000),
@dirpath varchar(1024),
@file_type varchar(16),
@target_table varchar(256);
select @target_table = '`AdConversions`.`App_AdCreative_Device_Mapping_Conversion`'
,@dirpath= 'D:\cv'
,@file_type='.tsv'
,@sql = 'dir '+ @dirpath + ' /b/a ' ;
if OBJECT_ID('tempdb..#temp') is not null
drop table tempdb..#temp
create table #temp ( dirfile nvarchar(255)) ;
insert into #temp
exec xp_cmdshell @sql ;
select ' LOAD DATA LOCAL INFILE ''' + REPLACE( @dirpath,'\','\\') +'\\' + dirfile + ''' INTO TABLE ' + @target_table + ' CHARACTER SET utf8; ' as ExeSql
from #temp where dirfile like '%'+@file_type;