我的查询出了什么问题?具有多个更新案例的SQL

时间:2019-12-27 19:03:33

标签: sql oracle

我想用不同的名称来更新“ money”。

select names,money from workers ;

返回:

NAMES|MONEY
Frank|1250$
Tony|1240$
UPDATE workers
SET money = CASE 'names' WHEN 'Tony' THEN '1500$'
                         WHEN 'Frank' THEN '1600$' END
WHERE 'names' IN ('Tony','Frank');

语法还可以,但是没有行被更新,为什么?

1 个答案:

答案 0 :(得分:2)

列名不应用单引号引起来。

SQL> create table workers as
  2    select 'Frank' names, 0 money from dual union all
  3    select 'Tony', 0 from dual union all
  4    select 'Little', 0 from dual;

Table created.

SQL>
SQL> update workers set
  2    money = case when names = 'Tony' then 1500
  3                 when names = 'Frank' then 1600
  4            end
  5  where names in ('Tony', 'Frank');

2 rows updated.

SQL> select * From workers;

NAMES       MONEY
------ ----------
Frank        1600
Tony         1500
Little          0

SQL>