Skip to main content

Use VARCHAR2 instead of CHAR and VARCHAR

ZPA rule for PL/SQL and Oracle SQL · CharacterDatatypeUsage

VARCHAR is today a synonym of VARCHAR2, but Oracle reserves it for a future type with different comparison semantics: code declared with it may change behavior. CHAR pads every value with spaces to its length, so a value read into a VARCHAR2 or compared with one carries the padding, and comparisons and searches behave unexpectedly.

This rule reports a declaration of type CHAR or VARCHAR. Use VARCHAR2.

Examples​

Noncompliant Code Example
declare
l_code char(10); -- Noncompliant
l_label varchar(30); -- Noncompliant
begin
select code, label into l_code, l_label from crate where id = 42;
end;
Compliant Solution
declare
l_code varchar2(10);
l_label varchar2(30);
begin
select code, label into l_code, l_label from crate where id = 42;
end;