NET_HOST函數用於從STRING類型的URL字串中解析主機名稱(hostname)部分。
命令格式
STRING NET_HOST(STRING <url>)參數說明
url:必填。STRING類型。待解析的URL字串。
說明
為了獲得最佳解析結果,URL字串應符合RFC 3986定義的格式。
傳回值說明
返回STRING類型。解析給定的URL並返回其中的主機名稱部分。
若包含連接埠號碼,連接埠號碼也會保留在返回結果中。
若函數無法解析輸入的URL,則返回NULL。
相關解析函數
若需要解析URL中除主機名稱的其他部分,可以使用如下函數:
NET_PUBLIC_SUFFIX:解析給定的URL中的公用尾碼(如com、org或net)。
NET_REG_DOMAIN: 解析給定的URL中登入或可註冊的網域名稱(即公用尾碼加上前一級標籤)。
使用樣本
SELECT input
,description
,NET_HOST(input) AS HOST
,NET_PUBLIC_SUFFIX(input) AS SUFFIX
,NET_REG_DOMAIN(input) AS DOMAIN
FROM (
SELECT "" AS input, "invalid input" AS description
UNION ALL SELECT "http://abc.xyz", "standard URL"
UNION ALL SELECT "//user:password@a.b:80/path?query",
"standard URL with relative scheme, port, path and query, but no public suffix"
UNION ALL SELECT "https://[::1]:80", "standard URL with IPv6 host"
UNION ALL SELECT "http://例子.捲筒紙.中國", "standard URL with internationalized domain name"
UNION ALL SELECT " www.Example.Co.UK ",
"non-standard URL with spaces, upper case letters, and without scheme"
UNION ALL SELECT "mailto:?to=&subject=&body=", "URI rather than URL--unsupported"
);
+-----------------------------------+-------------------------------------------------------------------------------+-------------------+------------+---------------+
| input | description | host | suffix | domain |
+-----------------------------------+-------------------------------------------------------------------------------+-------------------+------------+---------------+
| | invalid input | NULL | NULL | NULL |
| http://abc.xyz | standard URL | abc.xyz | xyz | abc.xyz |
| //user:password@a.b:80/path?query | standard URL with relative scheme, port, path and query, but no public suffix | a.b | NULL | NULL |
| https://[::1]:80 | standard URL with IPv6 host | [::1] | NULL | NULL |
| http://例子.捲筒紙.中國 | standard URL with internationalized domain name | 例子.捲筒紙.中國 | 中國 | 捲筒紙.中國 |
| www.Example.Co.UK | non-standard URL with spaces, upper case letters, and without scheme | www.Example.Co.UK | Co.UK | Example.Co.UK |
| mailto:?to=&subject=&body= | URI rather than URL--unsupported | mailto | NULL | NULL |
+-----------------------------------+-------------------------------------------------------------------------------+-------------------+------------+---------------+相關函數
NET_HOST函數屬於網路函數,更多網路相關函數請參見網路函數。