This topic describes the syntax of URL functions. This topic also provides examples on how to use the functions.
- The format of a URL is
[protocol:][//host[:port]][path][?query][#fragment]
. - If you want to use strings in analytic statements, you must enclose strings in single quotation marks (''). Strings that are not enclosed or enclosed in double quotation marks ("") indicate field names or column names. For example, 'status' indicates the status string, and status or "status" indicates the status log field.
Function | Syntax | Description |
---|---|---|
url_encode function | url_encode(x) | Encodes a URL. |
url_decode function | url_decode(x) | Decodes a URL. |
url_extract_fragment function | url_extract_fragment(x) | Extracts the fragment from a URL. |
url_extract_host function | url_extract_host(x) | Extracts the host from a URL. |
url_extract_parameter function | url_extract_parameter(x,parameter name) | Extracts the value of a specified parameter in the query string from a URL. |
url_extract_path function | url_extract_path(x) | Extracts the path from a URL. |
url_extract_port function | url_extract_port(x) | Extracts the port number from a URL. |
url_extract_protocol function | url_extract_protocol(x) | Extracts the protocol from a URL. |
url_extract_query function | url_extract_query(x) | Extracts the query string from a URL. |
url_encode function
The url_encode function is used to encode a URL.
Syntax
url_encode(x)
Parameters
Parameter | Description |
---|---|
x | The value of this parameter is a specific URL. |
Return value type
The varchar type.
Examples
Encode the value of the url field.
- Sample field
url:https://homenew.console.aliyun.com/home/dashboard/ProductAndService
- Query statement
* | select url_encode(url)
- Query and analysis result
url_decode function
The url_decode function is used to decode a URL.
Syntax
url_decode(x)
Parameters
Parameter | Description |
---|---|
x | The value of this parameter is an encoded URL. |
Return value type
The varchar type.
Examples
Decode the value of the url field.
- Sample field
url:http%3A%2F%2Fwww.aliyun.com%3A80%2Fproduct%2Fsls
- Query statement
* | SELECT url_decode(url) AS decode
- Query and analysis result
url_extract_fragment function
The url_extract_fragment function is used to extract the fragment from a URL.
Syntax
url_extract_fragment(x)
Parameters
Parameter | Description |
---|---|
x | The value of this parameter is a specific URL. |
Return value type
The varchar type.
Examples
Extract the fragment from the value of the url field.
- Sample field
url:https://sls.console.aliyun.com/#/project/dashboard-demo/categoryList
- Query statement
* | SELECT url_extract_fragment(url)
- Query and analysis result
url_extract_host function
The url_extract_host function is used to extract the host from a URL.
Syntax
url_extract_host(x)
Parameters
Parameter | Description |
---|---|
x | The value of this parameter is a specific URL. |
Return value type
The varchar type.
Examples
Extract the host from the value of the url field.
- Sample field
url:https://homenew.console.aliyun.com/home/dashboard/ProductAndService
- Query statement
* | SELECT url_extract_host(url) AS host
- Query and analysis result
url_extract_parameter function
The url_extract_parameter function is used to extract the value of a specified parameter in the query string from a URL.
Syntax
url_extract_parameter(x,parameter name)
Parameters
Parameter | Description |
---|---|
x | The value of this parameter is a specific URL. |
parameter name | The name of the parameter in the query string of the URL. |
Return value type
The varchar type.
Examples
Extract the value of the accounttraceid parameter from the value of the url field.
- Sample field
url:https://sls.console.aliyun.com/lognext/project/dashboard-all/logsearch/nginx-demo?accounttraceid=d6241a173f88471c91d3405cda010ff5ghdw
- Query statement
* | SELECT url_extract_parameter(url,'accounttraceid') AS accounttraceid
- Query and analysis result
url_extract_path function
The url_extract_path function is used to extract the path from a URL.
Syntax
url_extract_path(x)
Parameters
Parameter | Description |
---|---|
x | The value of this parameter is a specific URL. |
Return value type
The varchar type.
Examples
Extract the path from the value of the url field.
- Sample field
url:https://sls.console.aliyun.com/lognext/project/dashboard-all/logsearch/nginx-demo?accounttraceid=d6241a173f88471c91d3405cda010ff5ghdw
- Query statement
* | SELECT url_extract_path(url) AS path
- Query and analysis result
url_extract_port function
The url_extract_port function is used to extract the port number from a URL.
Syntax
url_extract_port(x)
Parameters
Parameter | Description |
---|---|
x | The value of this parameter is a specific URL. |
Return value type
The varchar type.
Examples
Extract the port number from the value of the url field.
- Sample field
url:http://localhost:8080/lognext/profile
- Query statement
* | SELECT url_extract_port(url) AS port
- Query and analysis result
url_extract_protocol function
The url_extract_protocol function is used to extract the protocol from a URL.
Syntax
url_extract_port(x)
Parameters
Parameter | Description |
---|---|
x | The value of this parameter is a specific URL. |
Return value type
The varchar type.
Examples
Extract the protocol from the value of the url field.
- Sample field
url:https://homenew.console.aliyun.com/home/dashboard/ProductAndService
- Query statement
* | SELECT url_extract_protocol(url) AS protocol
- Query and analysis result
url_extract_query function
The url_extract_query function is used to extract the query string from a URL.
Syntax
url_extract_query(x)
Parameters
Parameter | Description |
---|---|
x | The value of this parameter is a specific URL. |
Return value type
The varchar type.
Examples
Extract the query string from the value of the url field.
- Sample field
url:https://sls.console.aliyun.com/lognext/project/dashboard-all/logsearch/nginx-demo?accounttraceid=d6241a173f88471c91d3405cda010ff5ghdw
- Query statement
* | SELECT url_extract_query(url)
- Query and analysis result