MySQL 中“go”的等价物是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/763442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:08:01  来源:igfitidea点击:

What is the equivalent of 'go' in MySQL?

sqlmysqltsql

提问by Ahmed Mozaly

In TSQL I can state:

在 TSQL 中,我可以声明:

insert into myTable (ID) values (5)
GO
select * from myTable

In MySQL I can't write the same query.

在 MySQL 中,我无法编写相同的查询。

What is the correct way to write this query in MySQL?

在 MySQL 中编写此查询的正确方法是什么?

回答by Jeff Fritz

Semicolon at the end of the line.

行尾的分号。

INSERT INTO myTable (ID) values (5);

回答by Daniel Schneller

The semicolon is the default delimiter. You can however redefine it to whatever you want with the DELIMITER keyword. From the MySQL manual:

分号是默认分隔符。但是,您可以使用 DELIMITER 关键字将其重新定义为您想要的任何内容。从 MySQL 手册:

mysql> delimiter //

mysql> CREATE PROCEDURE simpleproc (OUT param1 INT)
    -> BEGIN
    ->   SELECT COUNT(*) INTO param1 FROM t;
    -> END;
    -> //
Query OK, 0 rows affected (0.00 sec)

mysql> delimiter ;

mysql> CALL simpleproc(@a);
Query OK, 0 rows affected (0.00 sec)

This is not limited to stored procedure definitions of course.

这当然不限于存储过程定义。

回答by Grant Collins

Just a simple ;

只是一个简单的;

so try

所以试试

insert into myTable(ID) values (5);
select * from myTable;

回答by Brian

I think the problem is that GO is a batch terminator, not a statement terminator. After explicitly setting transactions, I got this code to execute without telling me that the procedure already exists. Without the transaction statements, I do get an error that the procedure already exists.

我认为问题在于 GO 是批处理终止符,而不是语句终止符。在显式设置事务后,我执行了此代码,而没有告诉我该过程已经存在。如果没有事务语句,我会收到一个错误,表明该过程已经存在。

start transaction; drop procedure if exists usp_test; commit; start transaction; CREATE PROCEDURE usp_test() SELECT * from books; commit; call usp_test();

开始交易;如果存在 usp_test,则删除程序;犯罪; 开始交易;创建程序 usp_test() SELECT * from books; 犯罪; 调用 usp_test();

回答by Daniel A. White

Use a semicolon (;). It will separate your statements.

使用分号 ( ;)。它将分开您的陈述。