How to get rightmost 10 places of a string in oracle

后端 未结 4 1003
旧时难觅i
旧时难觅i 2021-01-03 18:24

I am trying to fetch an id from an oracle table. It\'s something like TN0001234567890345. What I want is to sort the values according to the right most 10 posit

4条回答
  •  庸人自扰
    2021-01-03 19:12

    codaddict's solution works if your string is known to be at least as long as the length it is to be trimmed to. However, if you could have shorter strings (e.g. trimming to last 10 characters and one of the strings to trim is 'abc') this returns null which is likely not what you want.

    Thus, here's the slightly modified version that will take rightmost 10 characters regardless of length as long as they are present:

    select substr(colName, -least(length(colName), 10)) from tableName;
    

提交回复
热议问题