如何在SQL Server中比较两个图像 [英] How to compare two images in SQL server

查看:103
本文介绍了如何在SQL Server中比较两个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要比较已插入Image Data Type列的Image和通过SQL Stored Procedure的Image Object,是否可以通过SQL脚本进行比较?



我尝试了什么:



我尝试使用下面的脚本,但它不能正常工作



创建表foo



img image



go



选择*

来自foo a,foo b

WHERE convert(varbinary,a.img) = convert(varbinary,b.img)

I need to compare the Image which already inserted in the Image Data Type column and the Image Object which passed through the SQL Stored Procedure, Is it possible to compare through SQL script?

What I have tried:

I tried with the below script, but it is not working

create table foo
(
img image
)
go

select *
from foo a, foo b
WHERE convert(varbinary,a.img) = convert(varbinary,b.img)

推荐答案

您尚未在 CONVERT 调用中指定长度。根据文档 [< a href =https://docs.microsoft.com/en-us/sql/t-sql/data-types/binary-and-varbinary-transact-sqltarget =_ blanktitle =New Window> ^ ],数据将被截断为前30个字节。



指定 max as长度和比较应该有效:

You haven't specified a length in your CONVERT call. According to the documentation[^], the data will be truncated to the first 30 bytes.

Specify max as the length, and the comparison should work:
SELECT *
FROM foo As a INNER JOIN foo As b
ON CONVERT(varbinary(max), a.img) = CONVERT(varbinary(max), b.img);



如果没有,那么你需要前明白问题是什么。



注意:只有字节完全相同时,记录才会匹配。如果单个字节不同,则图像被认为是不同的,即使它们看起来相同。


If it doesn't, then you'll need to explain what the problem is.

NB: The records will only match if the bytes are exactly the same. If a single byte is different, the images are considered different, even if they look the same.


这篇关于如何在SQL Server中比较两个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆