判断两个图片是否相同

 


--自定义函数:

if object_id('tablename') is not null drop table tablename
create table tablename
  (id int identity(1, 1),
   a1 image,
   a2 image)
go
insert into tablename(a1, a2) select 'aaa', 'aaa'
insert into tablename(a1, a2) select 'bbb', 'bba'
insert into tablename(a1, a2) select 'ccc', 'ccc'
insert into tablename(a1, a2) select 'ddd', 'ddc'
--------------------------------------------------------------------------------
if object_id('Compare_Image') is not null drop function Compare_Image
go
create function Compare_Image(@a1 image, @a2 image) returns int
as
begin
  declare @n int, @i int, @j int
  declare @b1 varbinary(8000), @b2 varbinary(8000)
  set @n = 1
  if datalength(@a1) <> datalength(@a2) --长度不同
    set @n = 0
  else
  begin
    set @i = 0
    set @j = (datalength(@a1) - 1) / 8000 + 1
    while @i <= @j
    begin
      set @b1 = substring(@a1, @i * 8000 + 1, case @i when @j then datalength(@a1) % 8000 else 8000 end)
      set @b2 = substring(@a2, @i * 8000 + 1, case @i when @j then datalength(@a2) % 8000 else 8000 end)
      if @b1 <> @b2
      begin
        set @n = 0
        break
      end   
      set @i = @i + 1
    end
  end
  return(@n)
end
go
select * from tablename where dbo.Compare_Image(a1, a2) = 1
/*
id  a1         a2
1   0x616161   0x616161
3   0x636363   0x636363
*/
drop function Compare_Image
--------------------------------------------------------------------------------
drop table tablename

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值