In Oracle, "not exists" is used to determine whether a clause returns a result set. If the clause returns a result set, it is false. If the clause does not return a result set, it is true. The syntax is "select * from daul where not exists (clause query condition)".
The operating environment of this tutorial: Windows 10 system, Oracle 11g version, Dell G3 computer.
What is the usage of not exists in oracle
exists: The emphasis is on whether to return the result set, and it is not required to know what is returned. For example:
select name from student where sex = 'm' and mark exists(select 1 from grade where ...)
As long as the sub-child guided by exists If the sentence has a result set returned, then the exists condition is established. Please note that the returned field is always 1. If it is changed to "select 2 from grade where...", then the returned field is 2. This number is meaningless. So the exists clause does not care about what is returned, but whether there is a result set returned.
The biggest difference between exists and in is that the in clause can only return one field, for example:
select name from student where sex = 'm' and mark in (select 1,2,3 from grade where ...)
, the in clause returns three fields, which is not true Correct, the exists clause is allowed, but in only allows one field to be returned. Just remove any two fields in 1, 2, and 3.
And not exists and not in are the opposites of exists and in respectively.
exists (sql returns the result set as true)
not exists (sql does not return the result set as true)
The process of not exists is described in detail below:
As follows:
Table A
ID NAME
1 A1
2 A2
3 A3
Table B
ID AID NAME
1 1 B1
##2 2 B2 3 2 B3Table A and table B have a 1-to-many relationship A.ID => B.AIDSELECT ID,NAME FROM A WHERE EXISTS (SELECT * FROM B WHERE A.ID=B.AID)The execution result is1 A12 A2The reason can be analyzed as follows
SELECT ID,NAME FROM A WHERE EXISTS (SELECT * FROM B WHERE B.AID=1) --->SELECT * FROM B WHERE B.AID=1有值返回真所以有数据 SELECT ID,NAME FROM A WHERE EXISTS (SELECT * FROM B WHERE B.AID=2) --->SELECT * FROM B WHERE B.AID=2有值返回真所以有数据 SELECT ID,NAME FROM A WHERE EXISTS (SELECT * FROM B WHERE B.AID=3) --->SELECT * FROM B WHERE B.AID=3无值返回真所以没有数据NOT EXISTS is the other way around
SELECT ID,NAME FROM A WHERE NOT EXIST (SELECT * FROM B WHERE A.ID=B.AID)The execution result is3 A3
EXISTS = IN, the meaning is the same but there is a slight difference in syntax. It seems that the efficiency of using IN is less, which may be the reason why the index will not be executed.
SELECT ID,NAME FROM A WHERE ID IN (SELECT AID FROM B)NOT EXISTS = NOT IN, the meaning is the same but there is a difference in syntax. Little difference
SELECT ID,NAME FROM A WHERE ID NOT IN (SELECT AID FROM B)Sometimes we will encounter the situation where we need to select a certain column without duplication, use a certain column as the selection condition, and other columns will be output normally.Recommended tutorial: "
Oracle Video tutorial》
The above is the detailed content of What is the usage of not exists in oracle. For more information, please follow other related articles on the PHP Chinese website!

Oracle has a wide and diverse customer base, covering multiple fields such as financial services, healthcare, retail and e-commerce, and manufacturing. 1) In financial services, Oracle FLEXCUBE improves operational efficiency and data security; 2) In health care, OracleHealth Sciences Clinical Development accelerates new drug research and development; 3) In retail and e-commerce, OracleRetail and OracleCDP achieve personalized customer experience; 4) In manufacturing, OracleERPCloud optimizes supply chain management.

Triggers in Oracle are stored procedures used to automatically perform operations after a specific event (insert, update, or delete). They are used in a variety of scenarios, including data verification, auditing, and data maintenance. When creating a trigger, you need to specify the trigger name, association table, trigger event, and trigger time. There are two types of triggers: the BEFORE trigger is fired before the operation, and the AFTER trigger is fired after the operation. For example, the BEFORE INSERT trigger ensures that the age column of the inserted row is not negative.

Two ways to rename Oracle table names: use SQL statements: ALTER TABLE <Old table name> RENAME TO <New table name>;Use PL/SQL statements: EXECUTE IMMEDIATE 'ALTER TABLE ' || :old_table_name || ' RENAME TO ' || :new_table_name;

Oracle provides the following ways to fall back on committed database changes: Use the ROLLBACK statement to immediately revoke all uncommitted changes. Operation through the database management tool interface. Use Oracle Flashback technology to return to a specific point in time and restore data, flashback logging is required.

Methods to check whether the index has been rebuilt in Oracle: DBA_INDEXES view: view REBUILT value (YES/NO); ALL_INDEXES view: view STATUS value (VALID/UNUSABLE); V$INDEX_STATISTICS view: view NUM_REBUILDS value, indicating the number of index reconstructions.

After the Oracle upgrade fails, follow the following steps to restore the system: Terminate recovery and switch to recovery mode. Use the recovery command to roll back the data file. Open the database and confirm that the data file is installed and restore the redo log. If the control file is corrupted, recreate it. Reopen the database in full recovery mode. Verify the restore and confirm that the data and objects are intact. If a rollback segment was created during restore, roll it back.

To modify an expired Oracle database password, follow these steps: 1. Exit all sessions; 2. Connect with the database with SYSDBA permissions; 3. Execute the ALTER USER command to modify the password; 4. Reconnect with the new password; 5. Execute the query to confirm that the password has been modified.

Escape characters in Oracle are used to indicate special characters or control sequences, including line connections, string delimiters, line breaks, carriage return, tabs, and backspace characters. Escape character processing usually involves escaping special characters in a string, using | concatenating multiline strings, and using a backslash to escape the escape character itself.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1
Easy-to-use and free code editor

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.