栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在两个二进制类型之间的SQL Server中按位异或?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在两个二进制类型之间的SQL Server中按位异或?

代码块中的所有注释

-- variablesdeclare @vb1 binary(16), @vb2 binary(16), @lo binary(8), @hi binary(8)-- 2 guids to comparedeclare @guid1 uniqueidentifier set @guid1 = '96B4316D-1EA7-4CA3-8D50-FEE8047C1329'declare @guid2 uniqueidentifier set @guid2 = 'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF'-- split every 8 bytes into a binary(8), which is a bigint, the largest size usable with XORselect @vb1 = @guid1, @vb2 = @guid2-- xor the high and low parts separatelyselect @hi = convert(binary(8), substring(@vb1,1,8)) ^ convert(bigint, substring(@vb2,1,8))select @lo = convert(binary(8), substring(@vb1,9,8)) ^ convert(bigint, substring(@vb2,9,8))-- the final result, concatenating the bytes using char(8) - binary -> uniqueidentifierselect 'A', @guid1 union allselect 'B', @guid2 union allselect 'A XOR B = ', convert(uniqueidentifier, convert(binary(16),convert(char(8),@hi) + convert(char(8),@lo)))


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/441521.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号