首页 > 解决方案 > 值更改时,regexp_substr 不起作用

问题描述

我想要每个学生的最低和最高分数。下面是示例标记,我希望 uc_min 作为之前的任何内容 / 和 uc_max 作为之后的任何内容 /

下面是我的代码,它不适用于个位数

select distinct  regexp_substr(marks,'[^/]+',1,1) uc_min, 
        regexp_substr(marks,'[^/]+',4,1)  uc_max
   from std
  where student_id = 'YYY'

预期输出:

Sample marks   Expected uc_min    Expected uc_max
1/100          1                  100
20/30          20                 30
180/730        180                730
20/200         20                 200

标签: sqloracle

解决方案


一个substr/ instr解决方案,假设有一个"/"

select substr(marks, 1, instr(marks,'/') - 1) as uc_min,
       substr(marks, instr(marks,'/') + 1) as uc_max
from std;

演示


推荐阅读