What is the usage of ‘length’ in Oracle?
In Oracle, the LENGTH function is used to calculate the number of characters or bytes in a given string. Its syntax is as follows:
What is the size of the string?
In this case, the string is the string for which the length needs to be calculated.
There are several factors to consider when using the LENGTH function.
- The LENGTH function will return the byte count of a given string if it contains multi-byte characters such as Chinese. If the string only contains single-byte characters, it will return the character count.
- If the given string is NULL, the LENGTH function will return NULL.
Below are some examples:
The result is 5 because ‘Hello’ contains 5 characters.
The result of SELECT LENGTH(‘你好’) FROM dual; is 4, as ‘你好’ contains 2 Chinese characters, with each Chinese character occupying 2 bytes.
The result will be 11 because ‘Hello World’ contains 11 characters.
The result is NULL because the given string is NULL.