Hi Sree,
I have created a stored procedure to count the number of words in a string, hope it will help you!
REPLACE PROCEDURE SAMPLES.WordCount
(
IN InputString VARCHAR(4000) ,
OUT WCount INT
)
BEGIN
DECLARE Indexs INT;
DECLARE Charss CHAR(1);
DECLARE PrevChar CHAR(1);
DECLARE WordCntt INT;
SET Indexs = 1;
SET WordCntt = 0;
WHILE Indexs <= CHARACTER_LENGTH(InputString)
DO
BEGIN
SET Charss = SUBSTR(InputString, indexs, 1);
SET PrevChar = CASE WHEN INDEXs = 1 THEN ''
ELSE SUBSTR(InputString, INDEXs - 1, 1)
END;
IF PrevChar = '' AND Charss <> ''
THEN SET WordCntt = WordCntt + 1;
END IF;
SET Indexs = Indexs + 1;
END;
END WHILE
;
SET WCount = WordCntt;
END;
Hi Sree,
I have created a stored procedure to count the number of words in a string, hope it will help you!