Initially there was a syntax error here:
returns Nombre_Nacionalidad;
The correct form is:
return Nombre_Nacionalidad;
Regarding the error:
#1418
- This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you might want
to use the less safe log_bin_trust_function_creators variable)
appeared once the syntax error has been corrected, it indicates that it is because you have activated the binary logging
mode.
The reference manual explains what it consists of :
The binary record contains information about SQL statements that
modify the content of the database. This information is
stores in the form of "events" that describe the modifications. The
Binary record has two important purposes:
-
For replication, the binary record is used on replication master servers as a record of the
statements that will be sent to slave servers. The server
master sends the events contained in its binary record to its
slaves, who execute those events to make the same changes
of data that was made in the teacher.
-
Certain data recovery operations require the use of the binary registry. After restoring a copy file of
security, the events in the binary register are executed again
that were recorded after the backup was made.
These events update the databases from the point of copy
security.
Keeping in mind that, the manual also indicates that you can put your query the following:
DETERMINISTIC
READS SQL DATA
That way you indicate that this function is deterministic (and does not modify the data), so it is safe.
The code would then be like this:
delimiter //
create function autor_nac(v_id int) returns NVARCHAR (50)
DETERMINISTIC
READS SQL DATA
begin
declare Nombre_Nacionalidad NVARCHAR (50);
set Nombre_Nacionalidad = (select CONCAT (nombre," ",nacionalidad) from autor
where id=v_id);
return Nombre_Nacionalidad;
end;
//
delimiter ;