Hi
I'm facing a problem creating a procedure doing exactly what is in the subject.
Basically what I would like to do is :
alter sequence my_sequence RESTART select max(my_id) from mytable;
But I figured it can't be that simple. Indeed this doesn't work. So I made a simple procedure :
CREATE PROCEDURE upd_my_seq()
DEFINE max_my_id DECIMAL(19,0);
SELECT MAX(my_id) INTO max_my_id FROM my_table;
ALTER SEQUENCE my_sequence RESTART max_my_id;
END PROCEDURE ;
Unfortunately it didn't work either (procedure compiling error):
201: A syntax error has occurred.
Eventually I managed to compile a correct and more sophisticated procedure :
CREATE PROCEDURE upd_my_seq()
DEFINE max_my_id INTEGER;
DEFINE req VARCHAR;
SELECT MAX(my_id) INTO max_my_id FROM my_table;
LET req = "ALTER SEQUENCE my_sequence RESTART ?";
PREPARE prep_req FROM req;
DECLARE cur_maxid CURSOR FOR prep_req;
OPEN cur_maxid USING max_my_id;
FETCH prep_req;
END PROCEDURE;
Now this procedure compiles ok. But once again I have an error when executing the procedure :
201: A syntax error has occurred. :confused:
Does anyone has an idea ?
Thanks
I'm facing a problem creating a procedure doing exactly what is in the subject.
Basically what I would like to do is :
alter sequence my_sequence RESTART select max(my_id) from mytable;
But I figured it can't be that simple. Indeed this doesn't work. So I made a simple procedure :
CREATE PROCEDURE upd_my_seq()
DEFINE max_my_id DECIMAL(19,0);
SELECT MAX(my_id) INTO max_my_id FROM my_table;
ALTER SEQUENCE my_sequence RESTART max_my_id;
END PROCEDURE ;
Unfortunately it didn't work either (procedure compiling error):
201: A syntax error has occurred.
Eventually I managed to compile a correct and more sophisticated procedure :
CREATE PROCEDURE upd_my_seq()
DEFINE max_my_id INTEGER;
DEFINE req VARCHAR;
SELECT MAX(my_id) INTO max_my_id FROM my_table;
LET req = "ALTER SEQUENCE my_sequence RESTART ?";
PREPARE prep_req FROM req;
DECLARE cur_maxid CURSOR FOR prep_req;
OPEN cur_maxid USING max_my_id;
FETCH prep_req;
END PROCEDURE;
Now this procedure compiles ok. But once again I have an error when executing the procedure :
201: A syntax error has occurred. :confused:
Does anyone has an idea ?
Thanks