最後在同事的幫助下,我找到了可行的解決方案。它有一些限制(不考慮符號,不考慮小數部分),但是對於ID,它工作得很好。
- 微調的空間距離都開始和結束字符串
- 修剪掉串前導零
- 測試的最大允許長度
- 墊串用零四個字符(加上四個零字符串的開頭和獲得最後從字符串4個字符)
- 測試在字符串中的每個位置上設置允許字符
所以記錄從SRC_TABLE
不能轉換爲DECIMAL(4)
可以通過選擇來獲得:
select
Some_Id
from
SRC_TABLE
where
characters(trim(leading '0' from trim(both ' ' from Some_Id))) > 4
or substring(substring('0000' || trim(leading '0' from trim(both ' ' from Some_Id)) FROM characters('0000' || trim(leading '0' from trim(both ' ' from Some_Id))) - 3) FROM 1 FOR 1) NOT IN ('0','1','2','3','4','5','6','7','8','9')
or substring(substring('0000' || trim(leading '0' from trim(both ' ' from Some_Id)) FROM characters('0000' || trim(leading '0' from trim(both ' ' from Some_Id))) - 3) FROM 2 FOR 1) NOT IN ('0','1','2','3','4','5','6','7','8','9')
or substring(substring('0000' || trim(leading '0' from trim(both ' ' from Some_Id)) FROM characters('0000' || trim(leading '0' from trim(both ' ' from Some_Id))) - 3) FROM 3 FOR 1) NOT IN ('0','1','2','3','4','5','6','7','8','9')
or substring(substring('0000' || trim(leading '0' from trim(both ' ' from Some_Id)) FROM characters('0000' || trim(leading '0' from trim(both ' ' from Some_Id))) - 3) FROM 4 FOR 1) NOT IN ('0','1','2','3','4','5','6','7','8','9');
做好了解決方案。請注意,雖然它適用於您的特定情況,但它不等同於正確的數字解析器,因爲使用此方法負數和具有小數點的數據將被視爲無效。 – lins314159 2012-04-20 00:07:43