Code for custom functions:
drop FUNCTION IF EXISTS fn_hrstaffbase_getnamefromidcard
Delimiter//
CREATE FUNCTION Fn_hrstaffbase_getnamefromidcard (a VARCHAR ())
RETURNS VARCHAR ()
Begin
Return (SELECT staff_ name from hr_staff_base where idcard = a);
END//
-- ------------------------------------------------------------------------------------------------------------- --------
Function call Query:
Select Fn_hrstaffbase_getnamefromidcard (' 299012234225 ')
-- ------------------------------------------------------------------------------
It's all null,
Processing method:
When you create a new library, you must
You can also modify the database settings: Right-click the database, mouse to edit the database
To set up a database such as:
The original settings are:
The database can read only Latin values and cannot read Chinese
So the result of calling the function is:
-- ---------------------------------------------------------------
After you modify the database settings, the query results appear:
#################################################################################
Sometimes MySQL cannot build a custom function because the function 2 is not turned on
Enter show variables like '%func% '; Command
You will see the state of the log_bin_trust_function_creators, if it is off, the function of the custom function is closed
Input command set global Log_bin_trust_function_creators=1;
Log_bin_trust_function_creators can be turned on with custom function functions
However, this setting is a temporary scenario because the status will turn off after MySQL automatically restarts, so you need to
Add the "--log-bin-trust-function-creators=1" parameter when the service starts. Or add Log-bin-trust-function-creators=1 in the [mysqld] section of My.ini (MY.CNF).
MySQL Custom function call does not produce results