La fonction NET_HOST extrait le nom d'hôte (hostname) d'une URL de type STRING.
Syntaxe
STRING NET_HOST(STRING <url>)
Paramètres
url : obligatoire. Type STRING. URL à analyser.
Pour une analyse optimale, l'URL doit respecter le format défini par la RFC 3986.
Valeur de retour
Renvoie une valeur de type STRING correspondant au nom d'hôte extrait de l'URL.
Le numéro de port est conservé dans le résultat s'il est présent.
Renvoie NULL si l'analyse de l'URL échoue.
Fonctions d'analyse associées
Pour analyser d'autres parties de l'URL que le nom d'hôte, utilisez les fonctions suivantes :
NET_PUBLIC_SUFFIX : extrait le suffixe public (par exemple com, org ou net) de l'URL.
NET_REG_DOMAIN : extrait le domaine enregistré ou enregistrable de l'URL (c'est-à-dire le suffixe public plus l'étiquette précédente).
Exemples
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 |
+-----------------------------------+-------------------------------------------------------------------------------+-------------------+------------+---------------+
Fonctions associées
La fonction NET_HOST fait partie des fonctions réseau. Pour plus d'informations sur les autres fonctions liées au réseau, consultez la rubrique Network Functions Overview.