Examples | OEXISTS Function| Teradata Vantage - 17.10 - Example: Query a 1-D ARRAY Data Type and Table using OEXISTS - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - Data Types and Literals

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1143-171K
Language
English (United States)

Consider the following one-dimensional ARRAY data type and table.

CREATE TYPE phonenumbers AS VARRAY(20) OF CHAR(10);
CREATE TABLE employee_info (eno INTEGER, phonelist phonenumbers);

The table is populated with the following values:

/* The first 2 elements are populated; the rest are uninitialized. */
INSERT INTO employee_info VALUES (1, 
   phonenumbers('1112223333', '6195551234'));
/* Empty ARRAY instance */
INSERT INTO employee_info VALUES (2, 
   phonenumbers());
/* Update the empty ARRAY instance such that element 3 is set to a value; then elements 1 and 2 are set to NULL, the rest are uninitialized. */
UPDATE employee_info
SET phonelist[3] = '8584850000'
WHERE id = 2;

The following query checks to see whether element 2 of the phonelist array contains a value.

SELECT eno, phonelist.OEXISTS(2)
FROM employee_info;

The following is the result of the query.

ENO         phonelist.OEXISTS(2)
---         --------------------
  1           1           (element 2 contains a value that is non-NULL)
  2           1           (element 2 contains a NULL)

The following query checks to see whether element 3 of the phonelist array contains a value.

SELECT eno, phonelist.OEXISTS(3)
FROM employee_info;

The following is the result of the query.

ENO         phonelist.OEXISTS(3)
---         --------------------
  1           0           (element 3 is in an uninitialized state)
  2           1           (element 3 contains a value that is non-NULL)

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

SELECT eno, OEXISTS(phonelist, 3)
FROM employee_info;