I try to alter the table using DB2 stored procedure. Below is my code. I found the issue in alter query. But that same query executed perfectly in DB2 command line editor. I want to run the same query using stored procedure. kindly help me.
CREATE PROCEDURE MODIFYAUTOINCRE()
SPECIFIC TEST
RESULT SETS 1
MODIFIES SQL DATA
LANGUAGE SQL
------------------------------------------------------------------------
-- SQL Stored Procedure
------------------------------------------------------------------------
P1: BEGIN
DECLARE v_max INTEGER DEFAULT 0;--
DECLARE stmt1 VARCHAR(100);
DECLARE stmt2 VARCHAR(100);
DECLARE name1 VARCHAR(100);
-- Declare cursor
DECLARE cursor1 CURSOR WITH RETURN FOR
SELECT MAX(LABEL_ID) FROM ESTORE.APPLICATION_LABELS;
-- Cursor left open for client application
OPEN cursor1;
FETCH cursor1 INTO v_max;
IF (v_max > 0 ) THEN
SET v_max=v_max+1;
SET stmt1= 'ALTER TABLE APTR.APPLICATION_LABELS ALTER COLUMN LABEL_ID SET GENERATED AS IDENTITY (START WITH '||v_max||' INCREMENT BY 1 NO CACHE);';
PREPARE name1 FROM stmt1;
EXECUTE IMMEDIATE name1;
commit;
END IF;
END P1
ERROR: An unexpected token "END-OF-STATEMENT" was found following "NTITY (START WITH 69". Expected tokens may include: ")".. SQLCODE=-104, SQLSTATE=42601, DRIVER=3.58.81