MySQL/Oracle数据库中的切换布尔值
在Oracle和MySQL的适当SQL中转换此伪代码的最佳方法是什么?由于两个DBMS中都没有真正的布尔值,因此您需要一个case语句:MySQL/Oracle数据库中的切换布尔值,mysql,sql,oracle,Mysql,Sql,Oracle,在Oracle和MySQL的适当SQL中转换此伪代码的最佳方法是什么?由于两个DBMS中都没有真正的布尔值,因此您需要一个case语句: Update myTable SET field = 1 (if field = 0 or if field is null) where myid = 12345; Update myTable SET field = 0 (if field = 1) where myid = 12345; 这假设列的值永远不会超过0和1,因为这两个DBMS中都没有真正的
Update myTable SET field = 1 (if field = 0 or if field is null) where myid = 12345;
Update myTable SET field = 0 (if field = 1) where myid = 12345;
这假设列的值永远不会超过0和1,因为这两个DBMS中都没有真正的布尔值。您需要一个case语句:
Update myTable SET field = 1 (if field = 0 or if field is null) where myid = 12345;
Update myTable SET field = 0 (if field = 1) where myid = 12345;
这假设列的值与0和1的值不同,您可以简单地使用如下模:
update myTable
set the_column = case when the_column = 1 then 0 else 1 end
where myId = 12345;
您可以简单地使用如下的模:
update myTable
set the_column = case when the_column = 1 then 0 else 1 end
where myId = 12345;
它应该是模2。在你的例子中,模1总是导致0,它应该是模2。在您的示例中,模1总是导致0