Total Pageviews

December 29, 2017

12/29/2017 10:35:00 AM
Difference Between Char and Varchar2 in Oracle
Differences Between CHAR and VARCHAR2 Data Types
  • Predefined Subtypes
  • How Blank-Padding Works
  • Value Comparisons


CHAR and VARCHAR2 Blank-Padding Difference

In this example, both the CHAR variable and the VARCHAR2 variable have the maximum size of 10 characters. Each variable receives a five-character value with one trailing blank. The value assigned to the CHAR variable is blank-padded to 10 characters

  first_name  CHAR(10);
  last_name   VARCHAR2(10);
  first_name := 'Rama ';
  last_name  := 'Nyrk ';

  DBMS_OUTPUT.PUT_LINE('*' || first_name || '*');
  DBMS_OUTPUT.PUT_LINE('*' || last_name || '*');

*Rama      *
*Nyrk *
Value Comparisons
The SQL rules for comparing character values apply to PL/SQL character variables.

Whenever one or both values in the comparison have the data type VARCHAR2, nonpadded comparison semantics apply; otherwise, blank-padded semantics apply.
Related Posts Plugin for WordPress, Blogger...