按范围选择表值

Big*_*yes 2 sql oracle

在我的表中,我有主键id.它是一个双字节varchar类型.如果id从00到89,则返回一组数据,否则返回不同的数据.我在存储过程中的查询是

BEGIN
select * from MyTable where (id like '0%' or
                             id like '1%' or
                             id like '2%' or
                             id like '3%' or
                             id like '4%' or
                             id like '5%' or
                             id like '6%' or
                             id like '7%' or
                             id like '8%') 
                             and status = 'active'
union all
select * from MyTable where id like '9%' and status='inactive'
END
Run Code Online (Sandbox Code Playgroud)

我的问题是如何改进它?我可以将字符串转换为数字然后使用>89<90

psu*_*sur 5

您还可以使用正则表达式:

select * from MyTable
where REGEXP_LIKE(id, '^[0-8][0-9]') and status='active'
or REGEXP_LIKE(id, '^9[0-9]') and status='inactive'
Run Code Online (Sandbox Code Playgroud)