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>--   w  w  w .  j a va  2s  . c o  m
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  w  w. j  av  a 2  s  .c om
  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