查找出db中不可見字元
阿新 • • 發佈:2019-02-11
refs
https://stackoverflow.com/questions/8655909/whats-the-best-way-to-identify-hidden-characters-in-the-result-of-a-query-in-sq
原理先生成一個不可見字元表,而後用表關聯後以不可見字元為關鍵字,查詢表。
--SELECT * from by_dtu WHERE DATALENGTH(bianhao) > LEN(bianhao) ;WITH cte AS ( SELECT 1 AS CharCode UNION ALL SELECT CharCode + 1 FROM cte WHERE CharCode <47 and CharCode!=37 ) SELECT * FROM by_dtu T cross join cte WHERE EXISTS (SELECT * FROM by_dtu Tx WHERE Tx.id = T.id AND
-- 過濾掉% 因為它是個萬用字元
-- Tx.bianhao LIKE '%' + CHAR(cte.CharCode) + '%'
Tx.bianhao LIKE '%' + (select case when cte.CharCode=37 then '\'+CHAR(cte.CharCode) else CHAR(cte.CharCode) end ) + '%'
)