Oracle PL/SQL String Formatting
you can write it like this:
select first_name, last_name, f
||'-'
||substr(l, 1, length(l) - 1)
||upper(substr(l, -1)) code
from (select first_name, last_name,
initcap(rpad(substr(translate(first_name, 'xil', 'x'), 1, 6), 6,
'_')) f,
lpad(substr(translate(last_name, 'xil', 'x'),
greatest(-6, -length(translate(last_name, 'xil', 'x')))), 6,
'_')
l
from employees);
i've assumed you only wanted to replace i
and l
and not also I
and L
. translate will act the same as replace(replace(str, 'l', ''), 'i', '')
in this case.