If SUBSTR(COD_ID,8) is number THEN substr(COD_ID,1,2)||'-'||
REPLACE(LTRIM(REPLACE(SUBSTR(COD_ID,3),'0',' ')),' ','0')
If SUBSTR(COD_ID,8) is alphanumeric THEN SUBSTR(COD_ID,8)
If I create 2 oracle view seems that I get correct output:
create or replace view v_cod (cod_id)
as
select substr(cod_id,8) cod_id
from tab_id
create or replace view v_cod_id (cod_id)
as
select substr(COD_ID,1,2)||'-'||
REPLACE(LTRIM(REPLACE(SUBSTR(COD_ID,3),'0',' ')),' ','0') cod_id
from v_cod
where cod_id > '00000000'
AND cod_id < '99999999'
union all
select substr(COD_ID,1,2)||'-'||
REPLACE(LTRIM(REPLACE(SUBSTR(COD_ID,3),'0',' ')),' ','0') cod_id
from v_cod
where COD_ID not between '00000000' and '99999999'
But I must create Just one view
Can I create only one Oracle View (from TAB_ID) to get this output?
SQL> select code_id,
(case
when ascii(substr(code_id,8,1))>= 48 and
ascii(substr(code_id,8,1)) <= 57 then
(substr(code_id,8,2)||'-'||to_char(to_number(substr(code_id,-6))))
else substr(code_id,-8)
end) newstr
from my_table;
Bookmarks