Sql Server字元的處理(LastIndexOf用法),STUFF、CHARINDEX、REVERSE、LEN,charindex

來源:互聯網
上載者:User

Sql Server字元的處理(LastIndexOf用法),STUFF、CHARINDEX、REVERSE、LEN,charindex
  DECLARE @s VARCHAR(100)
  SET @s='R1-1-1'   擷取最後一個“-”之後的數字
  select REVERSE(@s)    返回值:1-1-1R  將字元顛倒過來  select LEN(@s)             返回值:6  擷取長度  select CHARINDEX('-',REVERSE(@s))                     返回值:2   --擷取某個字串第一次出現的位置,若沒有改字元,則返回0  select STUFF(@s,1,LEN(@s)-CHARINDEX('-',REVERSE(@s))+1,'')        返回值:1   
                STUFF函數STUFF (expression , start , length ,relaceChar)                                         expression:需要處理的字串                                    start:開始位置(順便提醒一下Sql Server是從1開始的,不是0)
                                             length:需要替換的字元個數                                    relaceChar:將選取的字元替換為某某

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.