Skip to content
Advertisement

All tables consisting of numbers less than a fixed number

I am trying to find out all the tables where table names consist of numbers less than a fixed number 16284961 at the end preceded by an underscore for example LOG_16282961.

Sample User_segments table:

Expected Output:

Query:

Using above query, although I am getting my result but additionally it also includes following tables which are not required in my output:

Can you please help fix my query to get the desired output? Thanks.

Advertisement

Answer

Here’s one way – using regexp_substr to isolate one or more consecutive digits at the end of the input string, only if immediately preceded by underscore. (If the string does not have that structure, regexp_substr returns null and the filter condition becomes null < [something], which is never true.)

Create mock-up table for testing:

Query and output:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement