SQL 为 Oracle 更新查询 if 语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28581198/
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-09-01 03:18:22 来源:igfitidea点击:
Update query if statement for Oracle
提问by Jakub Zak
I need to update newly created column in my oracle table. To do so I need to use existing values in row to decide how to populate this column, I am getting error:
我需要更新我的 oracle 表中新创建的列。为此,我需要使用行中的现有值来决定如何填充此列,但出现错误:
java.lang.NullPointerException -> See Debug Output for details
This is my query:
这是我的查询:
UPDATE
SCHEMA_NAME.TABLE_NAME
SET
OCO= IF CO= 'Y' AND COM='Y' THEN
{
'Y'
} ELSE
{
'N'
}
END IF;
Any suggestions on syntax?
关于语法的任何建议?
回答by Lalit Kumar B
You could use CASEexpression in the SET
clause.
您可以在子句中使用CASE表达式SET
。
For example,
例如,
UPDATE table
SET schema.column = CASE
WHEN CO= 'Y' AND COM='Y' THEN
'Y'
ELSE
'N'
END