0

I am creating a function that contains the following loop:

    While v_start >= v_stop do
    set v_msg := concat(v_msg,v_start,v_delimiter);
    set v_start := v_start + v_step;
    end while;

When I call the function, I pass the following parameter:

    select a06_counter_loop(10,-5, -3, '-->') as 'The Loop Output';

It should return:

    10-->7-->4-->1-->-2-->-5

But it returned:

    10-->7-->4-->1-->-2-->-5-->

My question is that how do I get rid of the last non-number character?

Let me know if you need the entire code for the function.

Thanks, Perri

2 Answers 2

1
    set v_msg := v_start;
    set v_start := v_start + v_step;
    While v_start >= v_stop do
       set v_msg := concat(v_msg,v_delimiter, v_start);
       set v_start := v_start + v_step;
    end while;
Sign up to request clarification or add additional context in comments.

Comments

1

Try this by using CONCAT_WS(separator,str1,str2,...)

While v_start >= v_stop do
set v_msg := CONCAT_WS(v_delimiter,v_msg,v_start);
set v_start := v_start + v_step;
end while;

Demo

1 Comment

Thanks, but I cannot change the order of the parameters getting passed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.