Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Increment a number in a string in PL SQL loop

JodyApr 3 2017 — edited Apr 19 2017

In a loop I want to increment the last character which is a number as follows.

In the first loop the string will have a value of ABC_1. In the second loop it should have a value of ABC_2 until ABC_10.

Here is my code which does not work as I expect. Any help will be appreciated. Thank you!

v_cnt    NUMBER (2) := 0;
v_name   VARCHAR2 (50) := 'ABC_';

LOOP

v_cnt := v_cnt + 1;

EXIT WHEN v_cnt > 10;

v_name := v_name || v_cnt;

DBMS_OUTPUT.put_line ('v_name - ' || v_name);

END LOOP;

This post has been answered by Frank Kulash on Apr 3 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 2 2017
Added on Apr 3 2017
6 comments
15,098 views