How can I simulate a print statement in MySQL?

Mysql

Mysql Problem Overview


I have some procedures where I would like to get some kind of acknowledgement after a condition has been assessed.

For example, the pusedocode would be like,

if ( select count(*) from assgn to where eid = 1 )  > 5
  print " the total number of projects employee working is more than 5 "
else
  insert the value into the assgnto table  

How should I go about doing that in MySQL?

Mysql Solutions


Solution 1 - Mysql

If you do not want to the text twice as column heading as well as value, use the following stmt!

SELECT 'some text' as '';

Example:

mysql>SELECT 'some text' as ''; +-----------+ | | +-----------+ | some text | +-----------+ 1 row in set (0.00 sec)

Solution 2 - Mysql

You can print some text by using SELECT command like that:

SELECT 'some text'

Result:

+-----------+
| some text |
+-----------+
| some text |
+-----------+
1 row in set (0.02 sec)

Solution 3 - Mysql

This is an old post, but thanks to this post I have found this:

\! echo 'some text';

Tested with MySQL 8 and working correctly. Cool right? :)

Solution 4 - Mysql

to take output in MySQL you can use if statement SYNTAX:

if(condition,if_true,if_false)

the if_true and if_false can be used to verify and to show output as there is no print statement in the MySQL

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRahulView Question on Stackoverflow
Solution 1 - MysqlmvsagarView Answer on Stackoverflow
Solution 2 - Mysqluser562854View Answer on Stackoverflow
Solution 3 - MysqlGucu112View Answer on Stackoverflow
Solution 4 - Mysqlshyam_guptaView Answer on Stackoverflow