When I make a query within a function to assign the result to a variable, if the query does not return anything, does it save a null value?

0
SELECT c.horas_aportadas
INTO horas_aportadas_coordinador
FROM voluntario c
WHERE new.id_coordinador = c.nro_voluntario;

In that code, the id_coordinador is an attribute that can be null, so if it is then the query does not return anything, and what I want to know is that it is saved in the variable horas_aportadas_coordinador . Do you save a null value, or do you keep the value that I assign by default when you create it (When you create the variable, assign it a -1)?

    
asked by Guido Modarelli 20.10.2018 в 19:11
source

1 answer

0

Even if you have assigned something to the variable; if you then execute a query that does not bring results, the null value will remain in it, overwriting the pre-existing value. a solution would be to use ISNULL or what your RDBMS supports so if the result is null, keep the previous value)

    
answered by 21.10.2018 / 00:37
source