The TRIM() function cleans your data. It’s very easy. When specifying strings, you can specify characters and strings. It deletes every occurrence of that character.
The example shows how to clean the order ID:
SELECT id, order_id, TRIM(order_id, '&') AS order_id_trimmed FROM `orders.orders`;
Order id, character, and itself are some of the arguments in the function. There is a mysterious rationale for it to appear after order id. The data is now looked at after it has been cleaned.
This is a function that may be useful. The string is nullified so that the last character becomes the first, the second is the second, and so on and so forth.
It can be used if processing ID numbers are entered in reverse order. The ID numbers indicate that the first three digits of the user ID number, the order date, and the last two digits are the control numbers. Whenever a new system ID is created, it must be entered in reverse order. The REVERSE() function can reverse the user ID number sequence.
SELECT id, order_id, REVERSE(order_id) AS order_id_reversed FROM `orders.orders`;
The column I want to reverse is the only thing I have to say in the function. The result can be found here:
When you want to find out the character position of a specific substring inside a given text, this is the function you want to use. This helps when, for example, you’re writing a batch of email templates for customers and need to determine the position of “@“
SELECT id, customer, email, STRPOS(email, '@') AS at_position FROM `orders.orders`;
The first argument of a function is a string or a column value to search. Then you state the substring you’re looking for. In this case the function returns a positive integer, the position of the rightmost character.
|1||Jones & Son, Inc.||[email protected]||8|
|2||Jones & Son, Inc.||[email protected]||8|
|3||Stavros GmbH||[email protected]||9|
|4||Hendricks, Hendricks, Hoekstra||[email protected]||6|
|5||Mckenna & Partners||seckenna.com||7|
In the third test, the result is as follows, using the first email, “[email protected]“. It has seven characters in front of @, so that’s at position eight, which is precisely what the output shows.