日期:2014-05-17  浏览次数:20977 次

oracle 取字符串/后面的字符
有一个字段 name 
  gaga/gaga/aa
  fa/gda
  dfa/gads/ga/ga
比如有这些值,我怎么取这个字段最后一个/后面的值
  name
  aa
  gda
  aa

结果这样

------解决方案--------------------
SQL code

--举例如下,你的表自已替换下就可以了
select replace(regexp_substr('gaga/gaga/aa','/[[:alpha:]]*$'),'/','') from dual;

------解决方案--------------------
SQL code
select substr('dfa/gads/ga/ga', instr('dfa/gads/ga/ga', '/', -1) + 1) from dual;

------解决方案--------------------
SQL code

--方法1:
SQL> with tmp as
  2  (
  3    select 'gaga/gaga/aa' name from dual union all
  4    select 'fa/gda' name from dual union all
  5    select 'dfa/gads/ga/ga' name from dual
  6  )
  7  select replace(regexp_substr(name,'/[[:alpha:]]*$'),'/','') name from tmp;
 
NAME
----------------------------
aa
gda
ga
 
--方法2:
SQL> with tmp as
  2  (
  3    select 'gaga/gaga/aa' name from dual union all
  4    select 'fa/gda' name from dual union all
  5    select 'dfa/gads/ga/ga' name from dual
  6  )
  7  select substr(name, instr(name, '/', -1) + 1) name from tmp;
 
NAME
----------------------------
aa
gda
ga