如何根据查询结果为oracle中的列设置值?
How to set a value for a Column in oracle based on query results?
我的 Oracle DB
中有一个名为 Person
的 table,包含以下列:
- ID
- Name
- hasPaid
- sendProduct
对于 hasPaid
值为 'yes'
的任何行,我想将 sendProduct
列的当前值修改为 'Yes'
select * from Person where hasPaid = 'Yes';
我在上面编写了以下查询以获取 hasPaid 值为 'Yes' 的所有行,但是我不确定如何使用它设置 hasPaid 列?
UPDATE Person
SET sendProduct = 'Yes'
where hasPaid = 'Yes';
也许读一读 SQL Tutorial? 这是一个非常基础的 DML(数据操作语言)概念。
OldProgrammer
的答案是正确的。
但是如果你只想更新需要更新的行,你也可以使用:
UPDATE Person
SET sendProduct = 'Yes'
WHERE sendProduct != 'Yes'
AND hasPaid = 'Yes';
我的 Oracle DB
中有一个名为 Person
的 table,包含以下列:
- ID
- Name
- hasPaid
- sendProduct
对于 hasPaid
值为 'yes'
sendProduct
列的当前值修改为 'Yes'
select * from Person where hasPaid = 'Yes';
我在上面编写了以下查询以获取 hasPaid 值为 'Yes' 的所有行,但是我不确定如何使用它设置 hasPaid 列?
UPDATE Person
SET sendProduct = 'Yes'
where hasPaid = 'Yes';
也许读一读 SQL Tutorial? 这是一个非常基础的 DML(数据操作语言)概念。
OldProgrammer
的答案是正确的。
但是如果你只想更新需要更新的行,你也可以使用:
UPDATE Person
SET sendProduct = 'Yes'
WHERE sendProduct != 'Yes'
AND hasPaid = 'Yes';