Home > Database > Oracle > How to add spaces to Oracle splicing fields

How to add spaces to Oracle splicing fields

下次还敢
Release: 2024-04-18 20:09:12
Original
1103 people have browsed it

In Oracle, the || operator can be used to splice fields, and a single quotation mark '' can be used when inserting spaces between fields. For example, concatenate the FirstName and LastName fields and add spaces: SELECT FirstName || ' ' || LastName AS FullName FROM myTable;

How to add spaces to Oracle splicing fields

How in Oracle Concatenate fields and add spaces

In Oracle, you can concatenate strings using the || operator. To add spaces, just use a single quote (') between the strings where you want to insert spaces.

Syntax:

<code>表达式1 || ' ' || 表达式2</code>
Copy after login

Example:

Suppose we have two fields: FirstName and LastName. To concatenate these two fields and add a space, we can use the following query:

<code class="sql">SELECT FirstName || ' ' || LastName AS FullName
FROM myTable;</code>
Copy after login

Output:

FullName
John Doe
Jane Smith
Mike Jones

Additional examples:

  • To add multiple spaces between fields, you can use multiple single quotes:
<code class="sql">SELECT FirstName || '   ' || LastName AS FullName
FROM myTable;</code>
Copy after login
  • To add a space before or after a field, you can use the following syntax:
<code class="sql">SELECT ' ' || FirstName || LastName AS FullName
FROM myTable;

SELECT FirstName || LastName || ' ' AS FullName
FROM myTable;</code>
Copy after login
  • To add a newline, you can use chr(10 ) Function:
<code class="sql">SELECT FirstName || chr(10) || LastName AS FullName
FROM myTable;</code>
Copy after login

The above is the detailed content of How to add spaces to Oracle splicing fields. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template