<<<<<<< HEAD concat | H2 | SQLDoc
Skip to main content

concat

1. CONCAT Function

======= concat | H2 Function | SQLDoc

concat

1. CONCAT Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The CONCAT function in H2 database is used to concatenate two or more strings together.

2. Syntax

The syntax for the CONCAT function in H2 database is as follows:

CONCAT(string1, string2, ...)

Arguments

  • string1, string2, ...: The strings that you want to concatenate. They can be column names, string literals, or a combination of both.

Return

  • The CONCAT function returns a single string that is the result of concatenating all the input strings in the order they are specified.

3. Notes

  • The CONCAT function in H2 database can concatenate any number of strings together.
  • If any of the input strings are NULL, the resulting concatenation will also be NULL. Use the COALESCE function to handle NULL values.
  • The CONCAT function automatically converts non-string values to strings before concatenation.
  • The CONCAT function does not add any delimiters between the concatenated strings. If you want to include delimiters, you need to explicitly specify them as strings in the CONCAT function.

4. Examples

Here are a few examples demonstrating the usage of the CONCAT function in H2 database:

Example 1 - Concatenating two strings:

SELECT CONCAT('Hello', 'World') AS result;

Output:

result
--------
HelloWorld

Example 2 - Concatenating strings stored in columns:

CREATE TABLE names (
first_name VARCHAR(50),
last_name VARCHAR(50)
);

INSERT INTO names VALUES ('John', 'Doe'), ('Jane', 'Smith');

SELECT CONCAT(first_name, ' ', last_name) AS full_name
FROM names;

Output:

full_name
------------
John Doe
Jane Smith

Example 3 - Handling NULL values:

SELECT CONCAT('Hello', NULL, 'World') AS result;

Output:

result
--------
NULL
  • || - Concatenate operator (alternate way to concatenate strings)
  • concat_ws - Concatenate with separator