15.10 - TITLE - Teradata Database

Teradata Database SQL Data Types and Literals

prodname
Teradata Database
vrm_release
15.10
category
Programming Reference
featnum
B035-1143-151K

Defines a heading for displayed or printed results that is different from the column name, which is used by default.

where:

 

Syntax element …

Specifies …

char_string

a character string literal that defines a column name heading.

TITLE is a Teradata extension to the ANSI SQL:2011 standard.

The maximum length for the column name heading is 256 Unicode characters.

A TITLE phrase submitted in BTEQ can be up to three lines.

A double slash character (//) defines a line break. You can insert blanks to center lines.

You can use the TITLE phrase in a CREATE TABLE or ALTER TABLE statement to specify a standard heading.

You can use the TITLE function to get the title for a specified expression or column. For information, see SQL Functions, Operators, Expressions, and Predicates.

The following example shows a simple use of the TITLE phrase.

   CREATE TABLE Charges, 
   FALLBACK 
    (EmpNo SMALLINT FORMAT '9(5)' TITLE 'Employee//Id' BETWEEN 10001 AND 32001 NOT NULL,
     Proj_Id CHAR(8) TITLE 'Project//  Id' NOT NULL, 
     WkEnd DATE FORMAT 'YYYY/MM/DD' TITLE 'Week//Ending', 
     Hours DECIMAL(4,1) FORMAT 'ZZ9.9' BETWEEN 0.5 AND 999.5) 
   PRIMARY INDEX (EmpNo, Proj_Id) 
   INDEX (Proj_Id);

When a title is specified at column creation time, note that the defined column name, not the title name, must be specified in statements that access the column. For example, to retrieve the total hours worked on each project by user Peterson, the project column must be referenced:

   SELECT Proj_Id, SUM(Hours) 
   FROM CHARGES 
   WHERE EmpNo = 10001
   GROUP BY Proj_Id ORDER BY Proj_Id ;

The returned report, however, uses the following title headings:

    Project
         Id     Sum(Hours)
   --------     ----------
   PAY-0001            9.5
   PAY-0002           34.5

A TITLE phrase also can be given in the retrieval statement to override a default title.

For example, in the following SELECT statement, a TITLE phrase provides a more descriptive heading for the DOB column.

   SELECT Name, DOB (TITLE 'Birthdate') 
   FROM Employee; 

This statement returns:

   Name         ­Birthdate
   --------     ---------
   Smith T       51/10/31
   Newman P      56/08/29
   Omura H       54/04/24
      .            .
      .            .

The multiline TITLE definition in this statement:

   SELECT Name, DOB (TITLE 'Date//Of//Birth') 
   FROM Employee;

returns:

                Date
                  Of
Name           ­Birth
--------    --------
Smith T     51/10/31
Newman P    56/08/29
Omura H     54/04/24
   .           .
   .           .

Teradata SQL uses the following rules to generate a title for expression x:

 

IF x is …

THEN …

a column reference with an explicit TITLE phrase

that title value is returned.

Here is an example:

The explicit title for Project.ProjId, as defined in the CREATE TABLE statement for the Project table, is Project//Id.

The following statement returns the indicated result.

SELECT Proj_Id 
FROM Project
WHERE Description='O/E Batch System';
Project
     Id
--------
OE2‑0003

a column reference with no explicit TITLE

the column name is returned.

Here is an example:

The Salary column has no explicit TITLE.

The following statement returns the indicated result.

SELECT Salary 
FROM Employee
WHERE EmpNo = 10002;
Salary
---------
35,000.00

a constant

TITLE is a character representation of that constant. The character representation of the constant could be the identical characters or a normalized form of the constant.

Here is an example:

The following statement returns 12 as the column heading for the value 12.

SELECT Name, 12 
FROM Employee
WHERE EmpNo = 10003;
Name     12
-------  --
Leidner  12

of the form “operator y”, where operator is a unary (+ or -) or aggregate operator

TITLE is ‘operator’ followed by ‘(y)’

Here is an example:

The following statement returns the aggregate operator name (SUM) as part of the column title.

SELECT SUM(Salary) 
FROM Employee
WHERE DeptNo = 700;
Sum(Salary)
-----------
113,000.00

of the form
“y operator z”

y followed by “operator” followed by z.

Here is an example:

The following statement returns the headings of the column data for which the computation is performed and the operator.

SELECT Salary_Loan - 1000
FROM Employee_Loan
WHERE EmpNo = 10004;
Salary_Loan - 1000
------------------
          41000.00

an attribute function of the form “function (y)”

TITLE is function, followed by (y).

Here is an example:

The following statement returns the indicated result.

SELECT FORMAT (Employee.EmpNo);
Format(EmpNo)
-------------
ZZZZ9

of the form
“y (data_description)”, where data_description does
not contain a TITLE phrase or a NAMED phrase

TITLE is (y).

Here is an example:

The following statement returns the indicated result.

SELECT YrsExp (BYTEINT) 
FROM Employee
WHERE EmpNo = 10016;
YrsExp
------
    20

of the form
“y (data_description)”, where data_description does not contain a TITLE phrase, but does contain a NAMED phrase

TITLE is the name that is specified in the NAMED phrase.

Here is an example:

The following statement returns the indicated result.

SELECT YrsExp (BYTEINT, NAMED YearsOfExperience)
FROM Employee
WHERE EmpNo = 10016;
YearsOfExperience
-----------------
               20

of the form
“y (data_description)”, where data_description contains a TITLE phrase

TITLE is the title that is specified by the phrase.

Here is an example:

The following statement returns the indicated result.

SELECT Salary (INTEGER, TITLE 'Pay') 
FROM Employee
WHERE EmpNo = 10018;
Pay
-----
65000

The number of dashes used to define column width is an attribute of BTEQ.

You can modify this display by including a FORMAT phrase in the SELECT statement.