HANA SQL function to split a comma delimited string into substrings

2.7k views Asked by At

I have the following HANA Procedure:

CREATE PROCEDURE SP_LIT()
AS

BEGIN
DECLARE count INT;
DECLARE pos INT;
DECLARE value NVARCHAR(100);

value := 'R,A';


IF LENGTH(:value) > 0 THEN

    value := :value + ',';
    pos   := LOCATE(:value,',',1);
END IF;
    WHILE :pos > 0 DO
    BEGIN
        INSERT INTO [O/P table] VALUES (LEFT(:value,:pos-1));
        value := RIGHT(:value, LENGTH (:value)-:pos);
        pos := LOCATE(:value,',',1);

    END;
    END WHILE;
END;

Everything seems fine but on execution the following error is thrown:

Error: invalid number exception: invalid number: not a valid number string 'R,A'

Any idea where am I going wrong?

1

There are 1 answers

0
Muskaan On

I found the solution. The '+' sign in concatenation should be replaced by '||' pipe operator.