Oracle LENGTHB() Function
The Oracle (PL/SQL) LENGTHB() function returns the length of the specified string. It calculates length using bytes instead of characters. If the specified string is NULL, then this function returns NULL.
Syntax
LENGTHB(string)
Parameters
string |
Required. Specify the string to return the length for. It can be any of the datatypes CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. |
Return Value
Returns the length of the specified string measured in bytes.
Example 1:
The example below shows the usage of LENGTHB() function.
LENGTHB('12345') Result: 5 LENGTHB('ABCDE') Result: 5 LENGTHB(12345) Result: 5 LENGTHB('AlphaCodingSkills') Result: 17 LENGTHB('Alpha Coding Skills') Result: 19 LENGTHB(NULL) Result: NULL LENGTHB('') Result: NULL LENGTHB(' ') Result: 1
Example 2:
Consider a database table called Employee with the following records:
EmpID | Name | City | Age | Salary |
---|---|---|---|---|
1 | John | London | 25 | 3000 |
2 | Marry | New York | 24 | 2750 |
3 | Jo | Paris | 27 | 2800 |
4 | Kim | Amsterdam | 30 | 3100 |
5 | Ramesh | New Delhi | 28 | 3000 |
6 | Huang | Beijing | 28 | 2800 |
The statement given below can be used to get the length of records of City column (measured in bytes).
SELECT Employee.*, LENGTHB(City) AS LENGTHB_Value FROM Employee;
The query will produce the following result:
EmpID | Name | City | Age | LENGTHB_Value |
---|---|---|---|---|
1 | John | London | 25 | 6 |
2 | Marry | New York | 24 | 8 |
3 | Jo | Paris | 27 | 5 |
4 | Kim | Amsterdam | 30 | 9 |
5 | Ramesh | New Delhi | 28 | 9 |
6 | Huang | Beijing | 28 | 7 |
❮ Oracle Functions