Example: Query 2-D ARRAY Data Type and Table Using OCOUNT - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-04-03
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

Consider the following 2-D ARRAY data type and table.

CREATE TYPE shot_ary AS VARRAY(1:50)(1:50) OF INTEGER;
CREATE TABLE seismic_table (
   id INTEGER,
   shots shot_ary);

The table is populated with the following values:

/* The first 2 elements are populated; the rest are uninitialized. */
INSERT INTO seismic_table VALUES (1, shot_ary(11, 12));
/* Empty ARRAY instance */
INSERT INTO seismic_table VALUES (2, shot_ary());
/* Update the empty ARRAY instance such that element [1][3] is set to a value; then elements [1][1] and [1][2] are set to NULL, the rest are uninitialized */
UPDATE seismic_table
SET shots[1][3] = 1133
WHERE id = 2;

The following query returns the number of elements in the shots array that contain NULL or values that are non-NULL.

SELECT id, shots.OCOUNT()
FROM seismic_table;

The following is the result of the query.

ID          shots.OCOUNT()
--          --------------
 1           2    (the first 2 elements contain values that are non-NULL)
 2           3    (the first 3 elements contain NULL or values that are non-NULL)

The following is the same query using function-style syntax.

SELECT id, OCOUNT(shots)
FROM seismic_table;