I want to remove two plus(+) sign from phone number field and add just one plus sign.
For eg: The phone number can be in any of these formats:
(+) (+911) 24234324324324
++091787534 5303
(++91) 9711931220`
Desired Output:
(+911) 24234324324324
+091787534 5303
(+91) 9711931220`
Below is the query that I am using
**replace((TRIM(LEADING '0' FROM (REGEXP_REPLACE(channel_value, '[]\[!@#$%.&*~^_{}:;<>/\|()+-]', '')))),' ' ,'')**
Waiting for your suggestions.
Thank you.
2
Answers
To achieve your desired output in SQL, you can use a combination of string manipulation functions and regular expressions. Here’s how you can modify your query:
This query checks the format of the phone number in the channel_value column. If it starts with two ‘+’ signs, it removes one. If it starts with a single ‘+’ sign, it keeps it as is. If it doesn’t start with a ‘+’, it adds one at the beginning. This way, you achieve your desired output format directly in SQL.
replace this pattern:
(()?(?:+)?s?(?){2}
with:
$1+
fiddle