Oracle trigger for Phone formatting -


previous question: oracle trigger update phone numbers

if old value has '-' in position 10, still adds it.
how fix code not that?

create or replace trigger fix_cell_phone    before insert or update on clients_and_facilitators   each row  begin      -- cell numbers     if substr(:new.cli_second_address_desc, 1, 2) = '1-'        :new.cli_second_address_desc :=                             substr(:new.cli_second_address_desc, 1, length(:new.cli_second_address_desc)-4)                             || '-'                             || substr(:new.cli_second_address_desc, length(:new.cli_second_address_desc)-3);     end if;  end fix_cell_phone;  

you can change '-' concatenation use case statement conditionally concatenate dash if 1 not exist in tenth position. replace assignment statement column with:

substr(:new.cli_second_address_desc, 1, length(:new.cli_second_address_desc)-4)  || case when substr(:new.cli_second_address_desc, 10, 1) <> '-' '-' end  || substr(:new.cli_second_address_desc, length(:new.cli_second_address_desc)-3) 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -