Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用2个表更新查询_Sql_Oracle - Fatal编程技术网

Sql 使用2个表更新查询

Sql 使用2个表更新查询,sql,oracle,Sql,Oracle,我有两张桌子,表一和表二 表1有两列:status和id 表2有两列:id和name 我有一个函数接收一个名称,我想将table1.status更新为0,其中table1.id=table2.id,table2.name=我接收的名称 我尝试四处查看,但我尝试的每个查询都失败了。您可以使用更新: update table1 t1 set status = 0 where exists (select 1 from table2 t2

我有两张桌子,表一和表二

表1有两列:status和id

表2有两列:id和name

我有一个函数接收一个名称,我想将table1.status更新为0,其中table1.id=table2.id,table2.name=我接收的名称


我尝试四处查看,但我尝试的每个查询都失败了。

您可以使用
更新

update table1 t1
     set status = 0
     where exists (select 1 
                   from table2 t2
                   where t2.id = t1.id and t2.name = :name
                  );

@如果答案解决了你的问题,你可以接受。这样你就可以奖励回答问题的ppl。它还显示了未来的ppl谁有相同的问题,解决方案没有工作。@戈登,我赞成你的答案,因为它解决了问题,因为用户显然忘记接受它。我也遭受了很多痛苦,因此,当人们的回答显然是好的,但当他们自己解决了问题,问问题的人忘记了或不在乎时,我约束自己投票给他们。