当前位置: 代码迷 >> Oracle开发 >> oracle去字段后4位如何写
  详细解决方案

oracle去字段后4位如何写

热度:527   发布时间:2016-04-24 08:04:14.0
oracle去字段后4位怎么写啊
表test 字段id VARCHAR类型 想取它的后四位 请问怎么写这条sql啊?

------解决方案--------------------
SQL code
select substr(id, 1,length(id)-4) as idfrom test;
------解决方案--------------------
select substr(id,length(id)-4+1) as id
from test;
------解决方案--------------------
select substr(c1,length(c1)-4+1) from t1
------解决方案--------------------
SQL code
SQL> with tmp as (  2       select '12345' data from dual union all  3       select '1' data from dual union all  4       select '123' data from dual  5       )  6  select substr(data, -least(length(data), 4))  7    from tmp; SUBSTR(DATA,-LEAST(LENGTH(DATA------------------------------23451123
  相关解决方案