-1
我有這個varchar字段;SQL僅從varchar獲取數值(子串)
Substrg
--------
38-40week
8month
7
40
38-40week
我想例如只獲得數字:
38-40
8
7
40
38-40
我試着用這個,但它不工作...:
select SUBSTRING(Substrg, PATINDEX('%[0-9]%', Substrg), LEN(Substrg))
我該怎麼辦?謝謝
'PATINDEX()'是一個SQL Server功能,但你的問題被標記爲MySQL。你真的在用什麼數據庫?另外,什麼時候嵌入式'-'變成了數字字符? – 2014-09-24 11:10:02
如果是SQL Server,請參閱http://stackoverflow.com/questions/9636045/t-sql-strip-all-non-alpha-and-non-numeric-characters使用'select dbo.fnRemovePatternFromString(fld,'%[^-0-9]%')' – 2014-09-24 11:15:03
您可以擴展mysql以使其支持正則表達式,請參閱[this](https://github.com/hholzgra/mysql-udf-regexp)以獲取更多信息 – zaratustra 2014-09-24 11:17:05