Concatenating Strings Results In Value Treated as a Literal Instead of a Variable. (Doc ID 1083793.1)

Last updated on JULY 05, 2017

Applies to:

PL/SQL - Version: 10.2.0.4 and later   [Release: 10.2 and later ]
Information in this document applies to any platform.

Symptoms

In this sample, there are two variables 'a1' and 'a2'.
The objective is to be able to pass in either a 1 or a 2 so that within the DBMS_OUTPUT.PUT_LINE call, either variable a1 or a2 will be displayed.
Instead, the variable is being treated like a literal 'a1' or 'a2' but the goal is to concatenate to build a variable then get its value.

create or replace procedure new_test (p1 number) is
   a1 number := 22;
   a2 varchar2(20) := 'Test';
begin
   dbms_output.put_line('a'||p1);
end;
/

SQL> execute new_test(1);
a1

Notice that the literal 'a1' is displayed instead of the 22 which is the value stored in the a1 variable.


SQL> execute new_test(2);
a2

Notice that the literal 'a2' is displayed instead of the value 'Test' which is the value stored in the a2 variable.


Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms