DEV Community

Cong Li
Cong Li

Posted on

Introduction to the UPPER Function in GBase 8s

GBase databases offer a variety of string manipulation functions. This article provides a detailed introduction to the UPPER function in GBase 8s, including its functionality, syntax, important considerations, and practical examples.

Overview of the UPPER Function

The UPPER function accepts a string expression as a parameter and returns a string where every lowercase letter in the expression is replaced by its corresponding uppercase letter.

The following example uses the UPPER function to perform a case-insensitive search on the lname column for all employees with the last name "Curran":

SELECT title, INITCAP(fname), INITCAP(lname) 
FROM employees 
WHERE UPPER(lname) = 'CURRAN';
Enter fullscreen mode Exit fullscreen mode

Since the INITCAP function is specified in the projection list, the database server returns the results in mixed case format.

For example, the output for a matching row could be: accountant James Curran.

Function Syntax

Where char is the input parameter to the function. This can be a column name, a string literal, or another expression. The result of the function will be a new string with all lowercase letters converted to uppercase. It's important to note that the UPPER function does not modify non-alphabetic characters, such as numbers, punctuation, or spaces.

Image description

Considerations

  • If the string already contains uppercase letters, the UPPER function will only convert lowercase letters.
  • Non-alphabetic characters remain unchanged.
  • If the input string is NULL, the function will return NULL.
  • The function name UPPER is not case-sensitive.
  • The UPPER function can be nested with other functions to enable more complex string manipulations.

Examples

To better understand the usage of the UPPER function, here are a few practical query examples:

  • Converting a lowercase string to uppercase:
SELECT UPPER('abc') FROM dual;
Enter fullscreen mode Exit fullscreen mode
  • If the string contains numbers, the numbers remain unchanged:
SELECT UPPER('abc123') FROM dual;
Enter fullscreen mode Exit fullscreen mode
  • If the string is NULL, the result will also be NULL:
SELECT UPPER(NULL) FROM dual;
Enter fullscreen mode Exit fullscreen mode
  • Real-world example: performing a case-insensitive query based on the last name:
SELECT title, INITCAP(fname), INITCAP(lname) 
FROM employees 
WHERE UPPER(lname) = 'CURRAN';
Enter fullscreen mode Exit fullscreen mode

The query results might look like this:

Image description

Image description

Conclusion

The UPPER function is a powerful and practical string manipulation tool in GBase 8s. It allows you to quickly convert lowercase letters to uppercase, simplifying case-insensitive search operations. Thank you for reading!

Top comments (0)