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中编写此查询的正确方法是什么?
5 个解决方案
#1
39
Semicolon at the end of the line.
分号线末尾的分号。
INSERT INTO myTable (ID) values (5);
#2
13
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.
当然,这不仅限于存储过程定义。
#3
9
Just a simple ;
只是一个简单;
so try
所以试试吧
insert into myTable(ID) values (5);
select * from myTable;
#4
5
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();
开始交易; drop procedure如果存在usp_test;承诺;开始交易;从书中创建程序usp_test()SELECT *;承诺;叫usp_test();
#5
4
Use a semicolon (;
). It will separate your statements.
使用分号(;)。它会将您的陈述分开。
#1
39
Semicolon at the end of the line.
分号线末尾的分号。
INSERT INTO myTable (ID) values (5);
#2
13
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.
当然,这不仅限于存储过程定义。
#3
9
Just a simple ;
只是一个简单;
so try
所以试试吧
insert into myTable(ID) values (5);
select * from myTable;
#4
5
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();
开始交易; drop procedure如果存在usp_test;承诺;开始交易;从书中创建程序usp_test()SELECT *;承诺;叫usp_test();
#5
4
Use a semicolon (;
). It will separate your statements.
使用分号(;)。它会将您的陈述分开。