I want to delete part of a string found in a particular field.
For example, the entry in the field could be "01365320APS". The "APS" is what I am looking at deleting.
My question is, should I use:
SELECT SUBSTRING_INDEX('fieldname','APS', 1)
SQL Server TRIM() Function The TRIM() function removes the space character OR other specified characters from the start or end of a string. By default, the TRIM() function removes leading and trailing spaces from a string.
We can remove part of the string using REPLACE() function. We can use this function if we know the exact character of the string to remove. REMOVE(): This function replaces all occurrences of a substring within a new substring.
Use the MySQL REPLACE() function to replace a substring (i.e. words, a character, etc.) with another substring and return the changed string. This function takes three arguments: The string to change.
Syntax: SELECT SUBSTRING(column_name,1,length(column_name)-N) FROM table_name; Example: Delete the last 2 characters from the FIRSTNAME column from the geeksforgeeks table.
When you want to edit a field, you need an UPDATE
statement:
UPDATE table SET fieldname=REPLACE(fieldname,'APS','')
REPLACE
is a string function that replaces every occurence of the 2nd string in the 1st string with the 3rd one.
Please try this with a WHERE
clause first, to see if it is really what you want to do.
For every occurrence of APS, try this:
UPDATE table SET column=REPLACE(column,'APS','');
Reference: http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_replace
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With