透過在 MySQL 中傳遞名稱來獲取域名?
要透過在 MySQL 中傳遞名稱來獲取域名,可以使用 substring_index()。我們首先建立一個表 -
mysql> create table DemoTable ( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserMailId varchar(200) ); Query OK, 0 rows affected (0.77 sec)
使用 insert 命令在表中插入一些記錄 -
mysql> insert into DemoTable(UserMailId) values('John9989@facebook.com'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(UserMailId) values('983773CS@yahoo.com'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable(UserMailId) values('Chris95@gmail.com'); Query OK, 1 row affected (0.20 sec)
使用 select 語句從表中顯示所有記錄 -
mysql> select *from DemoTable;
這將產生以下輸出 -
+--------+-----------------------+ | UserId | UserMailId | +--------+-----------------------+ | 1 | John9989@facebook.com | | 2 | 983773CS@yahoo.com | | 3 | Chris95@gmail.com | +--------+-----------------------+ 3 rows in set (0.00 sec)
以下是透過在 MySQL 中傳遞名稱來獲取域名的查詢。
mysql> select UserId,UserMailId, substring_index(substring_index(UserMailId, '@', -1), '.', 1) AS `Domain_Name` from DemoTable;
這將產生以下輸出。在此,獲取了域名 -
+--------+-----------------------+-------------+ | UserId | UserMailId | Domain_Name | +--------+-----------------------+-------------+ | 1 | John9989@facebook.com | facebook | | 2 | 983773CS@yahoo.com | yahoo | | 3 | Chris95@gmail.com | gmail | +--------+-----------------------+-------------+ 3 rows in set (0.01 sec)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP