mysql中對字符串的定位及切割操做

 如題,用到了兩個函數locate和substringide

  
  
           
  
  
  1. locate('要查詢的字符','字符所在的字符串') 
  2. eg:locate('_','test_cd'); 
  3. substring('被截取的字符串',開始下標,結束下標) 
  4. eg:substring('test_cd',1,4) 

兩個函數能夠合併使用函數

  
  
           
  
  
  1. SELECT SUBSTRING('test_cd',1,LOCATE('_','test_cd')-1); 

結果爲spa

相關文章
相關標籤/搜索