The MySQL REPLACE() function enables you to replace all occurrences of a substring with another string. It allows you to do things like, replace all occurrences of one word with another word, etc.
This article demonstrates its usage.
The MySQL REPLACE() function enables you to replace all occurrences of a substring with another string. It allows you to do things like, replace all occurrences of one word with another word, etc.
This article demonstrates its usage.
Using a backslash to escape single quotes is a commonly used technique to ensure that the single quotes don’t interfere with MySQL‘s handling of the full string.
Single quotes are used to surround a string, so a single quote within the string itself could cause havoc if it isn’t properly escaped. Simply inserting a backslash immediately before the quote mark ensures that MySQL doesn’t terminate the string prematurely.
However, there may be occasions where you want the backslash to remain. For example, you might intend to use the string in an SQL statement, and therefore, you want it to be properly escaped first.
This is where the QUOTE() function comes in.
The MySQL QUOTE() function quotes a string to produce a result that can be used as a properly escaped data value in an SQL statement. The string is returned enclosed by single quotation marks and with each instance of backslash (\), single quote ('), ASCII NUL, and Control+Z preceded by a backslash.
MySQL has a number of string functions that return the position of a substring within a string. More specifically, they return the position of the first occurrence within the string (or the first occurrence after a given starting point).
The functions I’m referring to are as follows:
INSTR()LOCATE()POSITION()Below is an overview of each one.
MySQL has a BIT_LENGTH() function that allows you to get the length of a string, measured in bits.
This function is similar to the LENGTH() function, which returns the length of a string in bytes. The same is true for the OCTET_LENGTH() function, which is a synonym for the LENGTH() function.
One of the functions included in T-SQL is the UNICODE() function. You can use this function with SQL Server (and Azure) to return the Unicode value of a given character.
This function works similar to the ASCII() function, except that it returns the Unicode value.
If you ever need to find the ASCII code for a given character when using SQL Server, the T-SQL ASCII() function is probably what you need.
The ASCII() function returns the ASCII code value of the leftmost character of a character expression. Simply provide the character as an argument and SQL Server will return the ASCII value of that character (or the leftmost character in the string).