最近項目向MySql遷移,遷移完畢後,在獲取用戶權限時產生了一個異常,跟蹤進去獲取執行的語句以下,spa
SELECT PermissionId FROM spysxtPermission WHERE (ResourceCategory = 'BaseUser' AND ResourceId = '003bf4bd072243fa90517ee2bc088cb7' AND Enabled = 1 AND DeletionStateCode = 0) UNION SELECT PermissionId FROM spysxtPermission , ( SELECT RoleId FROM spysxtUserRole WHERE (UserId = '003bf4bd072243fa90517ee2bc088cb7' AND Enabled = 1 AND DeletionStateCode = 0 ) UNION SELECT RoleId FROM BaseUserRole WHERE ( UserId = '003bf4bd072243fa90517ee2bc088cb7' AND Enabled = 1 AND DeletionStateCode = 0 ) ) B WHERE ResourceCategory = 'spysxtRole' AND spysxtPermission.ResourceId = B.RoleId AND spysxtPermission.Enabled = 1 AND spysxtPermission.DeletionStateCode = 0
在Navicate執行,提示以下:調試
這個語句在Oracle中執行都是正常的,一時不知道是什麼緣由,baidu了也沒找到如何處理,我將語句逐個拆開執行,最終找到問題出在這裏:code
SELECT RoleId FROM spysxtUserRole WHERE (UserId = '003bf4bd072243fa90517ee2bc088cb7' AND Enabled = 1 AND DeletionStateCode = 0 )
UNION SELECT RoleId FROM BaseUserRole WHERE ( UserId = '003bf4bd072243fa90517ee2bc088cb7' AND Enabled = 1 AND DeletionStateCode = 0 )
看到這裏,我忽然想到有多是字符集不同形成的,打開表blog
原來問題出在排序規則上,一個是utf8_unicode_ci,一個是utf8_danish_ci。所有改成utf8_unicode_ci。問題解決!排序
原覺得是代碼bug,一直在調試代碼,沒想到問題出在這裏。ci