Delimiter //
/**
 * Author:  armen
 * Created: 28 fév 2018
 */
drop function if exists CASH_BUSINESS_CONVERT_PHONE_NUMBER_TO_NUMERIC //

Create Function CASH_BUSINESS_CONVERT_PHONE_NUMBER_TO_NUMERIC(
		phoneNumber varchar(45)
	)
	returns varchar(15)
Begin
	return Substring( 
            replace(
                replace(
                    replace(
                        replace(
                            replace(
                                replace(
                                    replace(
                                        replace(
                                            replace(
                                                replace(
                                                    Coalesce(phoneNumber, '')
                                                    , ' ', ''
                                                )
                                                , '.', ''
                                            )
                                            , '-', ''
                                        )
                                        , ':', ''
                                    )
                                    , '/', ''
                                )
                                , ',', ''
                            )
                            , ';', ''
                        )
                        , '(', ''
                    )
                    , ')', ''
                )
                , '|', ''
            )
            , 1, 15
        )
	;
End //
Delimiter ;
