• <i id='P91Ie'><tr id='P91Ie'><dt id='P91Ie'><q id='P91Ie'><span id='P91Ie'><b id='P91Ie'><form id='P91Ie'><ins id='P91Ie'></ins><ul id='P91Ie'></ul><sub id='P91Ie'></sub></form><legend id='P91Ie'></legend><bdo id='P91Ie'><pre id='P91Ie'><center id='P91Ie'></center></pre></bdo></b><th id='P91Ie'></th></span></q></dt></tr></i><div id='P91Ie'><tfoot id='P91Ie'></tfoot><dl id='P91Ie'><fieldset id='P91Ie'></fieldset></dl></div>

    <small id='P91Ie'></small><noframes id='P91Ie'>

  • <legend id='P91Ie'><style id='P91Ie'><dir id='P91Ie'><q id='P91Ie'></q></dir></style></legend>
  • <tfoot id='P91Ie'></tfoot>

          <bdo id='P91Ie'></bdo><ul id='P91Ie'></ul>

      1. MySQL 相当于 Oracle 中的 DECODE 函数

        MySQL equivalent of DECODE function in Oracle(MySQL 相当于 Oracle 中的 DECODE 函数)
          <bdo id='PrIAg'></bdo><ul id='PrIAg'></ul>

          • <legend id='PrIAg'><style id='PrIAg'><dir id='PrIAg'><q id='PrIAg'></q></dir></style></legend>

          • <small id='PrIAg'></small><noframes id='PrIAg'>

          • <tfoot id='PrIAg'></tfoot>

              <i id='PrIAg'><tr id='PrIAg'><dt id='PrIAg'><q id='PrIAg'><span id='PrIAg'><b id='PrIAg'><form id='PrIAg'><ins id='PrIAg'></ins><ul id='PrIAg'></ul><sub id='PrIAg'></sub></form><legend id='PrIAg'></legend><bdo id='PrIAg'><pre id='PrIAg'><center id='PrIAg'></center></pre></bdo></b><th id='PrIAg'></th></span></q></dt></tr></i><div id='PrIAg'><tfoot id='PrIAg'></tfoot><dl id='PrIAg'><fieldset id='PrIAg'></fieldset></dl></div>

                    <tbody id='PrIAg'></tbody>
                  本文介绍了MySQL 相当于 Oracle 中的 DECODE 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我试图在 MySQL 中找到等效的 DECODE 函数.它是这样工作的:

                  I am trying to find an equivalent of DECODE function in MySQL. It works like this:

                  Select Name, DECODE(Age,
                         13,'Thirteen',14,'Fourteen',15,'Fifteen',16,'Sixteen',
                         17,'Seventeen',18,'Eighteen',19,'Nineteen',
                         'Adult') AS AgeBracket
                  FROM Person
                  

                  DECODE 函数会将列 'Age' 的值与 13、14、15.. 进行比较,并返回适当的字符串值 'Thirteen'、'Fourteen'.. 如果没有匹配,则默认值为 'Adult'将被退回.

                  The DECODE function will compare value of column 'Age' with 13, 14, 15.. and return appropriate string value 'Thirteen', 'Fourteen'.. and if it matches with nothing, then default value of 'Adult' will be returned.

                  有什么想法可以在 MySQL 中的哪个函数中完成这项工作?谢谢.

                  Any ideas which function in MySQL can do this job? Thanks.

                  澄清:我同意使用 CASE 是实现预期结果的一种方式,但出于性能和其他原因,我更愿意寻找函数.

                  CLARIFICATION: I agree using CASE is one way of achieving desired result, but I am rather looking for a function because of performance and other reasons.

                  推荐答案

                  您可以使用 IF(),而在 Oracle 中您会使用 DECODE().

                  You can use IF() where in Oracle you would have used DECODE().

                  mysql> select if(emp_id=1,'X','Y') as test, emp_id from emps; 
                  

                  这篇关于MySQL 相当于 Oracle 中的 DECODE 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Bogus foreign key constraint fail(虚假外键约束失败)
                  how to get last insert id after insert query in codeigniter active record(如何在codeigniter活动记录中插入查询后获取最后一个插入ID)
                  Force InnoDB to recheck foreign keys on a table/tables?(强制 InnoDB 重新检查表/表上的外键?)
                  How to auto generate migrations with Sequelize CLI from Sequelize models?(如何使用 Sequelize CLI 从 Sequelize 模型自动生成迁移?)
                  Clear MySQL query cache without restarting server(无需重启服务器即可清除 MySQL 查询缓存)
                  ALTER TABLE to add a composite primary key(ALTER TABLE 添加复合主键)

                1. <legend id='a3kjU'><style id='a3kjU'><dir id='a3kjU'><q id='a3kjU'></q></dir></style></legend>
                2. <tfoot id='a3kjU'></tfoot>

                    <bdo id='a3kjU'></bdo><ul id='a3kjU'></ul>
                    • <small id='a3kjU'></small><noframes id='a3kjU'>

                          <tbody id='a3kjU'></tbody>
                            <i id='a3kjU'><tr id='a3kjU'><dt id='a3kjU'><q id='a3kjU'><span id='a3kjU'><b id='a3kjU'><form id='a3kjU'><ins id='a3kjU'></ins><ul id='a3kjU'></ul><sub id='a3kjU'></sub></form><legend id='a3kjU'></legend><bdo id='a3kjU'><pre id='a3kjU'><center id='a3kjU'></center></pre></bdo></b><th id='a3kjU'></th></span></q></dt></tr></i><div id='a3kjU'><tfoot id='a3kjU'></tfoot><dl id='a3kjU'><fieldset id='a3kjU'></fieldset></dl></div>