SQL 在 plsql 循环中在 Oracle 中附加字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6456430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 11:05:50  来源:igfitidea点击:

Appending strings in Oracle within a plsql loop

sqloracleplsql

提问by help

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?

与任何编程语言一样,您可以使用简单的 =+ 附加到变量字符串,但是如何在 Oracle PlSql 块中执行此操作?

Example

例子

my_string string

my_string = 'bla';

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

expected output: bla12345678910

预期输出:bla12345678910

回答by Chandu

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;