简体   繁体   English

将图像转换为 nvarchar(max)

[英]Convert image to nvarchar(max)

I have a field that is defined as longblob in an MySQL database in which I upload pdf/word files/ etc. However, I access this database from my SQL Server database and the data is accessed from a linked server and views.我有一个在 MySQL 数据库中定义为longblob的字段,我在其中上传了 pdf/word 文件/等。但是,我从我的 SQL Server 数据库访问该数据库,并且从链接服务器和视图访问数据。

Problem The problem is, the data needs to be imported by another application, but the data type of the document file is coming across as image and that is causing a problem.问题问题是,数据需要由另一个应用程序导入,但文档文件的数据类型以图像形式出现,这导致了问题。

What have I tried我试过什么

I have first tried to see if I change longblob to varbinary to get a varbinary(max) data type in SQL Server.我首先尝试查看是否将longblob更改为varbinary以在 SQL Server 中获取varbinary(max)数据类型。 That did not work, I still got image.那没有用,我仍然有图像。

Then I tried to make a view of the view to convert the data.然后我尝试制作视图以转换数据。 I tried CAST(fileContent as varchar(max)) and got the error:我试过CAST(fileContent as varchar(max))并得到错误:

Explicit conversion from data type image to nvarchar(max) is not allowed.不允许从数据类型 image 显式转换为 nvarchar(max)。

I then tried cast(cast(fileContent as varbinary(max)) as varchar(max)) as fileContent as I see suggested but I am getting back a ton of gibberish.然后我尝试cast(cast(fileContent as varbinary(max)) as varchar(max)) as fileContent正如我所看到的那样,但我得到了大量的胡言乱语。

%PDF-1.4 %âãÏÓ 3 0 obj <</Type /Page /Parent 1 0 R /MediaBox [0 0 595.280 841.890] /TrimBox [0.000 0.000 595.280 841.890] /Resources 2 0 R /Group << /Type /Group /S /Transparency /CS /DeviceRGB >> /Contents 4 0 R>> endobj 4 0 obj <</Filter /FlateDecode /Length 521>> stream xœµRËnÛ0Ü3¿b-ÐÐ|ŠRn ) 4¥==¨¶âºu'F1

instead of something like 0x255044462D312E ,而不是像0x255044462D312E这样的东西,

Appreciate if I could get some assistance in converting binary data (which claims it's an image to nvarchar(max) .感谢我能否在转换二进制数据(声称它是一个图像到nvarchar(max)获得一些帮助。

declare @t table(theimage image)
insert into @t(theimage) 
values(0x3a26);


select convert(varchar(max), cast(theimage as varbinary(max)), 1) as theimagebinaryaschar
from @t;

declare @theimageaschar varchar(max) = '0x3a26';
select convert(varbinary(max), @theimageaschar, 1) as theimageasbinary;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM