I'm trying to create a sequence inside an anonymous block (it's an script that will be launched on several environments) and I'm using execute immediate, this is the code:
SELECT MAX(ID_VINCULACION)
INTO vMAX_VINCULACION
FROM SA_ENTIDADES_VINCULADAS;
EXECUTE IMMEDIATE 'CREATE SEQUENCE "GPP"."SEQ_ENTIDADES_VINCULADAS" MINVALUE 1 MAXVALUE 99999999999999999999999999 INCREMENT BY 1 START WITH ' || vMAX_VINCULACION || ' NOCACHE NOORDER NOCYCLE NOKEEP NOSCALE GLOBAL';
I'm using the select max for start with so i can get the biggest existing ID, but it is throwing this error:
ORA-00933: SQL command not properly ended ORA-06512: at line 40 ORA-06512: at line 40
I don't exactly know why, so I tried to use the Execute Immediate ... Using, this is the resulting code:
SELECT MAX(ID_VINCULACION)
INTO vMAX_VINCULACION
FROM SA_ENTIDADES_VINCULADAS;
EXECUTE IMMEDIATE 'CREATE SEQUENCE "GPP"."SEQ_ENTIDADES_VINCULADAS" MINVALUE 1 MAXVALUE 99999999999999999999999999 INCREMENT BY 1 START WITH :a NOCACHE NOORDER NOCYCLE NOKEEP NOSCALE GLOBAL' USING vMAX_VINCULACION;
And this one throws another error... :
ORA-01722: invalid number
I don't get this one either, as the Max function returns a number. I have tried launching the query and it returns a 5.
So I'm pretty lost here, hope you can help me.
Thanks in advance.
EXECUTE IMMEDIATE
is intended for statements without parameters. – jarlh