select
gfid,
gfname,
case instr(gfid, '.', -1, 1) when 0 then '0' else substr(gfid, 0,instr(gfid, '.', -1, 1)-1) end as parentid
from testtable98
order by gfid
------解决方案-------------------- case instr(gfid, '.', -1, 1) when 0 then '0' else substr(gfid, 0,instr(gfid, '.', -1, 1)-1) end as parentid
=>
decode(instr(gfid, '.', -1, 1),0 , '0' , substr(gfid, 0,instr(gfid, '.', -1, 1)-1)) as parentid ------解决方案--------------------
WITH T AS(
SELECT '01' AS GFID,'档案查阅' AS GFNAME FROM DUAL UNION ALL
SELECT '01.01','档案阅览' AS GFNAME FROM DUAL UNION ALL
SELECT '01.01.1','导出' AS GFNAME FROM DUAL UNION ALL
SELECT '01.01.2','打印' AS GFNAME FROM DUAL UNION ALL
SELECT '01.01.3','收藏' AS GFNAME FROM DUAL UNION ALL
SELECT '01.02','目录浏览' AS GFNAME FROM DUAL UNION ALL
SELECT '01.03','档案查询' AS GFNAME FROM DUAL UNION ALL
SELECT '01.04','全文检索' AS GFNAME FROM DUAL UNION ALL
SELECT '02','档案借阅' AS GFNAME FROM DUAL UNION ALL