Sample Exam Questions

From the objective of OSS-DB Exam Silver
S3.2 Functions and operators (String functions)

Sample Question

3.23

Choose one incorrect description for a function that handles strings.

  1. character_length is a function that returns the length of a string in characters. For example, character_length('josé') returns 4.
  2. byte_length is a function that returns the length of a string in bytes. For example, in a database with a UTF-8 character set, byte_length('josé') returns 5.
  3. substring is a function that returns a substring. For example, substring('12345678' from 3 for 2) returns '34'.
  4. replace is a function that replaces strings. For example, replace('12341234', '2', 'x') returns '1x341x34'.
  5. trim is a function that removes whitespace from both ends of a string. For example, trim(' abc ') returns 'abc'.

※This sample exam is different from those that appear in the actual OSS-DB Exam.
2024/05/02

Answer and Explanation

To obtain the length (in characters) of a string, use the function 'character_length'. It correctly counts the number of characters, even for multibyte characters. You can also use 'char_length' or 'length', which have the same functionality.

To obtain the length (in bytes) of a string, use the function 'octet_length'. The function 'byte_length' does not exist. For languages that involve multibyte characters, such as Japanese, the number of bytes per character varies depending on the type of encoding. However, the function returns the byte count according to the encoding of the database server.

There is a function called 'substring' that extracts a part of a string. There are several patterns for the arguments, but the standard usage is to specify from which character and how many characters to extract, using 'from' and 'for', as in option C.

replace is a function that replaces a specific character in a string. As in option D, you pass the substring to be replaced and the replacement string as arguments.

trim is a function that removes whitespace from both ends of a string. There are also functions like ltrim, which only removes leading whitespace, and rtrim, which only removes trailing whitespace. However, you can achieve the same effect as ltrim and rtrim by specifying 'leading' or 'trailing' as an argument to trim.

This is a question where you need to select the incorrect option, so the correct answer is B.