Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

String Functions

Updated on 2025-01-24 GMT+08:00

Description

SQL provides the string function for concatenating strings and converting between uppercase and lowercase letters. For details, see Table 1.

NOTE:

In the SQL syntax, characters must be enclosed in single quotation marks ('). Fields or table names are not enclosed or are enclosed with double quotation marks ("). For example, 'msg' indicates the character string msg, and msg or "msg" indicates the structured msg field.

Syntax

SELECT (fieldname1 || fieldname2) AS fieldname1_fieldname2

String Function Statements

Table 1 String function statements

Statement

Description

Example

CONCAT(expr1, expr2...)

Concatenates all listed strings.

SELECT str1, str2, str3, CONCAT(str1, str2, str3)

WHERE str1 IS NOT NUll

TEXTCAT(expr, expr)

Concatenates two strings.

SELECT str1, str2, TEXTCAT(str1, str2)

WHERE str1 IS NOT NUll

STRING_FORMAT(pattern[, args...])

Formats strings based on the Java string format.

SELECT str1, STRING_FORMAT(str1, '%s')

WHERE str1 IS NOT NUll

LENGTH(expr)

Returns the length of a string, which is the number of UTF-16 characters in the string.

SELECT LENGTH(str1)

WHERE str1 IS NOT NUll

LOWER(expr)

Converts a string into lowercase letters.

SELECT LOWER(str1)

WHERE str1 IS NOT NUll

POSITION(string1 IN string2 [FROM fromIndex])

Returns the index of the position where string1 appears in string2 for the first time. The search starts from the specified index. If no index is specified, the search starts from index1. If string1 does not exist in string2, 0 is returned.

SELECT POSITION(str1 IN str2 FROM 5)

REGEXP_EXTRACT(expr, pattern, [index])

Extracts a string that matches a specified regular expression in expr. The index starts from 1. If no match is found, null is returned. If no index is specified or the index is 0, the first matched substring is returned. For exact match, add a caret (^) before the regular expression and a dollar sign ($) after the regular expression.

SELECT REGEXP_EXTRACT(str1, '[A-Za-z]+://[A-Za-z0-9.-]+(/[^ ]*)', 5)

REGEXP_LIKE(expr, pattern)

Checks whether a string matches a specified regular expression. For exact match, add a caret (^) before the regular expression and a dollar sign ($) after the regular expression. The usage of this function is similar to that of the LIKE statement. The difference is that the LIKE statement searches for content with a specified pattern.

SELECT REGEXP_LIKE(str1, '\.(jpg|jpeg|png|gif)$')

REPLACE(expr, pattern, replacement)

Uses replacement to replace the substring same as pattern in expr.

SELECT REPLACE(expr,pattern, replacement)

STRPOS(string1, string2)

Returns the index of the position where string2 appears in string1 for the first time. The search starts from index1. If no result is found, 0 is returned.

SELECT STRPOS(str1, str2)

WHERE str1 IS NOT NUll

AND str2 IS NOT NUll

SUBSTRING(expr, index, [length])

Subtracts a string. length indicates how many UTF-16 characters will be extracted.

SELECT SUBSTRING(str1, 3, 10)

WHERE str1 IS NOT NUll

RIGHT(expr, [length])

Truncates a specified length from the right to the left of a string.

SELECT RIGHT(str1, 5)

WHERE str1 IS NOT NUll

LEFT(expr, [length])

Truncates a specified length from the left to the right of a string.

SELECT LEFT(str1, 5)

WHERE str1 IS NOT NUll

SUBSTR(expr, index, [length])

Same as SUBSTRING.

SELECT SUBSTR(str1, 3, 10)

WHERE str1 IS NOT NUll

UPPER(expr)

Converts a string into uppercase letters.

SELECT UPPER(str1)

WHERE str1 IS NOT NUll

REVERSE(expr)

Reverses the character string.

SELECT REVERSE(str1)

WHERE str1 IS NOT NUll

LPAD(expr, length, chars)

Adds specified characters to the left of a string until the string reaches the specified length. If the specified length is less than the actual string length, the string is truncated based on the specified length. If the string or the specified character is null, null is returned. If the specified character is empty, no padding is performed. Characters may be deleted if necessary.

SELECT LPAD(str1, 50, 'testStr')

WHERE str1 IS NOT NUll

RPAD(expr, length, chars)

Adds specified characters to the right of a string until the string reaches the specified length. If the specified length is less than the actual string length, the string is truncated based on the specified length. If the string or the specified character is null, null is returned. If the specified character is empty, no padding is performed. Characters may be deleted if necessary.

SELECT RPAD(str1, 50, 'testStr')

WHERE str1 IS NOT NUll

CONTAINS_STRING(<expr>, str)

Checks whether expr contains the str string.

SELECT CONTAINS_STRING(log_level,'warn')

ICONTAINS_STRING(<expr>, str)

Checks whether expr contains the str string. The string is not case sensitive.

SELECT ICONTAINS_STRING(log_level,'WARN')

Examples

REPEAT

REPEAT(expr, [N]) repeats expr for N times.

  1. Example field

    field4:is

  2. Query and analysis statement
    select field4,REPEAT(field4,3)
  3. Query and analysis result
    Table 2 Query and analysis result

    field4

    EXPR$1

    Is

    isisis

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback