当在 MySQL 中将性别值作为布尔值存储在表中时将其作为字符串提取
首先让我们创建一个表格 -
mysql> create table DemoTable815(Gender BOOLEAN); Query OK, 0 rows affected (0.84 sec)
使用插入命令在表中插入一些记录 -
mysql> insert into DemoTable815 values(true); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable815 values(false); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable815 values(false); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable815 values(true); Query OK, 1 row affected (0.16 sec)
使用选择语句显示表中的所有记录 -
mysql> select *from DemoTable815;
将生成以下输出 -
+--------+ | Gender | +--------+ | 1 | | 0 | | 0 | | 1 | +--------+ 4 rows in set (0.00 sec)
以下是在表中将性别存储为布尔值时将其作为字符串提取的查询 -
mysql> select if(Gender=true,'MALE','FEMALE') AS String from DemoTable815;
将生成以下输出 -
+--------+ | String | +--------+ | MALE | | FEMALE | | FEMALE | | MALE | +--------+ 4 rows in set (0.00 sec)
广告