Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.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
MySQL/Oracle数据库中的切换布尔值_Mysql_Sql_Oracle - Fatal编程技术网

MySQL/Oracle数据库中的切换布尔值

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中都没有真正的

在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中都没有真正的布尔值。您需要一个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