Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2014
    Posts
    1

    Unanswered: String concatenation in DB2 Stored Procedures

    I have a DB2 stored procedures to get n number of sequence values and then combine them into a single comma delimited string and return it. The concat function in the stored procedure is not working as expected.

    Code:
    CREATE PROCEDURE REFWTX.GET_SEQ_VALUES (in numb integer, OUT SEQVALUES VARCHAR(10000))
    LANGUAGE SQL
    SPECIFIC GET_SEQ_VALUES
    BEGIN
    DECLARE SEQ_VAL Integer;
    DECLARE CUR_COUNT INTEGER;
    SET CUR_COUNT=1;
    WHILE (CUR_COUNT <= numb) DO
    SELECT NEXTVAL FOR REFWTX.ACK_999_INTR_CTRL_NO_SEQ INTO SEQ_VAL FROM SYSIBM.SYSDUMMY1;
    set SEQVALUES = SEQVALUES|| ',' || CHAR(SEQ_VAL);
    SET CUR_COUNT=CUR_COUNT+1;
    END WHILE;
    return;
    END
    The portion of the procedure:

    Code:
    set SEQVALUES = SEQVALUES|| ',' || CHAR(SEQ_VAL);
    is not working as expected. How do I concatenate strings in stored procedures?

  2. #2
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    It should work. Post here the results you are getting.

    I would change CHAR(SEQ_VAL) with VARCHAR(SEQ_VAL).
    Florin Aparaschivei
    DB2 9.7, 10.5 on Windows
    Iasi, Romania

  3. #3
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    is not working as expected.
    I agree with aflorin27
    Post here the results you are getting.
    Or, did you received error message?


    Anyway,
    what result do you get, if you initialize SEQVALUES before the WHILE loop.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •