简体   繁体   English

在Select语句中使用if条件

[英]Using if condition in the Select statement

I am trying to use the if condition in the select query of the Oracle database. 我正在尝试在Oracle数据库的select查询中使用if条件。 The columns should be set to some value depending on the value like the below is what I tried 列应设置为某些值,具体取决于值,如下所示是我尝试的值

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

DATA field is a Boolean so I want to set the Status to be Unpublished if the Boolean is 0 and published if it is 1.But the above syntax gives error like DATA字段是一个布尔值,因此如果要将布尔值设置为0,将状态设置为Unpublished,如果将布尔值设置为1,则将状态设置为Unpublished。

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

您可以使用CASE语句:

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

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

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