Sql 从varchar中删除额外的零

Sql 从varchar中删除额外的零,sql,oracle,substring,Sql,Oracle,Substring,我想删除字符串开头的所有零0: SQL: 预期结果: SUBSTR('000088000000006',0,7)='0000880'=>Serno='880' SUBSTR('000088000000006',8,14)='0000006'=>lot='6' 如果您正在使用Oracle,您可以尝试以下方法: select REGEXP_REPLACE(SUBSTR('00008800000006',0,7), '^0+(.*$)', '\1') as Serno, REGEXP_REPL

我想删除字符串开头的所有零
0

SQL:

预期结果:

  • SUBSTR('000088000000006',0,7)='0000880'=>Serno='880'
  • SUBSTR('000088000000006',8,14)='0000006'=>lot='6'

如果您正在使用Oracle,您可以尝试以下方法:

select
 REGEXP_REPLACE(SUBSTR('00008800000006',0,7), '^0+(.*$)', '\1') as Serno,
 REGEXP_REPLACE(SUBSTR('00008800000006',8,14), '^0+(.*$)', '\1') as lot
 from dual;
输出

SERNO    LOT

880      6   
SERNO    LOT

880      6   
您也可以使用LTRIM

select
 ltrim(SUBSTR('00008800000006',0,7), '0') as Serno,
 ltrim(SUBSTR('00008800000006',8,14), '0') as lot
  from dual
输出

SERNO    LOT

880      6   
SERNO    LOT

880      6