Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appending strings in Oracle within a plsql loop

Tags:

sql

oracle

plsql

Like any programming language you can use a simple =+ to append to a variable string, but how do you do that within an Oracle PlSql block?

Example

my_string string

my_string = 'bla';

while ...(not greater than 10)
my_string += 'i';

expected output: bla12345678910

like image 966
help Avatar asked Jun 23 '11 15:06

help


People also ask

How do I concatenate in Oracle SQL?

There are two ways to concatenate Strings in Oracle SQL . Either using CONCAT function or || operator. SELECT CONCAT( string1, string2 ) FROM dual; Since CONCAT function will only allow you to concatenate two values together.

What is the concatenation operator in PL SQL?

The || Operator in PLSQL is used to concatenate 2 or more strings together. The result of concatenating two character strings is another character string.


1 Answers

Concatenation operator is || However, there is not short form of the concatenation that you are looking for (i.e. +=).

You can try this:

DECLARE
 lvOutPut VARCHAR2(2000);
BEGIN
    lvOutPut := 'BLA';
    FOR i in 1..10 LOOP
        lvOutPut := lvOutPut || i;
    END LOOP;
    DBMS_OUTPUT.PUT_LINE(lvOutPut);
END;
like image 193
Chandu Avatar answered Oct 17 '22 21:10

Chandu