I encountered many problems when I used MySQL to write functions today. Now I will write down the problems and solutions.
1: in MySQL, a semicolon (-) is required for each row ,--!
Second, the result set cannot be returned in MySQL functions. therefore, select * From tablename and select column_name from tablename cannot be used. otherwise, the error not allowed to return aresult set from a function is reported. change the select XX into method ..
Third: error message :"This function has none of deterministic, no SQL, or reads SQL data in its declaration and binary"
we should have enabled bin-log, we must specify whether our function is
1 uncertain deterministic
2 No SQL statement, of course, the data will not be modified.
3 reads SQL data only reads data, of course, the data will not be modified.
4 modifies SQL data
5 contains SQL statements
In the function, only deterministic, no SQL, and reads SQL data are supported. If bin-log is enabled, we must specify a parameter for our function.
we can disable this by setting the following parameters.
set global log_bin_trust_function_creators = 1;
Last completedCodeAs follows:
Code
Create Definer = CURRENT_USER Function 'Func _ get_city_name '('cid' Int )
Returns Varchar ( 50 )
Begin
Declare Result Varchar ( 50 );
Set Result = '' ;
Select Region_name Into Result From Vsvt_region Where Region_id = CID;
Return Result;
End ;;