[转]SQL - Create XML - How to set Unicode UTF-8

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[转]SQL - Create XML - How to set Unicode UTF-8相关的知识,希望对你有一定的参考价值。

本文转自:https://stackoverflow.com/questions/44754356/sql-create-xml-how-to-set-unicode-utf-8

 

I found a solution via another way. (don‘t remember which website I found it) See code below. This code will export my file in UTF-8-BOM encoding.



DECLARE @OLE            INT 

EXECUTE sp_OACreate ‘ADODB.Stream‘,  @OLE OUTPUT

DECLARE @Text XML
SET @Text =  N‘This is the 测试测试 test string‘;  --(SELECT TOP(1) [xml] from VW_WARP_LEVERANCIERS_XML)     
DECLARE @Converted NVARCHAR(MAX)
SET @Converted = CONVERT(nvarchar(MAX), @Text)

EXECUTE sp_OASetProperty             @OLE,    ‘Type‘,             2                           --1 = binary, 2 = text
EXECUTE sp_OASetProperty             @OLE,    ‘Mode‘,             3                           --0 = not set, 1 read, 2 write, 3 read/write
EXECUTE sp_OASetProperty             @OLE,    ‘Charset‘,          ‘UTF-8‘                     --‘ISO-8859-1‘
EXECUTE sp_OASetProperty             @OLE,    ‘LineSeparator‘,    ‘adLF‘
EXECUTE sp_OAMethod                  @OLE,    ‘Open‘  
EXECUTE sp_OAMethod                  @OLE,    ‘WriteText‘,        NULL,       @Converted      --text method

--Commit data and close text stream
EXECUTE sp_OAMethod                  @OLE,    ‘SaveToFile‘,       NULL,       ‘d:1.txt‘, 2   --1 = notexist 2 = overwrite
EXECUTE sp_OAMethod                  @OLE,    ‘Close‘
EXECUTE sp_OADestroy                 @OLE

EXECUTE sp_OADestroy @OLE 


以上是关于[转]SQL - Create XML - How to set Unicode UTF-8的主要内容,如果未能解决你的问题,请参考以下文章

[转]How to: Create a Custom Principal Identity

How To Create An ASM Diskgroup Using XML code Thru ASMCMD [ID 1290550.1]

How can I create a dump of SQL Server?

[转]How do I use variables in Oracle SQL Developer?

sql 一种表值函数,可将XML转换为表。感谢http://stackoverflow.com/questions/2266132/how-can-i-get-a-list-of-element

How to create an rpm package