In SQL Server, you can use the T-SQL REPLACE()
function to replace all instances of a given string with another string. For example, you can replace all occurrences of a certain word with another word.
Tag: how to
Repeat a String Multiple Times in MySQL – REPEAT()
This article demonstrates how to repeat a string multiple times in MySQL using the REPEAT()
function.
As the name suggests, the REPEAT()
function can be used to repeat a string. More specifically, it allows you to specify how many times the string should be repeated.
How to Retain the Backslash when Escaping Quotes in MySQL – QUOTE()
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.
How to Get the Number of Bits in a String in MySQL – BIT_LENGTH()
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.
How to Find the ASCII Code for a given Character in MySQL
In MySQL, you can use the ASCII()
function to return the ASCII code for a given character. More specifically, it returns the ASCII code for the leftmost character in a given string.
You can also use ORD()
, which works the same way, except that it also supports multibyte characters.
How to Return the Unicode Value for a given Character in SQL Server – UNICODE()
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.
How to Return the ASCII Code Value for a given Character in SQL Server
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).
How to Convert Lowercase to Uppercase in SQL Server – UPPER()
In SQL Server, you can convert any lowercase string to uppercase by using the UPPER()
function.
To use it, simply pass the string as an argument when calling the function.
How to Convert Uppercase to Lowercase in SQL Server – LOWER()
In SQL Server, you can convert any uppercase string to lowercase by using the LOWER()
function.
Simply provide the string as an argument when you call the function, and it will be returned in lowercase form.
How to Convert Uppercase Characters to Lowercase in MySQL
In MySQL, you can use the LOWER()
function to convert any uppercase characters to lowercase. Alternatively, you can use the LCASE()
function, which is a synonym for LOWER()
.
The syntax goes like this:
LOWER(str)
Or…
LCASE(str)
Where str
is the string you want converted to lowercase.