问题
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...
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
回答1:
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...
回答2:
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 SELECT statement as:
SELECT message;
Eg:
SELECT "WELCOME TO MySQL";
回答3:
For debugging info from stored procedure in MySQL,there are following options through which you can do this.
1.Write into the file externally:
select "your_message" as log into outfile '/temp/brajesh.txt';
2.Use select command to print message:
select "result_message";
3.Use select command to print additional information with message:
select concat("Hello ! :", result);
4.Create addition table temp and push all message into it:
insert into temp select 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 ;
来源:https://stackoverflow.com/questions/20039398/show-message-in-stored-procedure