Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show message in stored procedure

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
like image 655
Igor Avatar asked Nov 18 '13 03:11

Igor


People also ask

How do I view stored procedure text?

Using SQL Server Management StudioExpand Stored Procedures, right-click the procedure and then select Script Stored Procedure as, and then select one of the following: Create To, Alter To, or Drop and Create To. Select New Query Editor Window. This will display the procedure definition.

How do you display text in SQL?

:Explanation: Note: You can use literal string (enclosed in single or double quotation mark) just like we use a column name in the SELECT statement. If you use the literal string with a column then it will be displayed in every row of the query results.

How do I view a stored procedure output?

The easy way is to right-click on the procedure in Sql Server Management Studio (SSMS), select 'Execute stored procedure..." and add values for the input parameters as prompted. SSMS will then generate the code to run the procedure in a new query window, and execute it for you.

Is it possible to print out a message from a function procedure?

Stored procedures can't "show messages". Then can return either an OUTPUT parameter OR a record set. It's up to your application to determine what to do with the results. That said, you can "print" a message which is similar to simply selecting some text: see stackoverflow.com/questions/6912102/…


1 Answers

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

like image 78
Andrew Avatar answered Sep 18 '22 12:09

Andrew