我剛剛發現了一個我認為是 Azure SQL 中的錯誤:
下面的查詢顯示了結果:
Select * from table where '_' BETWEEN ' ' AND 'ZZZZZZZ',
但事實上,在我的理解和常規 SQL Server 或 Oracle 中,此查詢不顯示任何結果。
這里有什么想法嗎?
uj5u.com熱心網友回復:
尾部的空格被忽略的=和between比較。So' '等效于'', 這是當前(我認為是每個)排序規則的 varchar 排序順序中最低的非空值。這在 SQL Server 和 Azure SQL 資料庫上是相同的。
在當前所有非二進制排序規則'Z' > '_'和所有二進制排序規則中'Z' < '_',但' '始終較低。
您可以使用動態 SQL 在所有排序規則中運行比較。例如
declare c cursor local for select name from fn_helpcollations()
declare @collation sysname
declare @collations table(collation sysname, is_Z_less_than_underscore bit)
open c
fetch next from c into @collation
while @@FETCH_STATUS = 0
begin
declare @sql nvarchar(max) = 'select ''' @collation ''', case when ''Z'' < ''_'' collate ' @collation ' then 1 else 0 end'
begin try
insert into @collations
exec (@sql)
end try
begin catch
print error_message()
end catch
fetch next from c into @collation
end
close c
deallocate c
select *
from @collations
order by 2,1
uj5u.com熱心網友回復:
它還以 MS SQL 形式回傳結果。由于對于某些排序規則,“_”實際上似乎介于“”和“ZZZZZZZ”之間,因此它實際上與
Select * from table where 1=1
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/349947.html
標籤:sql azure-sql-数据库
