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

Assignment Help:

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.

Related Discussions:- Example of not exists operator - sql

Logical operators-pl/sql expressions , Logical Operators The logical op...

Logical Operators The logical operators AND, NOT, and OR follow the tri-state logic shown in table below. The AND and OR are binary operators; NOT is a unary operator.

Difference between ttitle and btitle, TTITLE and BTITLE are commands in Pl-...

TTITLE and BTITLE are commands in Pl-SQL to control report headings and footers. This Ttitle & Btitle are mainly used on creating SQL*PLUS report. Ttitle is used for toptitle headi

Rephrase conditional control statements, Rephrase Conditional Control State...

Rephrase Conditional Control Statements When computing a logical expression, the PL/SQL uses short-circuit evaluation. That is, the PL/SQL stops evaluating the expression as s

Number types in pl/sql, Number Types The Number types permit you to sto...

Number Types The Number types permit you to store the numeric data (real numbers, integers, and floating-point numbers), show quantities, and do computations. BINARY_INTEG

Explicit cursors, Explicit Cursors The set of rows returned by the que...

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

Assignment of variable - updating a variable, Assignment of Variable - Upda...

Assignment of Variable - Updating a Variable Syntax: SET SN = SID ('S2'); This can obviously be read as "set the variable SN to be equal in value to SID ( 'S2' )".

Using prior and next - collection method, Using PRIOR and NEXT The PRI...

Using PRIOR and NEXT The PRIOR(n) returns the index number that precede index n in a collection. The NEXT(n) returns the index number which succeed the index n. If n has no pr

Sql, Write a cursor to open an employee database and fetch the employee rec...

Write a cursor to open an employee database and fetch the employee record whose age is greater than 45

Declarations in sql-pl/sql, Declarations in SQL Your program stores value...

Declarations in SQL Your program stores values in the variables and constants. As the program executes, the value of the variables can change, but the values constants cannot.

Definition of from - sql, Definition of FROM - SQL Recall that the ope...

Definition of FROM - SQL Recall that the operand of FROM is denoted by a commalist, each element of that commalist being a table expression optionally accompanied by a range v

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd