使用UTF-8的xp_cmdshell写入文件 [英] Write to file with xp_cmdshell in UTF-8
本文介绍了使用UTF-8的xp_cmdshell写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SELECT @command ='echo'+ @fileContent +'> e:\ out\'+ @fileName +'.csv'
exec master.dbo.xp_cmdshell'mkdire:\ out\''
exec master..xp_cmdshell @command
问题是文件内容不是UTF-8,所以有些特殊字符是错误的。 / p>
我可以使用UTF-8编码创建文件吗? 您可以使用 SQLCMD 代替旧的tecnique作为DOS outupt redirect
sqlcmd -S ServerName -d DataBaseName -E -oCSV文件路径和位置 - Q您的查询-W -w 4000 -s; -f 65001
交换机 -f 65001 指示使用UTF8作为outfile文件
SELECT @command ='sqlcmd -S ServerName -d DataBaseName -E -o'+ @fileName +' - Q您的查询-W -w 4000 -s; -f 65001'
exec master.dbo.xp_cmdshell'mkdire:\ out\'
exec master..xp_cmdshell @command
ps我无法测试,所以请检查SQLCMD文档
希望它有帮助
I am creating files with xp_cmdshell like this:
SELECT @command = 'echo ' + @fileContent + ' > e:\out\' + @fileName + '.csv'
exec master.dbo.xp_cmdshell 'mkdir "e:\out\"'
exec master..xp_cmdshell @command
The problem is that the file contents is not in UTF-8 and so some special characters are wrong.
Can i create the file in UTF-8 encoding?
解决方案
You can use the SQLCMD instead the old tecnique as DOS outupt redirect
sqlcmd -S ServerName -d DataBaseName -E -o "CSV File Path & Location" -Q "Your Query" -W -w 4000 -s ";" -f 65001
the switch -f 65001 indicate to use UTF8 as outfile file
SELECT @command = 'sqlcmd -S ServerName -d DataBaseName -E -o "'+ @fileName +'" -Q "Your Query" -W -w 4000 -s ";" -f 65001'
exec master.dbo.xp_cmdshell 'mkdir "e:\out\"'
exec master..xp_cmdshell @command
p.s. i cant test it so please check the SQLCMD documentation
Hope it help
这篇关于使用UTF-8的xp_cmdshell写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文