這是一道來自stackoverflow的問題(連結http://stackoverflow.com/questions/35122231/mysql-how-to-get-numeric-value-after-special-character-in-varchar)
我有一串記錄,我該如何獲得這串記錄中斜線“/”之後的最右的數值(1,2,10),如果你有PHP代碼可以自動重置月份數值,那真是太好了。
回答:
假設你知道所有的記錄都是A/x/y的形式,然後「/」總是作為特殊符號,那麼你可以使用explode()
程式碼:
substring_index(): select substring_index(col,'/',-1) <br>
從 t;
如果你想將得到的t
變成數字 select substring_index(col,'/',-1)+1 <br>
從 t;
第二個答案:
試試看這個: $str = "ABC/209116/1"; <br>
$replace_with = "0"; <br>
$str= substr(0,strrchr($str,"/")); <br>
$replace_with;
以上就介紹了MySQL 如何在可變長字串中獲得在特殊字元之後的數值(來自stackoverflow),包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。