简体   繁体   English

在mysqladmin中创建存储过程?

[英]Create stored procedure in mysqladmin?

I am trying to create stored procedure in mysql admin.我正在尝试在 mysql admin 中创建存储过程。 I am hosting a website in POWWEB.com.我在 POWWEB.com 上托管一个网站。 For this purpose i am trying to create stored procedure in mysqladmin.为此,我试图在 mysqladmin 中创建存储过程。

The Mysql version is 5.0.45. Mysql 版本是 5.0.45。 I am able to create a stored procedure with only 1 line of code.我只能用 1 行代码创建一个存储过程。

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.非常感谢任何帮助或建议。

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//

Ignore PHPMyAdmin, it is as useless as a motorcycle-ashtray.忽略 PHPMyAdmin,它和摩托车烟灰缸一样没用。 Log in to your shell and use the mysql command line interface, this is the only supportable, correct way of scripting mysql.登录到您的 shell 并使用 mysql 命令行界面,这是编写 mysql 脚本的唯一可支持的正确方法。

The DELIMITER command is not a mysql server command, it is a mysql command-line client command. DELIMITER 命令不是 mysql 服务器命令,而是 mysql 命令行客户端命令。 To use it you must use the proper mysql command line client.要使用它,您必须使用正确的 mysql 命令行客户端。

It is difficult (although not impossible) to create stored procs otherwise.否则很难(尽管并非不可能)创建存储过程。

the Best answer is just @Barry's comment:最佳答案只是@Barry 的评论:

Stored procedures with multiple queries work fine when putting a BEGIN .. END block around it.当在它周围放置一个 BEGIN .. END具有多个查询的存储过程工作正常。 – Barry Staes — 巴里·斯塔斯

Plus, putting ;另外,; at end of each query .在每个查询结束时

example:例子:

BEGIN
    INSERT INTO passenger (fname,lname,tel,ID,sex)
    VALUES (fname,lname,tel,ID, sex);
    INSERT INTO passenger 
    select * from reservation where 1;
END

In phpMyAdmin, in the SQL editor you can set the delimiter in a form field labeled 'delimiter'.在 phpMyAdmin 的 SQL 编辑器中,您可以在标记为“分隔符”的表单字段中设置分隔符。 It is by default.它是默认的。 Set it to anything you like, do NOT type in delimiter // in your SQL but DO end the sql with your delimiter as END// where // is the delimiter of your choice.将其设置为您喜欢的任何内容,不要在 SQL 中输入分隔符 // 而是使用分隔符作为 END// 结束 sql,其中 // 是您选择的分隔符。

MySQL admin is outdated . MySQL 管理员已过时 Please use MySQL workbench for more functionalities and and rich GUI based operations.请使用MySQL 工作台以获得更多功能和丰富的基于GUI的操作。 https://www.mysql.com/products/workbench/ https://www.mysql.com/products/workbench/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM