Home  >  Article  >  Database  >  Usage of (+) in oracle

Usage of (+) in oracle

下次还敢
下次还敢Original
2024-05-08 18:39:17285browse

( ) in Oracle represents OUTER JOIN, which is used to merge rows from different tables, even if some rows have no matching. Usage: ( ) is placed after the forced inclusion row to create a LEFT, RIGHT or FULL OUTER JOIN. Advantages: Provides a complete data set, including rows with no matching rows; simplifies queries and avoids the use of subqueries or UNIONs.

Usage of (+) in oracle

Usage of ( ) in Oracle

What is ( )?

In Oracle, () is called "OUTER JOIN" and is used to merge rows from different tables in a query, even if some rows in one or both tables have no matching rows.

( ) Usage:

( ) is placed after the line you want to force inclusion, as follows:

<code>SELECT *
FROM table1 t1
INNER JOIN table2 t2 ON t1.id = t2.id(+)</code>

( ) How Work?

( ) pairs rows from the right table with rows from the left table in OUTER JOIN. If matching rows are found, they are merged into the result set. If no matching row is found, the row from the right-hand table is still included in the result set, but is associated with the NULL value from the left-hand table.

OUTER JOIN type:

( ) Different types of OUTER JOIN can be created according to the connection conditions:

  • LEFT OUTER JOIN (INNER): Returns all rows from the left table, even if there are no matching rows from the right table.
  • RIGHT OUTER JOIN (RIGHT): Returns all rows from the right table, even if there are no matching rows in the left table.
  • FULL OUTER JOIN (FULL): Returns all rows from the left and right tables, even if they have no matching rows.

Example:

The following example shows the usage of ( ) in LEFT OUTER JOIN:

<code>SELECT *
FROM employees e
LEFT OUTER JOIN departments d ON e.department_id = d.department_id(+)</code>

This query will return all employees , even if they don't have a matching department. Unmatched employees will be associated with NULL departments.

Advantages:

Advantages of using () include:

  • Get the complete data set from all related tables, even if some rows No match.
  • Simplify the query and avoid using subqueries or UNION statements.

The above is the detailed content of Usage of (+) in oracle. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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