【问题标题】:How can I simulate a print statement in MySQL?如何在 MySQL 中模拟打印语句?
【发布时间】:2011-08-02 12:31:37
【问题描述】:

我有一些程序希望在评估病情后得到某种确认。

例如,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  

我应该如何在 MySQL 中做到这一点?

【问题讨论】:

    标签: mysql


    【解决方案1】:

    如果您不想将文本作为列标题和值的两倍,请使用以下 stmt!

    选择'一些文本'作为'';

    例子:

    mysql>SELECT 'some text' as ''; +-----------+ | | +-----------+ |一些文字 | +-----------+ 一组中的 1 行(0.00 秒)

    【讨论】:

    • 我喜欢使用列标题,例如:SELECT 'is more than 5' AS ``the total number of projects the employee is working on``;
    • @mvsagar 所以不能在mysql 中使用print 吗?
    • @Kasun Siyambalapitiya 不,不是。
    【解决方案2】:

    你可以使用SELECT这样的命令打印一些文本:

    SELECT 'some text'
    

    结果:

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

    【讨论】:

    • 那么在mysql中不能使用print吗?
    • @kasun-siyambalapitiya 不,不是。
    【解决方案3】:

    这是一个旧帖子,但感谢this 帖子我发现了这个:

    \! echo 'some text';
    

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

    【讨论】:

    【解决方案4】:

    要在 MySQL 中获取输出,您可以使用 if 语句 语法:

    if(condition,if_true,if_false)
    

    if_true 和 if_false 可用于验证和显示输出 因为 MySQL 中没有 print 语句

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-02
      • 1970-01-01
      • 2011-03-09
      • 2019-11-27
      • 2021-06-23
      • 2011-06-07
      • 1970-01-01
      相关资源
      最近更新 更多