LENGTH function

LENGTH returns the length of a string. The returned value is the number of the characters in a string. The general format for this function is:

LENGTH(string)

SQL> SELECT LENGTH('this is a test') FROM dual;

LENGTH('THISISATEST')
---------------------
                   14

SQL>

The following query gets the length of the employee's name:


CREATE TABLE EMP (EMPNO NUMBER(4) NOT NULL,
                      ENAME VARCHAR2(10),
                      HIREDATE DATE);

INSERT INTO EMP VALUES (1, 'SMITH', TO_DATE('17-DEC-1980', 'DD-MON-YYYY'));
INSERT INTO EMP VALUES (2, 'ALLEN', TO_DATE('20-FEB-1981', 'DD-MON-YYYY'));
INSERT INTO EMP VALUES (3, 'WARD',  TO_DATE('22-FEB-1981', 'DD-MON-YYYY'));
INSERT INTO EMP VALUES (4, 'JONES', TO_DATE('2-APR-1981',  'DD-MON-YYYY'));
INSERT INTO EMP VALUES (5, 'MARTIN',TO_DATE('28-SEP-1981', 'DD-MON-YYYY'));


SQL> select ename, length(ename) from emp;

ENAME      LENGTH(ENAME)
---------- -------------
SMITH                  5
ALLEN                  5
WARD                   4
JONES                  5
MARTIN                 6

SQL>
Home »
Oracle »
String Functions » 

LENGTH:
  1. LENGTH function
  2. Length of a number
Related: