creating stored procedure in ubuntu terminal - mysql

I am trying to create stored procedures in mysql. I am doing it on terminal (ubunutu).
But when I am adding ; before end it executes all lines and throw an error .
I am trying to write
create procedure test()
-> begin
-> select * from salary;
I am unable to add end in last and it executeds and got this error
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right
syntax to use near '' at line 3.
Is this a right way to write stored procedure in terminal ?
Can I write stored procedure on separate file?
Then how can I execute that stored procedure written in file ?

fortunately i found a way to write a stored procedures on terminal
http://alextsilverstein.com/programming-and-development/mysql/mysql-the-reason-for-using-the-delimiter-statement-in-mysql-routines-stored-procedures-functions-triggers/

Related

How to define DB functions in MySQL Docker?

When using a SQL file placed inside /docker-entrypoint-initdb.d/ defining functions fails with the following error:
ERROR 1064 (42000) at line 6: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3
This is the content of the SQL file:
CREATE DATABASE alpha;
USE alpha;
SET GLOBAL log_bin_trust_function_creators = 1;
create function addit(a int, b int) returns int
begin
return a+b;
end
The above code works perfectly well when I connect to the instance after creation and run it.
Is it not allowed to define functions in db init scripts? How do I get around this?

MySQL Workbench - Stored Procedure - Error - No reference in manual

I am using MySQL workbench 8.0.18 on a mac.
I am trying to run the following stored procedure using $$ as my delimiter. It is not running and giving me the error
Error Code: 1064. You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '' at line 3
And here is the code with the delimiter:
delimiter $$
create procedure HelloWorld()
begin
select 'Hello World!';
end $$
I have gone through the documentation for mysql workbench but could not find any relevant answer pertaining to it.
Thank you for your help in advance.
You have to run this in a NORMAL query tab when you want to use DELIMITER:
If you want to add a procdure in new_procedure Routine
Leave out the DELIMITER completely,
When you save the procedure Workbench will add the DELIMITER abd DEFINER automatically

Not able to work with mysql stored procedure in ssrs

I am not able to work with MySQL stored procedures in SSRS.
While using Mysql queries dataaset get created successfully. but if want to fetch data from stored procedures with parameter i get this error.
ERROR [42000] [MySQL][ODBC 8.0(a) Driver][mysqld-8.0.13]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ims_data.GetUploadStatus' at line 1
ODBC does not support named parameters. you need to use ? for parameters
You can try
CALL ims_data.GetUploadStatus(?)
or
EXEC ('CALL ims_data.GetUploadStatus(?)', #p_period) AT MySQL (Linked Server Name)

mysql using tee in stored procedure

I'm new to MySQL (or SQL in general)
I'm trying to get MySQL to write the timestamp into a file with stored procedure using TEE command (I don't think I can use "select into outfile" because I don't want to delete the file, I want to add a line to it...):
mysql> DELIMITER $$
mysql> CREATE PROCEDURE test_to_file()
-> begin
-> TEE /home/ubuntu/test.txt;
-> SELECT NOW();
-> end $$
However, I get an error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/home/ubuntu/test.txt;
SELECT NOW();
end' at line 3
Thanks for the help
Disclaimer: I am not certain that whatever you are trying to do is necessarily a good idea... but there is a simple solution for this.
Create a table using the CSV Storage Engine.
You can then append to the file by simply inserting into this table.
Using tee is a client-side feature. It doesn't write to the server at all, unless you happen to be running the mysql client on the server machine... in which case, it's only writing to the server machine by coincidence.

mysql: DELIMITER syntax error at line 1

I try to add this function using the following SQL in phpmyadmin/MySQL
DROP FUNCTION IF EXISTS `__myv`;
DELIMITER ;;
CREATE FUNCTION `__myv`(`a` int, `b` int) RETURNS bigint(20)
BEGIN
return FLOOR(a / b);
END;;
DELIMITER ;
but I get this error:
Error
SQL query:
DELIMITER;
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER' at line 1
How to fix this error??
DELIMITER is a Mysql console command, You can't use it in phpmyadmin.
To set the delimiter in phpmyadmin, see this other answer
Even if DELIMITER is a console command, phpMyAdmin's import module has accepted it since many years. When opening a database and clicking on SQL, a query entered there is passed to the import module, so it should work (unless you have a very old phpMyAdmin version).