gpt4 book ai didi

sql - SQL语句中的 "set+0"是做什么用的?

转载 作者:可可西里 更新时间:2023-11-01 06:36:20 25 4
gpt4 key购买 nike

我对这条 SQL 语句的含义感到困惑:

SELECT exhibitor_categories+0 from exhibitor_registry

什么是 exhibitor_categories+0 ?它为返回的每一行返回一个数字。

exhibitor_categories 定义为:

set('contemporary', 'classical impression / transitional', 'outdoor', 'home accessories')

感谢您的宝贵时间:)

最佳答案

它将设置值隐式转换为 INTEGER

集合被视为位图,因此第一个值设置位 0,第二个值设置位 1 等。

mysql> CREATE TABLE exhibitor_registry(exhibitor_categories set('contemporary',
'classical impression / transitional', 'outdoor', 'home accessories') NOT NULL);

Query OK, 0 rows affected (0.08 sec)

mysql> INSERT
-> INTO exhibitor_registry
-> VALUES ('contemporary,classical impression / transitional,outdoor');
Query OK, 1 row affected (0.03 sec)

mysql> SELECT exhibitor_categories
-> FROM exhibitor_registry;
+----------------------------------------------------------+
| exhibitor_categories |
+----------------------------------------------------------+
| contemporary,classical impression / transitional,outdoor |
+----------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT exhibitor_categories + 0
-> FROM exhibitor_registry;
+--------------------------+
| exhibitor_categories + 0 |
+--------------------------+
| 7 |
+--------------------------+
1 row in set (0.00 sec)

关于sql - SQL语句中的 "set+0"是做什么用的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1702462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com