Introduction

CHAR(N) where N is the maximum number of characters.

If the actual value is shorter than the defined length, Oracle pads the value with blanks to reach the required length.

You can declare this data type as shown here:

declare
       variable1_tx CHAR(number of characters);
       ...

In SQL, the maximum length of the CHAR data type is limited to 2,000 whereas in PL/SQL, the maximum length is 32,767 bytes.

Demo

SQL>
SQL>-- ww w.  j a  v  a 2s. c om
SQL> declare
  2      v_tx char(5);
  3  begin
  4      v_tx:='A';
  5      DBMS_OUTPUT.put_line(length(v_tx));
  6      DBMS_OUTPUT.put_line('<'||v_tx||'>');
  7      v_tx:='A  ';
  8      DBMS_OUTPUT.put_line(length(v_tx));
  9      DBMS_OUTPUT.put_line('<'||v_tx||'>');
 10  end;
 11  /
5
<A    >
5
<A    >

PL/SQL procedure successfully completed.
SQL>

Use char in if statement

Demo

SQL>
SQL> declare--   w  ww. j  a  va  2s.  com
  2       v_tx char(5);
  3  begin
  4       v_tx:='A';
  5       if v_tx = 'A' and v_tx = 'A   '
  6       then
  7           DBMS_OUTPUT.put_line('Equal!');
  8       end if;
  9   end;
 10  /
Equal!

PL/SQL procedure successfully completed.

SQL>

The output shows that the total length is 5 characters with 4 blanks on the right.

Related Topic