91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MySQL CHAR和VARCHAR數據類型介紹

發布時間:2020-08-07 01:18:50 來源:ITPUB博客 閱讀:229 作者:feelpurple 欄目:MySQL數據庫
CHAR類型是固定長度的,長度范圍為0到255。如果存儲的值不覆蓋字段長度,存儲數據的其他的部分會在值的右邊自動添加空格。

VARCHAR字段中的值是可變長度的字符串,長度范圍為0到65535。VARCHAR字段的值以1字節或2字節的長度前綴加上數據的方式存儲。長度前綴指示了字段存儲的字節數,如果一個字段存儲的值不超過255字節,它使用一個長度前綴,如果字段存儲的值超過了255字節,它使用兩個長度前綴。

如果沒有啟用嚴格SQL模式,分配給CHAR或VARCHAR字段超過字段最大長度的值,這個值會被截斷保存到數據庫中,并會產生一個警告。對于VARCHAR字段來說,不管使用什么樣的SQL模式,分配給VARCHAR字段超過字段最大長度的值,在值插入前,超過字段最大長度的部分會被截斷,并會產生一個警告。對于CHAR字段來說,不管使用什么樣的SQL模式,超過字段最大長度的部分會被截斷,并隱式插入到數據庫中。

--測試①

MariaDB [test]> show variables like '%sql%mode%';
+---------------+--------------------------------------------+
| Variable_name | Value                                      |
+---------------+--------------------------------------------+
| sql_mode      | NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+---------------+--------------------------------------------+
1 row in set (0.26 sec)

MariaDB [test]> drop table vc;
Query OK, 0 rows affected (0.04 sec)

MariaDB [test]> CREATE TABLE vc (v VARCHAR(4), c CHAR(4));
Query OK, 0 rows affected (0.54 sec)

MariaDB [test]> INSERT INTO vc VALUES ('ab  ', 'ab  ');
Query OK, 1 row affected (0.14 sec)

--查看插入的數據中是否保留空格

MariaDB [test]> SELECT CONCAT('(', v, ')'), CONCAT('(', c, ')') FROM vc;
+---------------------+---------------------+
| CONCAT('(', v, ')') | CONCAT('(', c, ')') |
+---------------------+---------------------+
| (ab  )              | (ab)                |
+---------------------+---------------------+
1 row in set (0.00 sec)

MariaDB [test]> select length(v),length(c) from vc;
+-----------+-----------+
| length(v) | length(c) |
+-----------+-----------+
|         4 |         2 |
+-----------+-----------+
1 row in set (0.00 sec)

--插入超過字段最大值的數據到表中

MariaDB [test]> insert into vc values('abcdefg','abcedeg');
Query OK, 1 row affected, 2 warnings (0.03 sec)

MariaDB [test]> show warnings;
+---------+------+----------------------------------------+
| Level   | Code | Message                                |
+---------+------+----------------------------------------+
| Warning | 1265 | Data truncated for column 'v' at row 1 |
| Warning | 1265 | Data truncated for column 'c' at row 1 |
+---------+------+----------------------------------------+
2 rows in set (0.00 sec)

MariaDB [test]> select * from vc;
+------+------+
| v    | c    |
+------+------+
| ab   | ab   |
| abcd | abce |
+------+------+
2 rows in set (0.00 sec)

--測試②

MariaDB [test]> CREATE TABLE names (myname CHAR(10));
Query OK, 0 rows affected (0.13 sec)

MariaDB [test]> INSERT INTO names VALUES ('Monty');
Query OK, 1 row affected (0.00 sec)

--查看表中數據在WHERE條件中使用=的條件中帶空格的執行情況

MariaDB [test]> SELECT myname = 'Monty', myname = 'Monty  ' FROM names;
+------------------+--------------------+
| myname = 'Monty' | myname = 'Monty  ' |
+------------------+--------------------+
|                1 |                  1 |
+------------------+--------------------+
1 row in set (0.00 sec)

MariaDB [test]> SELECT * FROM names;
+--------+
| myname |
+--------+
| Monty  |
+--------+
1 row in set (0.00 sec)

MariaDB [test]> select length(myname) from names;
+----------------+
| length(myname) |
+----------------+
|              5 |
+----------------+
1 row in set (0.00 sec)

MariaDB [test]> SELECT * FROM names where myname = 'Monty';
+--------+
| myname |
+--------+
| Monty  |
+--------+
1 row in set (0.00 sec)

MariaDB [test]> SELECT * FROM names where myname = 'Monty ';
+--------+
| myname |
+--------+
| Monty  |
+--------+
1 row in set (0.00 sec)

MariaDB [test]> SELECT * FROM names where myname = 'Monty  ';
+--------+
| myname |
+--------+
| Monty  |
+--------+
1 row in set (0.00 sec)

MariaDB [test]> SELECT * FROM names where myname = 'Monty   ';
+--------+
| myname |
+--------+
| Monty  |
+--------+
1 row in set (0.00 sec)

MariaDB [test]> SELECT * FROM names where myname = 'Monty    ';
+--------+
| myname |
+--------+
| Monty  |
+--------+
1 row in set (0.00 sec)

MariaDB [test]> SELECT * FROM names where myname = 'Monty     ';
+--------+
| myname |
+--------+
| Monty  |
+--------+
1 row in set (0.00 sec)

MariaDB [test]> SELECT * FROM names where myname = 'Monty      ';
+--------+
| myname |
+--------+
| Monty  |
+--------+
1 row in set (0.00 sec)

MariaDB [test]> SELECT * FROM names where myname = 'Monty       ';
+--------+
| myname |
+--------+
| Monty  |
+--------+
1 row in set (0.00 sec)

--查看表中的數據在like條件下的執行情況

MariaDB [test]> SELECT myname LIKE 'Monty', myname LIKE 'Monty  ' FROM names;
+---------------------+-----------------------+
| myname LIKE 'Monty' | myname LIKE 'Monty  ' |
+---------------------+-----------------------+
|                   1 |                     0 |
+---------------------+-----------------------+
1 row in set (0.00 sec)

MariaDB [test]> SELECT * FROM names where myname like '%Monty%';
+--------+
| myname |
+--------+
| Monty  |
+--------+
1 row in set (0.00 sec)

MariaDB [test]> SELECT * FROM names where myname like 'Monty%';
+--------+
| myname |
+--------+
| Monty  |
+--------+
1 row in set (0.00 sec)

MariaDB [test]> SELECT * FROM names where myname like 'Monty %';
Empty set (0.00 sec)

MariaDB [test]> SELECT * FROM names where myname like 'Monty  %';
Empty set (0.00 sec)

MariaDB [test]> SELECT * FROM names where myname like 'Monty   %';
Empty set (0.00 sec)
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

会东县| 读书| 定远县| 铜鼓县| 浠水县| 隆回县| 镇江市| 东源县| 南皮县| 威海市| 乐至县| 蓝田县| 凤城市| 永定县| 水富县| 五家渠市| 木兰县| 尤溪县| 赤水市| 新龙县| 区。| 伽师县| 安顺市| 齐河县| 苏尼特左旗| 宝山区| 木里| 宜宾市| 额尔古纳市| 敦化市| 莱西市| 陵川县| 隆安县| 乌拉特中旗| 区。| 浙江省| 万盛区| 商都县| 皋兰县| 舟山市| 龙口市|