简体   繁体   English

如何在 MySQL 中模拟打印语句?

[英]How can I simulate a print statement in MySQL?

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,例如,pusdocode 会是这样的,

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 中做到这一点?

If you do not want to the text twice as column heading as well as value, use the following stmt!如果您不想将文本两次作为列标题和值,请使用以下 stmt!

SELECT 'some text' as '';

Example:

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

You can print some text by using SELECT command like that:您可以使用SELECT命令打印一些文本,如下所示:

SELECT 'some text'

Result:结果:

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

This is an old post, but thanks to this post I have found this:这是一篇旧帖子,但多亏了这篇文章,我才发现:

\! echo 'some text';

Tested with MySQL 8 and working correctly.使用 MySQL 8 测试并正常工作。 Cool right?酷吧? :) :)

to take output in MySQL you can use if statement SYNTAX:要在 MySQL 中获取输出,您可以使用 if 语句 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 if_true 和 if_false 可用于验证和显示输出,因为 MySQL 中没有打印语句

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM