ARRAY
ARRAY is a data type used to represent a value composed of a sequence of elements of the same type. This data type can store a series of elements sharing the same data type, making it convenient for unified management and operations.
Syntax
: Specifies the data type of the elements in the array.elementType
ARRAY Constant Format
This format represents an array constant. When defining an array constant, do not use quotes, because quotes will cause it to be recognized as a string type, and the string
'[1,3,4]' cannot be directly converted to array<int> type using CAST.
Examples
-
Create an integer array:
Result:
result [1, 2, 3] -
Convert an integer array to a string array:
Result:
result ["1", "2", "3"] -
Get the data type of array elements:
Result:
result array<decimal(2,1)> -
Create a nested array (an array containing other arrays):
Result:
result [[10.00, 20.00], [30.00, 40.00]] -
Get a specific element from an array:
Result:
result 10 -
Use
to check if a specific element exists in an array:ARRAY_CONTAINSResult:
Result true -
Sort an array:
Result:
result [1, 2, 3] -
Merge two arrays:
Result:
result [2,1,3,5]
