MySQL Error 1415 - mysql

I'm currently coding somewhat on MySQL and got a FUNCTION.
For me the code looks fine, but MySQL throws a
Error Code: 1415
Not allowed to return a result set from a function
Error.
Function:
Cick here, pastebin.com
As i said, i dont see any syntax error in it and simply cant understand why its throwing an Error. Only on execution though, creates without any problems.
I googled already, and haven't found anything helping my on this, so i hope you can.
Thanks in advice.

I replaced all the other functions referenced in your new function with ROUND(RAND()) and it ran fine; Could it be that one of those functions might be trying to return a result set?

Related

Cannot find MySQL syntax error

MySQL gives me syntax error for a simple query but I don't see any error. If you guys find any please help.
insert into cast(sid,celeb_id,type,name,prior)
values(30,1,1,'James Keziah Delaney',2)
It gives sql syntax error near cast.
The main cause of this error is that there is a function Cast in mysql.
It look like to call the cast() function.
You can choose one of the solutions to solve it.
add ` to contain cast table name
look like this.
insert into `cast`(sid,celeb_id,type,name,prior) values(30,1,1,'James Keziah Delaney',2)
sqlfiddle
add a space between cast and ( let mysql know you did't want to execute Cast method. thank for #Barmar remind.
Note:
I would suggest you don't give the table name from keyword or function name.
You can't insert into cast(). It requires a list of column names.

Syntax error when trying to create a database with name: 9e1617bafr1_1

yesterday I stumbled upon a weird problem.
I have a PHP script that creates mysql databases for me based of some input.
When the script tried to generate a database with the name "9e1617bafr1_1" (without quotes) and I got this error "MySQL Error 1064: You have an error in your SQL syntax".
Query is CREATE DATABASE IF NOT EXISTS 9e1617bafr1_1
I also get the error when trying to execute it on https://de.piliapp.com/mysql-syntax-check/ and http://sqlfiddle.com/
I resolved it by using backticks before and after the database name but I'm still wondering why I got this error in the first place as the creation of "9d1617bafr1_1", "9f1617bafr1_1" and so on worked flawlessly.
Unfortunately I did not find anything useful on this behavior on the internet and as I'm very curious about it I wanted to ask if anybody know if this is a reserved word or if it violates the SQL standard in any way?
9e1617bafr1_1 is parsed as number (9e1617) followed by a character string (bafr1_1). Your other attempts, "9d1617bafr1_1", and "9f1617bafr1_1", don't start with scientific notation, so they don't get parsed that way.

Why error occurs when creating the trigger?

I am trying to add a trigger through phpmyadmin 4.4
I get the error:
Why is this happening? How to declare a variable?
Start with BEGIN, end with END. Put the various statements between them.
Notice in the error how it is alread providing FOR EACH ..., but it is depending on you to do the rest. See http://dev.mysql.com/doc/refman/5.7/en/triggers.html (and other pages) for the complete syntax that phpmyadmin is "helping" you generate.

How do i output an SQL Error in MySQL

I've declared an handler which will handle SQLEXCEPTION, in the clean up code i had it do SELECT 'My Handle';, i ran a script that fails because of a primary key violation and it worked cause i got my output.
the problem with DECLARE ... HANDLE FOR SQLEXCEPTION is that when there is an error it will run though it's doesn't say what error triggered it, so i want to output the error
How do i output the SQL Error using a MySQL Query, i don't care if i can only output the error code/id i just need something to output giving me an indication on what the error is so i can fix the problem
EDIT: in case if it's not obvious, this code is in an SQL Procedure
There is nothing in the DECLARE HANDLER documentation on this functionality. You could handle the errors MySQL returns to your application and print or log them that way.
I actually haven't used any handles, but i think you can make your code into a stored procedure and then run the stored procedure!! You might find MySQL accepts what you are trying to do then.

Cannot use a MySQL UDF function

I have loaded an UDF function into MySQL (without having selected any particular DB). It used to work well during my session but now I get the error "ERROR 1305 (42000): FUNCTION currentdatabase.myfunction does not exist" when I try to use the function with the following sql statement :
select myfunction('aaa');
I then tried to drop the function and I got the same error code :
mysql> drop function myfunction;
ERROR 1305 (42000): FUNCTION database.myfunction does not exist
if a DB is selected.
Another error code otherwise :
ERROR 1046 (3D000): No database selected
So I decided to specify again the function and I got the following error code :
CREATE FUNCTION myfunction RETURNS INT SONAME 'myfunction.so';
ERROR 1125 (HY000): Function 'myfunction' already exists
My question is: how to use again my function ?
Thanks in advance.
Note: there is no space problem like ("select myfunction ('aaa');") as reported on several other websites.
I recently encountered this issue my self and I put together a quick blog post about it:
When installing a UDF recently I got an
annoying error message, which didn't seem to want to go away. Deleting
the function before attempting to remove it did not work so I used the
following set of escalating commands to attempt to get it to
install. But back to the error for a moment:
bash > mysql -u user -p < installdb.sql
Enter password:
ERROR 1125 (HY000) at line 7: Function 'lib_mysqludf_ssdeep_info' already exists This can be
solved really simply with the following options:
Attempt
to delete the function and then reinstall it Delete the
function row from the mysql.func table and then reinstall it
Stop the MySQL server (after trying option 2), start it again and
then reinstall it
From my testing you do not need to have backups of your binary database files as #jmcejuela suggests in his answer.
Source: http://simonholywell.com/post/2012/01/mysql-udf-install-error-function-already-exists.html
I believe the problem comes from removing the .so library before dropping the function/s. The server still believes it has the functions since they appear in SELECT * FROM mysql.func but of course calling these functions fail. Somehow DROP doesn't simply remove entries in this table but also checks whether the libraries are found which makes this fail. CREATE supposedly just check first the func table which makes this fail...
The solution is to restore the func table (func.MYI, func.MYD, func.frm files under your mysql's data/mysql) to the point everything matches.
Luckily I had a backup of these files. Otherwise you will have to backup them from a new mysql installation (you could simply install locally a new server not to remove your current one)
Bottom line: do not remove the .so libraries before dropping the functions.
Got some of these errors when swapping out (not dropping) the .so library before dropping the function(s).
Restarting the server eliminated the error messages, whether the functions were successfully dropped or not. Mysqld just looked at the mysql.func table and loaded functions from the (new) .so. I know restarting the server is not always an option, but if it is, it's fast and complete.