LOAD語句:利用MSSQL中的xp_cmdshell功能,將指定檔案夾下的指定檔案,產生mysql的LOAD語句

來源:互聯網
上載者:User

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 nulldrop table tempdb..#tempcreate 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 ExeSqlfrom #temp where dirfile like '%'+@file_type;


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.