Good afternoon,
I am attempting to run a stored procedure that updates records in MySQL 5.1 on Mac OSX 10.4.11. Here is a sample procedure:
DELIMITER $$
CREATE DEFINER=`root`#`localhost` PROCEDURE `TestUpd`()
BEGIN
UPDATE Addr
SET eMail2 = 'test';
END
$$
When I execute this procedure, I get the error, 'Error executing SQL command'. I've tried various options, but this is the simplest example that illustrates the problem.
This does not happen when I try the same thing in MySQL 5.1 on Windows XP.
Any ideas?
Thank you,
Igal
As a follow-up, we stumbled upon a workaround and will post it here for future reference.
When we added a select statement to the stored procedure after the UPDATE statement, the procedure worked as expected. This is not an optimal workaround since you will not be able to modify your procedures in all cases, but we are able to do so in our case. The following then worked for us:
DELIMITER $$
CREATE DEFINER=`root`#`localhost` PROCEDURE `TestUpd`()
BEGIN
UPDATE Addr
SET eMail2 = 'test';
SELECT 0;
END
$$
Related
I'm working in mysql workbench 8.0.11 and having problems creating stored procedures and also functions. Just to be clear, I am running this in mysql via the mysql workbench. I am not using any other program at all.
I'm trying to create a new stored procedure. I keep getting a syntax error: "delimiter" is no valid input at this position, expecting: CREATE.
I have checked the mysql website to make sure my syntax is correct, and it matches. Another thing to note is that I've tried starting the stored procedure with use accounting; (the db I'm working with) and I get the same error, except that "use" takes the place of "delimiter". So, I'm not sure it has anything to do with the delimiter keyword itself. Is there some setting in mysql workbench that I can set to get this straightened out? Also, I get the same exact syntax error when trying to create a function.
I have tried creating both a stored procedure and a function without using the delimiter keyword, or the use keyword, and when I hit the apply key mysql crashes.
Here is my code:
delimiter $$
create procedure 'add_expense_category' (id int, name varchar(20))
begin
insert into expense_categories(expense_category_id, expense_category)
values(id, name);
end $$
delimiter ;
Anyone have any ideas on how to solve this? Settings to change? Anything?
Thanks!
try this
delimiter $$
create procedure `add_expense_category` (id int, name varchar(20))
begin
insert into expense_categories(expense_category_id, expense_category)
values(id, name);
end $$
delimiter ;
In SQL Server I am able to achieve this using dynamic sql string, but now I need to do the same thing for mysql but am getting nowhere, is there any way to achive this
IF NOT EXISTS (SELECT 1 FROM mysql.proc p WHERE NAME = 'stored_proc_name')
BEGIN
DELIMITER $$
CREATE PROCEDURE justATest()
BEGIN
-- some SP logic here
END$$
END
I am storing the whole sql as a string inside a database column and execute the statement using a prepared statement Execute inside another stored procedure.
IF NOT EXISTS(SELECT 1 FROM mysql.proc p WHERE db = 'db_name' AND name = 'stored_proc_name') THEN
....
taken from
Older Post
Control statements like if then else are only allowed inside Stored Procedures in MySQL (unfortunately). There are usually ways around this, but it depends why you are conditionally creating the sproc.
E.g. If you're trying to avoid errors when running build scripts because sprocs already exist then you can use a conditional drop statement prior to your create like this:
DROP PROCEDURE IF EXISTS justATest;
CREATE PROCEDURE justATest()
BEGIN
-- enter code here
END;
This will ensure the any changed code gets run (rather than skipped).
My question is pretty straight forward. Is it possible to create a procedure that calls multiple previously stored procedures such as:
CREATE PROCEDURE `CALL_A_B_C` ( )
NOT DETERMINISTIC MODIFIES SQL DATA SQL SECURITY DEFINER
CALL `A` ();
CALL `B`();
CALL `C`();
This code doesn't work but you get the idea. Is there a way to do this?
The answer yes it is possible. Your code for an outer stored procedure might look like this
DELIMITER $$
CREATE PROCEDURE sp_abc()
BEGIN
CALL sp_a();
CALL sp_b();
CALL sp_c();
END$$
DELIMITER
Here is SQLFiddle demo
I want to create procedure for importing into Mysql Database.
If I run the following query in the SQL executor task, it fails.
DELIMITER $$
create procedure abc
as
begin
select count(*) from tableA;
select count(*) from tableB;
end
DELIMITER ;
Which shows there is a problem with the DELIMITER command.
I checked if the problem is with the .NET connector for MYSQL. But as per the forums in Mysql, it has been resolved there: http://dev.mysql.com/doc/refman/5.1/en/connector-net-news-6-3-1.html
Mysql connector bug for this: http://bugs.mysql.com/bug.php?id=46429
Actually DELIMITER is client side command, so I came to the conclusion that the problem is with SSIS.
COULD somebody please put some light on this?
i found my answer in sql server at here, but my question is about in mysql. please help me
well to create a stored procedure in mysql you do it like so...
delimiter //;
create procedure Foo()
BEGIN
Select * from videos;
END
See http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html for additional details