How to get rightmost 10 places of a string in oracle

后端 未结 4 967
旧时难觅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:14

    Yeah this is an old post, but it popped up in the list due to someone editing it for some reason and I was appalled that a regular expression solution was not included! So here's a solution using regex_substr in the order by clause just for an exercise in futility. The regex looks at the last 10 characters in the string:

    with tbl(str) as (
      select 'TN0001239567890345' from dual union
      select 'TN0001234567890345' from dual
    )
    select str
    from tbl
    order by to_number(regexp_substr(str, '.{10}$'));
    

    An assumption is made that the ID part of the string is at least 10 digits.

提交回复
热议问题