This topic describes how to use the string function KEYVALUE in Realtime Compute.

Syntax

VARCHAR KEYVALUE(VARCHAR str, VARCHAR split1, VARCHAR split2, VARCHAR key_name)      

Input parameters

Parameter Data type Description
str VARCHAR The key-value pairs in the specified string.
split1 VARCHAR The separator used between key-value pairs.
split2 VARCHAR The separator used between the key and value in each key-value pair.
key_name VARCHAR The name of a key.

Description

Parses the key-value pairs in a string based on the key-value pair separator and key-value separator, and then returns the value for the specified key name. If the key name does not exist or an exception occurs, null is returned.

Example

  • Test data
    str (VARCHAR) split1 (VARCHAR) split2 (VARCHAR) key1 (VARCHAR)
    k1=v1;k2=v2 ; = k2
    null ; | :
    k1:v1|k2:v2 null = :
    k1:v1|k2:v2 | = null
    k1:v1|k2:v2 | = :
  • Test statements
    SELECT KEYVALUE(str, split1, split2, key1) as 'result'
    FROM T1;         
  • Test results
    result (VARCHAR)
    v2
    null
    null
    null
    null