I wanna create a stored procedure to check if a sequence is with a given name is exist or no to create it or alter its value to max(Id) selected from given table name, So I create the below procedure but it throws a syntax error.
CREATE PROCEDURE EBPP_CORE.CREATE_OR_ALTER_SEQUENCE
@sequence_name VARCHAR2,
@table_name VARCHAR2
AS
BEGIN
DECLARE @MAX_ID_VAL NUMBER;
DECLARE @sequence_exist NUMBER;
SELECT @MAX_ID_VAL = CAST(ISNULL(MAX(id) + 1, 1) as nvarchar(10)) FROM @table_name ;
SELECT @sequence_exist = COUNT(*) FROM sys.sequences WHERE name = @sequence_name;
IF @sequence_exist>0
' ALTER SEQUENCE @sequence_name RESTART WITH @MAX_ID_VAL';
ELSE
'CREATE SEQUENCE @sequence_name START WITH @MAX_ID_VAL INCREMENT BY 1' ;
END