Columns should not be read into variables smaller than the column
ZPA rule for PL/SQL and Oracle SQL · ColumnIntoSmallerVariable
A column read with SELECT … INTO, FETCH … INTO or RETURNING … INTO into a variable declared smaller than the column compiles, and raises ORA-06502 on the day a value longer than the variable arrives. Declaring the variable with the column's %TYPE keeps both sizes the same, also when the column changes.
This rule uses the table and view metadata read from the database, and reports nothing without it. A text or RAW variable is reported when its length is less than the column's, whatever unit each counts in. A number is reported when it has fewer digits before the point than the column: a smaller scale only rounds the value. A variable whose size is not written, or is written as an expression the analysis does not evaluate, is not reported.
Examples
-- crate.code is VARCHAR2(10)
declare
v_code varchar2(5);
begin
select code into v_code from crate where id = 1; -- Noncompliant
end;
declare
v_code crate.code%type;
begin
select code into v_code from crate where id = 1;
end;