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 2022-07-29 GMT+08:00

This section describes the following string functions:

LISTAGG

LISTAGG is used to order data in columns within each group specified in the ORDER BY clause and concatenates the order results.

Figure 1 Input - Listagg
Figure 2 Output - Listagg

LISTAGG can be migrated after MigSupportForListAgg is set to false.

Input- LISTAGG

SELECT LISTAGG(BRANCH_ID, ',') WITHIN GROUP(ORDER BY AREA_ORDER) PRODUCTRANGE
                       FROM (SELECT DISTINCT VB.BRANCH_ID,
                                             VB.VER_ID,
                                             VB.AREA_ORDER
                               FROM SPMS_VERSION_BRANCH VB, SPMS_NODE_SET NS
                              WHERE VB.BRANCH_TYPE IN ('1', '3')
                                AND VB.AGENCY_BRANCH = NS.BRANCH_ID);

Output

SELECT LISTAGG (BRANCH_ID,',') WITHIN GROUP (
 ORDER BY AREA_ORDER ) PRODUCTRANGE
 FROM ( SELECT
         DISTINCT VB.BRANCH_ID
         ,VB.VER_ID
         ,VB.AREA_ORDER
          FROM
          SPMS_VERSION_BRANCH VB
         ,SPMS_NODE_SET NS
          WHERE VB.BRANCH_TYPE IN (
           '1','3')
         AND VB.AGENCY_BRANCH = NS.BRANCH_ID)
;

STRAGG

STRAGG is a string aggregate function used to collect values from multiple rows into a comma-separated string.

Input-STRAGG

SELECT DEPTNO,ENAME,STRAGG(ename) over (partition by deptno order by
           ename RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) 
                AS ENAME_STR FROM EMP;

Output

SELECT DEPTNO,ENAME,STRING_AGG (
    ename,',') over( partition BY deptno ORDER BY 
 ename RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED 
 FOLLOWING ) AS ENAME_STR
    FROM EMP
;

WM_CONCAT

WM_CONCAT is used to aggregate data from a number of rows into a single row, giving a list of data associated with a specific value.

Figure 3 Input - WM_Concat
Figure 4 Output - WM_Concat

NVL2 and REPLACE

NVL2( expression, value1, value2) is a function used to determine the value returned by a query based on whether a specified expression is null or not. If the expression is not null, then NVL2 returns value1. If the expression is null, then NVL2 returns value2.

Input - NVL2

NVL2(Expr1, Expr2, Expr3)

Output

DECODE(Expr1, NULL, Expr3, Expr2)

The REPLACE function is used to return char with every occurrence of search_string replaced with replacement_string. If replacement_string is omitted or null, then all occurrences of search_string are removed.

The REPLACE function in Oracle contains two mandatory parameters and one optional parameter. The REPLACE function in GaussDB(DWS) contains three mandatory parameters.

Input - Nested REPLACE

CREATE
     OR REPLACE FUNCTION F_REPLACE_COMMA ( IS_STR IN VARCHAR2 ) RETURN VARCHAR2 IS BEGIN
               IF
                         IS_STR IS NULL
                         THEN RETURN NULL ;
                    ELSE
                    RETURN REPLACE( REPLACE( IS_STR ,'a' ) ,CHR ( 10 ) ) ;
          END IF ;
END F_REPLACE_COMMA ;
/

Output

CREATE
     OR REPLACE FUNCTION F_REPLACE_COMMA ( IS_STR IN VARCHAR2 ) RETURN VARCHAR2 IS BEGIN
               IF
                         IS_STR IS NULL
                         THEN RETURN NULL ;
                    ELSE
                    RETURN REPLACE( REPLACE( IS_STR ,'a' ,'' ) ,CHR ( 10 ) ,'' ) ;
          END IF ;
end ;
/

Input - More than one REPLACE

SELECT
          REPLACE( 'JACK and JUE' ,'J', '' ) "Changes"
          ,REPLACE( 'JACK1 and JUE' ,'J' ) "Changes1"
          ,REPLACE( 'JACK2 and JUE' ,'J' ) "Changes2"
     FROM
          DUAL
;

Output

SELECT
          REPLACE( 'JACK and JUE' ,'J' ,'' ) "Changes"
          ,REPLACE( 'JACK1 and JUE' ,'J' ,'' ) "Changes1"
          ,REPLACE( 'JACK2 and JUE' ,'J' ,'' ) "Changes2"
     FROM
          DUAL
;

Input - REPLACE with Three parameters

SELECT
          REPLACE( '123tech123' ,'123', '1')
     FROM
          dual
;

Output

SELECT
          REPLACE( '123tech123' ,'123' , '1' )
     FROM
          dual
;

QUOTE

QUOTE allows the user to embed single-quotes in literal strings without having to resort to double quotes. That is, you can use single quotes to specify a literal string.

For example:

SELECT q'[I'm using quote operator in SQL statement]' "Quote (q) Operator" FROM dual;
Figure 5 Input - Quote
Figure 6 Output - Quote

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