将值插入特定行的 table

Insert Values into table of specific row

我希望根据特定行的选择将一些值插入到列中。我有一个包含 a、b、c 和 d 列的 table。我想在列 a = X 时将值 1、2 和 3 插入到列 b、c 和 d 中。我找不到如何执行此操作。

Toad for oracle 是我的平台,我正在寻找 SQL 代码。

您可以使用 INSERT INTO...SELECT 并为您的插入查询提供条件,例如:

INSERT
INTO table_name (b, c, d)
VALUES (bValue, cValue, dValue)
/* Select Condition */
WHERE a=1

您可以一次更新一个:

update mytable set b = 1 where a = X;
update mytable set c = 2 where a = X;
update mytable set d = 3 where a = X;

或者一次全部更新:

update mytable set b = 1,c = 2,d = 3 where a = X;

或者,假设 'a' 是一个主键列或唯一索引,并且只有 1 行 where a = X,如果您只有 4 列并且您想要更新其中的 3 列,您可以删除你的行并重新插入整个批次:

delete from mytable where a = X;
insert into mytable values(X, 1, 2, 3);
update mytable set b = 1,c = 2,d = 3 where a = X;