Skip to content
Advertisement

Error in Firebird Procedure

I have to do one query to get one parameter (I need a “1”), but this parameter can be in different cells, for example:

I have to capture and after, if its equals to one do other query to get what I want. I try to do a procedure with this code:

When execute the query apears this error:

I try to it works deleting the FOR and Do, appears this error:

Someone can help me with this procedure or explain me what is failing?

Advertisement

Answer

If you want to use a FOR SELECT .. DO (or a singleton select) in Firebird stored procedures, then you need to use INTO to populate parameter values.

See also the Firebird reference on FOR SELECT:

  • requires an INTO clause that is located at the end of the SELECT ... FROM ... specification. In each iteration of the loop, the field values in the current row are copied to the list of variables specified in the INTO clause. [..]

In other words, depending on what this stored procedure is meant to do, you need to declare additional return variables or local variables to hold the relevant fields of the select, for example:

However you can simplify this a lot by doing that logic within the select statement:

The reverse order is only to preserve the same logic as you had in your original snippet. Technically, to preserve that logic, it would need extra handling to preserve the previous value of total as the code you wrote would do, but I assume that is a bug in your code.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement