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

141,006

Solution 1

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.

Solution 2

you need length() function

select length(customer_name) from ar.ra_customers

Solution 3

The length function will do it. See http://www.techonthenet.com/oracle/functions/length.php

Solution 4

Regarding to Your example

select length('Burger') from dual;

I hope this will help :)

Share:
141,006
OCB
Author by

OCB

The best way to predict the future is to create it https://business.sendperks.com

Updated on March 11, 2021

Comments

  • OCB
    OCB about 3 years

    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; 
    
  • Wayne
    Wayne about 8 years
    I have, on occasion, seen systems that pad with blank spaces to make data in a column uniform length and had to use LENGTH(TRIM()) to get actual value lengths.
  • Frank Schmitt
    Frank Schmitt about 7 years
    @Wayne That's usually the case for CHAR columns - CHAR columns are always padded to the defined length, whereas VARCHAR columns aren't.
  • Wayne
    Wayne about 7 years
    @FrankSchmitt I realize that but thought it might be helpful to some people since you don't need the white space when querying a CHAR and the data type is not always obvious without checking the schema.
  • jpmc26
    jpmc26 almost 6 years
    What about NCHAR and NVARCHAR2?