Oracle PL/SQL - Trim CHAR and VARCHAR2 Value

Introduction

To strip trailing blanks from a character value before assigning it to a variable or inserting it into a column, use the RTRIM function.

Demo

SQL>
SQL> DROP TABLE t;

Table dropped.-- from w  w  w  .  ja va  2s . c om

SQL> CREATE TABLE t (c CHAR(3 CHAR));
SQL>
SQL> DECLARE
  2    c VARCHAR2(3 CHAR);
  3  BEGIN
  4    c := RTRIM('abc  ');
  5    INSERT INTO t(c) VALUES(RTRIM('abc  '));
  6  END;
  7  /

PL/SQL procedure successfully completed.

SQL>
SQL> select * from t;

C
---
abc

1 row selected.

SQL>

Related Topic