Example of not exists operator - sql, PL-SQL Programming

Example of NOT EXISTS Operator - SQL

Example is a translation into SQL of the corresponding example, which is included there merely to show that for any scalar comparison there is an alternative formulation using IS_EMPTY.

Example: MAX_ENROLMENTS expressed using an invocation of NOT EXISTS

CREATE ASSERTION MAX_ENROLMENTS_alternative1

CHECK (NOT EXISTS (SELECT *

FROM (VALUES (SELECT COUNT (*)

FROM IS_ENROLLED_ON)) AS

V (N)

WHERE V.N > 20000));

Explanation

  • VALUES ( SELECT COUNT(*) FROM IS_ENROLLED_ON ) denotes a table with just one column, unnamed, in whose single row the value of that column is the number of rows in the current value of IS_ENROLLED_ON. The SELECT expression is parenthesized to make it into a scalar subquery and given as the argument to an invocation of VALUES, which makes the number denoted by that scalar subquery into a one-row, one-column table. (Actually, it might be safer to place an extra pair of parentheses around the SELECT expression here. Although VALUES 1 and VALUES (1) are equivalent, it might not be clear as to which role the single parentheses are taking: do they denote a scalar subquery, as I have assumed, or are they the optional ones surrounding a single table expression? If the latter, we would expect a syntax error.)
  • AS V (N) defines the range variable V to refer to what in this case is just the single row of that table, and also assigns the name N to its only column.
  •  WHERE V.N > 20000 operates on that one-row, one-column table to yield a table of heading (N INTEGER) that is empty if and only if the single row in that one-row, one-column table fails to satisfy the condition N > 20000. Thus, the result is empty only when the number of enrolments is in fact no greater than the maximum allowed.
Posted Date: 1/18/2013 7:44:45 AM | Location : United States







Related Discussions:- Example of not exists operator - sql, Assignment Help, Ask Question on Example of not exists operator - sql, Get Answer, Expert's Help, Example of not exists operator - sql Discussions

Write discussion on Example of not exists operator - sql
Your posts are moderated
Related Questions
SSRS Report Writing Project Description: This report is part of a larger project to make a SQL Server Reporting Service (SSRS) based reporting solution. There can be more rep

Ending Transactions A good quality programming practice is to commit or roll back every transaction explicitly. Whether you rollback or issue the commit in your PL/SQL program

Example of WRAP Operator - SQL The effect of Example can be obtained in SQL but note that one needs to write down not only the names of the columns being wrapped but also the

Operator Precedence The operations within an expression are completed in a particular order depending on their precedence (priority). The table shows the default order of the op

Implicit Cursor Attributes The Implicit cursor attributes returns the information about the execution of an INSERT, DELETE, UPDATE, or SELECT INTO statement. The cursor attribu

Using research notes and Oracle documentation plan and execute an upgrade of an installation of Oracle 10g to Oracle 11g release 1. To do this you must show in screen shots and wri

The Package Specification The package specifications contain the public declarations. The scopes of these declarations are local to your database representation and global to t

Parameter and Keyword Description: SQL: This SQL is the name of the implicit SQL cursor. %FOUND: This attribute results TRUE if an INSERT, DELETE, or UPDATE state

SELECT a.child_fname,a.child_lname,concat(b.parent_title,b.parent_fname), b.parent_lname,b.parent_tphone FROM child a,parent b WHERE a.parent_id=b.parent_id ORDER BY a.child_fnam

Explicit Cursors The set of rows returned by the query can include zero, one, or multiple rows, depending on how many rows meet your search criteria. Whenever a query returns