views:

111

answers:

2

I am trying to create stored procedure in mysql admin. I am hosting a website in POWWEB.com. For this purpose i am trying to create stored procedure in mysqladmin.

The Mysql version is 5.0.45. I am able to create a stored procedure with only

1 line of code.

CREATE PROCEDURE TEST(input INT)
       INSERT INTO TEST(COL1) VALUES(input);

But this is of no use. I want to write a stored procedure with more commands.

So i try doing like CREATE PROCEDURE TEST(input INT) BEGIN INSERT INTO TEST(COL1) VALUES(input); INSERT INTO TEST1(COL1) VALUES(input); INSERT INTO TEST2(COL1) VALUES(input); END

But this gives a syntax error. But the same code works fine in my local machine. Please let me know if you have any idea of how to solve this. Any help or advice is greatly appreciated.

+1  A: 

The default delimiter is ;, so it interprets the code as multiple queries, which obviously doesn't work. Try something like this:

delimiter //
CREATE PROCEDURE TEST(input INT)
BEGIN
    INSERT INTO TEST(COL1) VALUES(input);
    INSERT INTO TEST1(COL1) VALUES(input);
    INSERT INTO TEST2(COL1) VALUES(input);
END//
Lukáš Lalinský
The DELIMITER // gives error. Is there any alternative.
Vinodtiru
What error? It works fine for me.
Lukáš Lalinský
There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problemERROR: Unknown Punctuation String @ 11STR: //SQL: delimiter //CREATE PROCEDURE TEST(input INT)BEGIN INSERT INTO TEST(COL1) VALUES(input);SQL query:delimiter // CREATE PROCEDURE TEST(input INT) BEGIN INSERT INTO TEST(COL1) VALUES(input);MySQL said: #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 //CREATE PROCEDURE TEST(input INT)BE
Vinodtiru
The code you gave works fine in my local machine when i tried it in the MySQL Query Browser. But when i try it in the myasladmin i get the above error. Not sure of what is the problem. Please advice.
Vinodtiru
The problem is that you are using phpmyadmin. Stop. Use the mysql command line client.
MarkR
@MarkR - No, it's not. The query works fine in phpMyAdmin.
Lukáš Lalinský
A: 

Ignore PHPMyAdmin, it is as useless as a motorcycle-ashtray. Log in to your shell and use the mysql command line interface, this is the only supportable, correct way of scripting mysql.

The DELIMITER command is not a mysql server command, it is a mysql command-line client command. To use it you must use the proper mysql command line client.

It is difficult (although not impossible) to create stored procs otherwise.

MarkR