更新同一列中的多个值

时间:2016-11-28 00:39:53

标签: oracle oracle-sqldeveloper

我有一个名为Movie_Stars的数据表。我想更新多个值,但它们都在同一列中。这就是我所拥有的:

update movie_stars
set movie_category = 'Family'
where movie_category = 'Drama'
and set movie_category = 'Children'
where movie_category = 'Cartoon'
and set movie_category = 'Teen'
where movie_category = 'Action';

但是这会生成错误“invalid user.table.column,table.column或column specification”。那么正确的列规范是什么?

1 个答案:

答案 0 :(得分:1)

使用CASE表达式:

update movie_stars
set movie_category = case when movie_category = 'Drama'
                          then 'Family'
                          when movie_category = 'Cartoon'
                          then 'Children'
                          when movie_category = 'Action'
                          then 'Teen'
                     end
where movie_category in ('Drama', 'Cartoon', 'Action')