There are several errors in your code.
First, if you are trying to create a stored procedure, remove everything that is before the CREATE OR REPLACE PROCEDURE command.
Second, every variable that is going to be referenced in the stored procedure code needs to be declared inside the procedure (as a variable or as a parameter), so using variable names that were declared outside the procedure (with the DECLARE command) will cause an error.
I think there are more errors, but they are difficult to identify because of the bad formatting of the code.
If you need further help, please post the complete error messages you get and post your code using the editor’s CODE tool.