SQL Tutorial SQL Advanced SQL Database SQL References

Oracle LENGTHC() Function



The Oracle (PL/SQL) LENGTHC() function returns the length of the specified string. It calculates length using Unicode complete characters. If the specified string is NULL, then this function returns NULL.

Syntax

LENGTHC(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, using Unicode complete characters.

Example 1:

The example below shows the usage of LENGTHC() function.

LENGTHC('12345')
Result: 5

LENGTHC('ABCDE')
Result: 5

LENGTHC(12345)
Result: 5

LENGTHC('AlphaCodingSkills')
Result: 17

LENGTHC('Alpha Coding Skills')
Result: 19

LENGTHC(NULL)
Result: NULL

LENGTHC('')
Result: NULL

LENGTHC(' ')
Result: 1

Example 2:

Consider a database table called Employee with the following records:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

The statement given below can be used to get the length of records of City column (using Unicode complete characters).

SELECT Employee.*, 
LENGTHC(City) AS LENGTHC_Value 
FROM Employee;

The query will produce the following result:

EmpIDNameCityAgeLENGTHC_Value
1JohnLondon256
2MarryNew York248
3JoParis275
4KimAmsterdam309
5RameshNew Delhi289
6HuangBeijing287

❮ Oracle Functions