MySQL 在存储过程中显示消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20039398/
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
Show message in stored procedure
提问by Igor
How do I show a message from a stored procedure?
如何显示来自存储过程的消息?
What is the right syntax to display a message saying whether or not rows exist?
显示一条消息是否存在行的正确语法是什么?
In SQL Server it's PRINT to show a message bat in WORKBENCH...
在 SQL Server 中,它是 PRINT 以在 WORKBENCH 中显示消息蝙蝠...
CREATE PROCEDURE `new_proced` (
in myid int(3)
)
BEGIN
if not exists (select id from table where id = myid)
then
show message 'Row no exists';
else
show message 'Row exists';
end if;
END
回答by Andrew
Not entirely sure why you would want to do something like that, but you could do something like this: ...
不完全确定为什么你会想要做这样的事情,但你可以做这样的事情:...
then
select 'YOUR MESSAGE HERE'
else
select 'YOUR OTHER MESSAGE HERE'
end if
Or you could select 1 or 0, might be a little better...
或者你可以选择 1 或 0,可能会好一点......
回答by Y. Kiran Kumar
There is no Proper output statement provide in MySQL like in Oracle, we have DBMS_OUTPUT.PUT_LINE. So, to display any messages on the console, you can use SELECTstatement as:
MySQL 中没有像 Oracle 那样提供正确的输出语句,我们有 DBMS_OUTPUT.PUT_LINE。因此,要在控制台上显示任何消息,您可以使用SELECT语句:
SELECT message;
SELECT message;
Eg:
SELECT "WELCOME TO MySQL";
例如:
SELECT "WELCOME TO MySQL";
回答by Brajesh
For debugging info from stored procedure in MySQL,there are following options through which you can do this.
要从 MySQL 中的存储过程调试信息,您可以通过以下选项执行此操作。
1.Write into the file externally:
1.外部写入文件:
select "your_message" as log into outfile '/temp/brajesh.txt';
选择“your_message”作为登录到输出文件“/temp/brajesh.txt”;
2.Use select command to print message:
2.使用select命令打印消息:
select "result_message";
选择“result_message”;
3.Use select command to print additional information with message:
3.使用select命令打印附加信息和消息:
select concat("Hello ! :", result);
select concat("你好!:", result);
4.Create addition table temp and push all message into it:
4.创建添加表临时并将所有消息推送到其中:
insert into temp select concat(result);
插入临时选择 concat(result);
Example
例子
drop procedure if exists display_name_procedure;
delimiter //
create procedure display_name_procedure(IN name_val varchar(65))
begin
declare result varchar(65);
set result := display_name_function(name_val);
create table if not exists temp (name_val varchar(65) not null);
insert into temp select concat(result);
select "penguin" as log into outfile '/temp/brajesh.txt';
select concat("Hello ! :", result);
end//
delimiter ;