1. 程式人生 > >sql擷取取最後一個符號後面的內容(或前面)

sql擷取取最後一個符號後面的內容(或前面)



SELECT
a.id,a.name,a.dept_id,b.name,b.name_path, REVERSE( LEFT( REVERSE(b.name_path),LOCATE('→' , REVERSE(b.name_path) )-1)  )  ,REVERSE(SUBSTRING(REVERSE(b.name_path),LOCATE('→' , REVERSE(b.name_path) )+1,LENGTH(b.name_path))),1
FROM(
SELECT
id,name,dept_id
FROM
security_org_position  where  data_state=1 and  `name`='文祕'  


) a  INNER JOIN  security_org_department b on a.dept_id=b.id where b.data_state=1  and b.level2!=30000 and b.level3=3 ;

 REVERSE( LEFT( REVERSE(b.name_path),LOCATE('→' , REVERSE(b.name_path) )-1)  )  反轉順序獲取第一次符號出現的位置擷取

REVERSE(SUBSTRING(REVERSE(b.name_path),LOCATE('→' , REVERSE(b.name_path) )+1,LENGTH(b.name_path))) 反轉獲取特殊符號第一次出現的位置,從指定位置獲取符號前面的資料