I want to execute, in a stored procedure, a certain set of statements if, in table my_table there is exactly one row with value value in column column_name. I have tried the following, but I get a syntax error:
IF ((SELECT COUNT(*) FROM my_table WHERE column_name = value) = 1) THEN
BEGIN
END;
END IF;
For context: In my procedure I create a temporary table at some point, where I store a list of values. Then later on in the procedure, I want to check if a given value is present in that temporary table.
IFstatement in programming blocks such as stored procedures. You cannot write code this way.thenmissing.then, the syntax is correct and this code should work (if used correctly in a procedure, e.g. you added the delimiter and such). Adding the errormessage and more code (since that cannot be all there is, as it should not generate an error, so the problem will likely lie somewhere else) will be the next step to identify the problem.