Oracle Sql是否一次更新多个记录?
是否可以在一个sql查询中更新多个记录? 因此,将id为A和ip 1.1.1.1的所有打印机的状态更新为“正常工作”,将所有其他打印机的状态更新为“不正常工作” 因此,基本上将这两个查询合并为一个查询:Oracle Sql是否一次更新多个记录?,sql,oracle,oracle11g,Sql,Oracle,Oracle11g,是否可以在一个sql查询中更新多个记录? 因此,将id为A和ip 1.1.1.1的所有打印机的状态更新为“正常工作”,将所有其他打印机的状态更新为“不正常工作” 因此,基本上将这两个查询合并为一个查询: update printers set status = true ,row_update_date =sysdate where printer id = 'A' and printer ip = '1.1.1.1' update printers set status = false ,ro
update printers set status = true ,row_update_date =sysdate where printer id = 'A' and printer ip = '1.1.1.1'
update printers set status = false ,row_update_date =sysdate where printer id = 'A' and printer ip != '1.1.1.1'
表结构:
printers table:
printer ID,printer ip, status,row_update_date
A ,1.1.1.1 ,
A ,1.1.1.2 ,
A ,1.1.1.3 ,
A ,1.1.1.4 ,
B ,1.1.2.1 ,
B ,1.1.2.2 ,
更新
我忘了更新日期 您可以尝试在
您可以尝试在以下情况下使用CASE进行更新:
您可以使用以下用例:
您可以使用以下用例:
或者,您可以使用Oracle的SQL for switch case类型语句
update printers
set status = decode(printer_IP,'1.1.1.1','true','false'),
row_update_date = sysdate
where printer_ID = 'A';
或者,您可以使用Oracle的SQL for switch case类型语句
update printers
set status = decode(printer_IP,'1.1.1.1','true','false'),
row_update_date = sysdate
where printer_ID = 'A';
谢谢,我忘了在所有记录上添加行更新日期,可以吗?@user648026是的,你可以一次更新多个列谢谢,我忘了在所有记录上添加行更新日期,可以吗?@user648026是的,你可以一次更新多个列
update printers
set status = decode(printer_IP,'1.1.1.1','true','false'),
row_update_date = sysdate
where printer_ID = 'A';