【问题标题】:Using if condition in the Select statement在 Select 语句中使用 if 条件
【发布时间】:2017-08-03 15:07:29
【问题描述】:

我正在尝试在 Oracle 数据库的选择查询中使用 if 条件。列应设置为某个值,具体取决于我尝试过的值,如下所示

Select if(expvalue.DATA = '0','Unpublished','Published') as STATUS from

DATA 字段是一个布尔值,所以如果布尔值为 0,我想将状态设置为未发布,如果为 1,则发布。但是上面的语法给出了类似的错误

ORA-00907: missing right parenthesis 00907. 00000 - "missing right parenthesis"

【问题讨论】:

    标签: sql oracle case


    【解决方案1】:

    您可以使用CASE 声明:

    select case when expvalue.DATA = '0' THEN 'Unpublished' ELSE 'Published' END AS STATUS from...
    

    【讨论】:

      猜你喜欢
      • 2013-09-21
      • 2019-02-16
      • 2011-08-08
      • 2012-02-23
      • 1970-01-01
      • 1970-01-01
      • 2012-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多