ms sql xml数据类型转换为文本

时间:2022-09-06 16:31:51

in MS Sql there are data types that are not supported by delphi 7, the xml datatype is one example.

在MS Sql中,有一些数据类型不受delphi 7的支持,xml数据类型就是一个例子。

I wish to convert the XML datatype to Text datatype, so that i could handle it in delphi.

我希望将XML数据类型转换为文本数据类型,以便在delphi中处理它。

Is there a way to convert from xml to text?

是否有一种方法可以将xml转换为文本?

2 个解决方案

#1


35  

A simple cast will suffice:

一个简单的演员就足够了:

select cast(XMLCol as nvarchar(max)) as XMLCol 

Or for non-unicode:

或者unicode:

select cast(XMLCol as varchar(max)) as XMLCol 

You can't convert explicitly to a 'text' data type.

不能显式地转换为“文本”数据类型。

I've added the as XMLCol to ensure that the converted data has the the same name as the column. You needn't have this, of course.

我添加了as XMLCol以确保转换后的数据具有与列相同的名称。你当然不需要这个。

EDIT:

编辑:

A few links. You are encouraged to use nvarchar(max) instead of text regardless. Microsoft have said they will be deprecating these types in future releases. nvarchar(max) ought to offer you 2GB:

几个链接。我们鼓励您使用nvarchar(max)而不是文本。微软表示,他们将在未来的版本中弃用这些类型。nvarchar(max)应该提供2GB:

http://www.petefreitag.com/item/734.cfm

http://www.petefreitag.com/item/734.cfm

http://www.teratrax.com/articles/varchar_max.html

http://www.teratrax.com/articles/varchar_max.html

http://msdn.microsoft.com/en-us/library/ms187752(v=SQL.90).aspx

http://msdn.microsoft.com/en-us/library/ms187752(v = SQL.90). aspx

#2


9  

SELECT CAST(YourXMLColumn as nvarchar(max))
    FROM YourTable

#1


35  

A simple cast will suffice:

一个简单的演员就足够了:

select cast(XMLCol as nvarchar(max)) as XMLCol 

Or for non-unicode:

或者unicode:

select cast(XMLCol as varchar(max)) as XMLCol 

You can't convert explicitly to a 'text' data type.

不能显式地转换为“文本”数据类型。

I've added the as XMLCol to ensure that the converted data has the the same name as the column. You needn't have this, of course.

我添加了as XMLCol以确保转换后的数据具有与列相同的名称。你当然不需要这个。

EDIT:

编辑:

A few links. You are encouraged to use nvarchar(max) instead of text regardless. Microsoft have said they will be deprecating these types in future releases. nvarchar(max) ought to offer you 2GB:

几个链接。我们鼓励您使用nvarchar(max)而不是文本。微软表示,他们将在未来的版本中弃用这些类型。nvarchar(max)应该提供2GB:

http://www.petefreitag.com/item/734.cfm

http://www.petefreitag.com/item/734.cfm

http://www.teratrax.com/articles/varchar_max.html

http://www.teratrax.com/articles/varchar_max.html

http://msdn.microsoft.com/en-us/library/ms187752(v=SQL.90).aspx

http://msdn.microsoft.com/en-us/library/ms187752(v = SQL.90). aspx

#2


9  

SELECT CAST(YourXMLColumn as nvarchar(max))
    FROM YourTable