search
Homephp教程PHP开发Oracle minus usage details and application examples

Oracle minus usage

"Minus" is directly translated into Chinese as "minus". It is also used for subtraction operations in Oracle, but it is not the subtraction of numbers in the traditional sense, but Is the subtraction of the query result set. A minus B means the result of removing all records contained in result set B from result set A, that is, records that exist in A but not in B. The algorithm is similar to RemoveAll() of Collection in Java, that is, A minus B will only remove the intersection of A and B. No operations will be performed on records that exist in B but not in A, and no exception will be thrown. .

Oracle’s minus is compared by column, so the prerequisite for A to minus B is that result set A and result set B need to have the same number of columns, and the columns with the same column index have the same data type. . In addition, Oracle will deduplicate the result set after minus. That is, if there are originally multiple identical records in A, only one corresponding record will remain after A minus B. For details, please see the example below.

Let’s look at an example of practical application of minus. Suppose we have a user table t_user with the following record data:

Oracle minus用法详解及应用实例

Then:

(1) The result of "select id from t_user where id

Oracle minus用法详解及应用实例

(2 ) The result of "select age,level_no from t_user where id

Oracle minus用法详解及应用实例

Seeing such a result, maybe You may feel a little strange, why is this? Let's analyze it. First, the result of "select age,level_no from t_user where id

Oracle minus用法详解及应用实例

Then, "select age,level_no from t_user where level=3" The result will be like this:

Oracle minus用法详解及应用实例

Then, directly after A minus B, the result should be:

Oracle minus用法详解及应用实例

At this time , we can see that there are duplicate records in the result set, and after deduplication, the above actual results are obtained. In fact, this is easy to understand, because the function of minus is to find the records that exist in A but not in B.

The above examples are all for a single table. Obviously, there is no advantage in using minus for single table operations. It is usually used to find out that some fields in table A do not exist in table B. Corresponding to the recorded situation. For example, we have another table t_user2, which has the same table structure as the t_user table. Then the following statement can find the records that exist in the t_user table but do not exist in the t_user2 table except for id.

select no,name,age,level_no from t_user minus select no,name,age,level_no from t_user2;

Thank you for reading, I hope it can help everyone, thank you for your support of this site!

For more detailed explanations of Oracle minus usage and application examples, please pay attention to 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)