All values matches the pattern.
with students (id, name, marks) as(
select 1, 'Ashley', 81 from dual union all
select 2, 'Samantha', 75 from dual union all
select 3, 'Belvet', 84 from dual union all
select 4, 'Julia' , 76 from dual)
SELECT *,
Name regexp "[a-z]{3}$" AS ordering_expression
FROM students
ORDER BY Name regexp "[a-z]{3}$" ASC;
id | name | marks | ordering_expression
-: | :------- | ----: | ------------------:
1 | Ashley | 81 | 1
2 | Samantha | 75 | 1
3 | Belvet | 84 | 1
4 | Julia | 76 | 1
So the rows are not sorted.
-- test 6-letter pattern
with students (id, name, marks) as(
select 1, 'Ashley', 81 from dual union all
select 2, 'Samantha', 75 from dual union all
select 3, 'Belvet', 84 from dual union all
select 4, 'Julia' , 76 from dual)
SELECT *,
Name regexp "[a-z]{6}$" AS ordering_expression
FROM students
ORDER BY Name regexp "[a-z]{6}$" ASC;
id | name | marks | ordering_expression
-: | :------- | ----: | ------------------:
4 | Julia | 76 | 0
1 | Ashley | 81 | 1
2 | Samantha | 75 | 1
3 | Belvet | 84 | 1
db<>fiddle here
'Ashley' should come first because 'ley' < 'lia'. – shiv_90
with students (id, name, marks) as(
select 1, 'Ashley', 81 from dual union all
select 2, 'Samantha', 75 from dual union all
select 3, 'Belvet', 84 from dual union all
select 4, 'Julia' , 76 from dual)
SELECT *
FROM students
ORDER BY RIGHT(Name, 3) ASC;
id | name | marks
-: | :------- | ----:
1 | Ashley | 81
4 | Julia | 76
2 | Samantha | 75
3 | Belvet | 84
db<>fiddle here