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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use