Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make use of SQL (Oracle) to count the size of a string?

i was wondering if there was a function in Oracle to count the number of character size in Oracle, i.e. given "Burger", the SQL returns 6.

i.e. select XXX('Burger') from DUAL;  
like image 218
Oh Chin Boon Avatar asked Jul 04 '11 08:07

Oh Chin Boon


People also ask

How do I count strings in Oracle SQL?

The Oracle REGEXP_COUNT function is used to count the number of times that a pattern occurs in a string. It returns an integer indicating the number of occurrences of a pattern. If no match is found, then the function returns 0.

How do I count the length of a text in SQL?

SQL Server LEN() FunctionThe LEN() function returns the length of a string. Note: Trailing spaces at the end of the string is not included when calculating the length. However, leading spaces at the start of the string is included when calculating the length. Tip: Also look at the DATALENGTH() function.

How do you find the length of a string in PL SQL?

The PLSQL LENGTH function is used for returning the length of the specified string, in other words, it returns the length of char. The char accepted by the LENGTH function in PLSQL can be of any of the datatypes such as CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB.


2 Answers

You can use LENGTH() for CHAR / VARCHAR2 and DBMS_LOB.GETLENGTH() for CLOB. Both functions will count actual characters (not bytes).

See the linked documentation if you do need bytes.

like image 188
Álvaro González Avatar answered Sep 21 '22 13:09

Álvaro González


you need length() function

select length(customer_name) from ar.ra_customers 
like image 21
heximal Avatar answered Sep 19 '22 13:09

heximal