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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6912102/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:43:22  来源:igfitidea点击:

How can I simulate a print statement in MySQL?

mysql

提问by Rahul

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

回答by mvsagar

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)

回答by DevelRoot

You can print some text by using SELECTcommand like that:

您可以使用如下SELECT命令打印一些文本:

SELECT 'some text'

Result:

结果:

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

回答by Gucu112

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

这是一篇旧帖子,但多亏了这篇文章,我才发现:

\! echo 'some text';

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

使用 MySQL 8 测试并正常工作。酷吧?:)