oracle截取字符串左右兩邊的字符數據,並用於排序


截取一個字符串中-最后出現的左右兩邊的數據

--截取左邊

SELECT reverse(substr(reverse(OBJBELONG),INSTR(reverse(OBJBELONG),'-') + 1)) FROM WF_TASK;

 

--截取右邊

SELECT reverse(substr(reverse(OBJBELONG),1,INSTR(reverse(OBJBELONG),'-') - 1)) FROM WF_TASK;

 

--以此來排序

order by reverse(substr(reverse(OBJBELONG),INSTR(reverse(OBJBELONG),'-') + 1)) asc,TO_NUMBER(reverse(substr(reverse(OBJBELONG),1,INSTR(reverse(OBJBELONG),'-') - 1))) asc 

 

--匹配正則查詢

SELECT
*
FROM
arv_basinfo
WHERE
1 = 1
AND reverse ( substr( reverse ( arvno ), INSTR( reverse ( arvno ), '-' ) + 0 ) ) = 'CSI-ZBZD-JY-2020-'
AND TO_NUMBER(
regexp_replace(
reverse ( substr( reverse ( arvno ), 1, INSTR( reverse ( arvno ), '-' ) - 1 ) ),
'[^0-9]',
''
)
) >= 1
AND TO_NUMBER(
regexp_replace(
reverse ( substr( reverse ( arvno ), 1, INSTR( reverse ( arvno ), '-' ) - 1 ) ),
'[^0-9]',
''
)
) <= 39500
ORDER BY
TO_NUMBER(
regexp_replace(
reverse ( substr( reverse ( arvno ), 1, INSTR( reverse ( arvno ), '-' ) - 1 ) ),
'[^0-9]',
''
)
) DESC


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM