Using UPPER() on Text Data

From InterBase

Go Up to Understanding SQL Expressions


The UPPER() function can be used in SELECT, INSERT, UPDATE, or DELETE operations to force character and Blob text data to uppercase. For example, an application that prompts a user for a department name might want to ensure that all department names are stored in uppercase to simplify data retrieval later. The following code illustrates how UPPER() would be used in the INSERT statement to guarantee a user’s entry is uppercase:

EXEC SQL
BEGIN DECLARE SECTION;
char response[26];
EXEC SQL
END DECLARE SECTION;
. . .
printf("Enter new department name: ");
response[0] = '\0';
gets(response);
if (response)
EXEC SQL
INSERT INTO DEPARTMENT(DEPT_NO, DEPARTMENT)
VALUES(GEN_ID(GDEPT_NO, 1), UPPER(:response));
. . .

The next statement illustrates how UPPER() can be used in a SELECT statement to affect both the appearance of values retrieved, and to affect its search condition:

EXEC SQL
SELECT DEPT_NO, UPPER(DEPARTMENT)
FROM DEPARTMENT
WHERE UPPER(DEPARTMENT) STARTING WITH 'A';

Advance To: