繁体   English   中英

操作数类型冲突:varchar 与 varchar(255) 使用 Always Encrypted with Secure Enclaves 和 CASE 语句不兼容

[英]Operand type clash: varchar is incompatible with varchar(255) Using Always Encrypted with Secure Enclaves and CASE statement

我正在尝试从案例语句中从数据库中返回一个加密值。

DECLARE @emptyValue VARCHAR(255) = '';
Select Top 1 CASE WHEN o.shippingFirstName = @emptyValue AND o.shippingLastName = @emptyValue  

THEN '' ELSE o.shippingFirstName  END AS nameDisplay  from [Order] o 

当我运行它时,我收到以下错误

Msg 206, Level 16, State 2, Line 20 Operand type clash: varchar is incompatible with varchar(255) encrypted with (encryption_type = 'RANDOMIZED', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'CEK1', column_encryption_key_database_name = 'cfg_phoenix_prod') collation_name = 'Latin1_General_BIN2' Msg 206, Level 16, State 2, Line 20 Operand type clash: varchar is incompatible with varchar(255) encrypted with (encryption_type = 'RANDOMIZED', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'CEK1', column_encryption_key_database_name = 'cfg_phoenix_prod') collation_name = 'Latin1_General_BIN2' Msg 206, Level 16, State 2, Line 20 Operand type clash: varchar is incompatible with varchar(255) encrypted with (encryption_type = 'RANDOMIZED', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_na me = 'CEK1', column_encryption_key_database_name = 'cfg_phoenix_prod') collation_name = 'Latin1_General_BIN2' Msg 206, Level 16, State 2, Line 20 Operand type clash: varchar is incompatible with varchar(255) encrypted with (encryption_type = 'RANDOMIZED', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'CEK1', column_encryption_key_database_name = 'cfg_phoenix_prod') collation_name = 'Latin1_General_BIN2' Msg 206, Level 16, State 2, Line 20 Operand type clash: varchar is incompatible with varchar(255) encrypted with (encryption_type = 'RANDOMIZED', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'CEK1', column_encryption_key_database_name = 'cfg_phoenix_prod') collation_name = 'Latin1_General_BIN2' Msg 8180, Level 16, State 1, Procedure sp_describe_parameter_encryption, Line 1 [Batch Start Line 17] Statement(s ) 可以 不准备。 消息 8180,级别 16,State 1,过程 sp_describe_parameter_encryption,第 1 行 [批处理开始第 17 行] 无法准备语句。 消息 8180,级别 16,State 1,过程 sp_describe_parameter_encryption,第 1 行 [批处理开始第 17 行] 无法准备语句。 消息 8180,级别 16,State 1,过程 sp_describe_parameter_encryption,第 1 行 [批处理开始第 17 行] 无法准备语句。 消息 8180,级别 16,State 1,过程 sp_describe_parameter_encryption,第 1 行 [批处理开始第 17 行] 无法准备语句。 执行批处理时出错。 错误信息是:内部错误。 语句或过程“DECLARE @emptyValue AS VARCHAR (255) = @pc2d5b410384a4500b3493a0306f71d28”中参数“@pc2d5b410384a4500b3493a0306f71d28”的元数据;

SELECT TOP 1 CASE WHEN o.shippingFirstName = @emptyValue AND o.shippingLastName = @emptyValue THEN ' ' ELSE o.shippingFirstName END AS nameDisplay FROM [Order] AS o;

' 在 sp_describe_parameter_encryption 返回的结果集中缺失。

比较似乎工作正常。 只有当 ELSE 尝试返回产生问题的 o.shippingFirstName 时。

类似这样的查询可以正常工作:

DECLARE @emptyValue VARCHAR(255) = ''; 
Select Top 1 o.shippingFirstName   from [Order] o  where o.shippingFirstName is not Null and o.shippingFirstName <> @emptyValue

有什么我遗漏或无法完成的吗?

茫然和困惑

因为这些列是使用 Always Encrypted 加密的,所以服务器根本无法读取它们。 只有客户端可以解密它们。 它无法将列值与未加密的变量进行比较,它们根本不兼容。 您可以做的唯一操作是将列与另一个加密值进行比较。

它没有办法将它们与任何东西进行比较。 相反,您需要删除@emptyValue变量的声明并将其作为参数直接从客户端传递。

如果您使用的是随机加密,您甚至不能这样做,您只需将其返回给客户端。

暂无
暂无

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

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