我想从字符串的开头删除所有零0
:
SQL:
SELECT SUBSTR('00008800000006',0,7) AS serno ,
SUBSTR('00008800000006',8,14) AS lot
FROM dual ;
预期结果:
答案 0 :(得分:3)
如果您使用的是Oracle,可以试试这个:
select
REGEXP_REPLACE(SUBSTR('00008800000006',0,7), '^0+(.*$)', '\1') as Serno,
REGEXP_REPLACE(SUBSTR('00008800000006',8,14), '^0+(.*$)', '\1') as lot
from dual;
<强> OUPUT 强>
SERNO LOT
880 6
您也可以使用LTRIM
select
ltrim(SUBSTR('00008800000006',0,7), '0') as Serno,
ltrim(SUBSTR('00008800000006',8,14), '0') as lot
from dual
<强> OUPUT 强>
SERNO LOT
880 6