You can use phone number functions to determine the location and telecom operator for phone numbers in the Chinese mainland. This topic describes their syntax and provides examples.
Log Service supports the following phone number functions.
|
Function name |
Syntax |
Description |
|
mobile_carrier(x) |
Returns the telecom operator of a phone number. |
|
|
mobile_city(x) |
Returns the city of a phone number. |
|
|
mobile_province(x) |
Returns the province of a phone number. |
mobile_carrier function
The mobile_carrier function returns the telecom operator for a specified phone number.
Syntax
mobile_carrier(x)
Parameters
|
Parameter |
Description |
|
x |
Specifies the phone number to analyze. The value must be of the bigint type. If it is not, use the try_cast function to convert it. For more information, see try_cast function. |
Return value type
varchar
Examples
This example shows how to query the telecom operator of a phone number from the mobile field.
-
Sample field
mobile:1881111**** -
Query statement
* | SELECT mobile_carrier(mobile) -
The query returns
China Mobile, the telecom operator associated with the phone number.
mobile_city function
The mobile_city function returns the city for a specified phone number.
Syntax
mobile_city(x)
Parameters
|
Parameter |
Description |
|
x |
Specifies the phone number to analyze. The value must be of the bigint type. If it is not, use the try_cast function to convert it. For more information, see try_cast function. |
Return value type
varchar
Examples
An e-commerce company uses the mobile and client_ip fields in its access logs to identify customers whose phone number's city differs from the city determined by their access IP address.
-
Sample fields
mobile:1881111**** client_ip:192.168.2.0 -
Query statement
* | SELECT mobile, client_ip, count(*) as PV WHERE mobile_city(mobile) != ip_to_city(client_ip) AND ip_to_city(client_ip) != '' GROUP BY client_ip, mobile ORDER BY PV DESC
mobile_province function
The mobile_province function returns the province for a specified phone number.
Syntax
mobile_province(x)
Parameters
|
Parameter |
Description |
|
x |
Specifies the phone number to analyze. The value must be of the bigint type. If it is not, use the try_cast function to convert it. For more information, see try_cast function. |
Return value type
varchar
Examples
An e-commerce company analyzes the mobile field in its access logs to count its customers by province.
-
Sample field
mobile:1881111**** -
Query statement
* | SELECT mobile_province(mobile) AS Province, count(1) AS PV GROUP BY Province ORDER BY PV DESC -
The query returns a result set. For example, a returned row shows the Province as
Zhejiang Provinceand the PV as234782.