[SQL]字串中截取字元

  • 215
  • 0

sql字串中截取字元

--SQL Server(SUBSTRING)
select SUBSTRING('0123456789',0,5) ;--0123
select SUBSTRING('0123456789',1,5) ;--01234
select SUBSTRING('0123456789',2,5) ;--12345


select SUBSTRING(m.xTIME,1,6),count(*)  from table m 
where m.xTIME > '202210' 
group by SUBSTRING(m.xTIME,1,6) ;
 

--Oracle SQL (substr)
select substr('0123456789',0,5) from dual;--01234
select substr('0123456789',1,5) from dual;--01234
select substr('0123456789',2,5) from dual;--12345
select substr('0123456789',-9,1) from dual;--1
select substr('0123456789',-9,2) from dual;--12


select substr(g.xdate,1,6),count(*) from table g 
      where g.xdate>'202206'
      group by substr(g.xdate,1,6);