with t as ( select '3.5' grade from dual union all select '3.55' grade from dual union all select '3a55' grade from dual union all select '3.555' grade from dual union all select '33.5' grade from dual union all select 'a.5' grade from dual union all select '3.aa' grade from dual ) select case when regexp_like(grade,'^[0-4]\.([0-9]|[0-9]{2})$') --마농님 댓글 보고 일단 4점대까지만 나오는 걸로 수정.. 그렇다고 하더라도 4.99는 없을텐데..; then 'Y' else 'N' end chk, grade from t
어차피 function으로 만드신다고 하셨으니 좀 절차적으로 나눠서 해야겠네요.
create or replace function fn_check_grade(in_grade varchar2) return varchar2 is v_chk varchar2(1); begin select case when regexp_like(in_grade,'^[0-4]\.([0-9]|[0-9]{2})$') then 'Y' else 'N' end into v_chk from dual; if v_chk = 'N' then return 'N'; end if; if to_number(in_grade) not between 0 and 4.5 then --가능한 평점대 지정 return 'N'; end if; return 'Y'; end;