Flylib.com

Books Software

 
 
 

OPERATORS


OPERATORS

  • String concatenation operator concatenates two strings together; for example, 'My name is'' ''Joe' returns the string My name is Joe .

  • Set operators Set operators allow concatenation of results from two queries. UNION ALL returns all rows including duplicates, UNION returns all unique rows, INTERSECT returns all rows common to both queries, and MINUS returns all rows in one and not the other query.

  • Hierarchical query operator The PRIOR operator placed with the CONNECT BY clause links the current row with a parent row.


CONDITIONS

  • Comparison conditions:

    • Equi (=), Anti (!=, <>, ^=), and Range (<, >, =<, >=).

    • [NOT] LIKEPattern matching.

    • [NOT] INSet membership between expressions.

    • [NOT] EXISTSSet membership producing a Boolean result.

    • [NOT] BETWEENRange search between two values, inclusive of end points.

    • ANY, SOME, and ALLSet membership conditions.

      • IS [NOT] NULLNULL value testcondition.

  • Logical conditions, in order of precedence:

    • NOTAn expression being false yields true.

    • ANDTwo expressions being true yield true.

    • OROne of two expressions being true yields true.


PSEUDOCOLUMNS

  • ROWID Relative row pointer.

  • ROWNUM A sequence number for rows returned by a query as the rows are returned.

  • <sequence>.CURRVAL and <sequence>.NEXTVAL The current and next values for a sequence.

  • LEVEL Returns the level of a row in a hierarchical query.


EXPRESSIONS

  • CURSOR expression An embedded or inline cursor inside a calling SQL statement:

    SELECT ...,CURSOR(<subquery>),... FROM ...;
    

  • CASE expression An embedded or inline CASE statement inside a SQL statement as a simple CASE statement:

    SELECT ... CASE expression WHEN condition THEN ...
        WHEN condition THEN ... ELSE ... END FROM table;
    

    Or a search CASE statement:

    SELECT ... CASE WHEN <condition> THEN ...
        WHEN <condition> THEN ... ELSE ... END FROM table;
    


FUNCTIONS

Functions can be used in a SELECT statement item selection list, WHERE and ORDER BY clauses, GROUP BY and HAVING clauses, CONNECT BY and START WITH clauses in hierarchical queries, plus INSERT VALUES and UPDATE SET clauses.

Single Row Functions

Execute an operation on each row of a query:

  • Strings:

    • INSTR(<string>,<substring>[,<position>[,occurrence>]])

    • LENGTH(<string>)

    • INITCAP(<string>)

    • LOWER(<string>)

    • UPPER(<string>)

    • LPAD(<string>,<n>[,<replace>)

    • RPAD LPAD(<string>,<n>[,<replace>)

    • LTRIM(<string>,<string>)

    • RTRIM(<string>,<string>)

    • trIM([[LEADINGTRAILINGBOTH] <character> FROM] <string>)

    • SUBSTR(<string>[,[-]<position> [,<n>]])

    • REPLACE(<string>,<search> [,<replace>])

  • Numbers:

    • ABS(<n>)

    • POWER(<n>,<exponent>)

    • SQRT(<n>)

    • CEIL(<n>)

    • FLOOR(<n>)

    • ROUND(<n>,<decimal places>)

    • TRUNC(<n>,<decimal places>)

    • MOD(<numerator>,<denominator>)

    • SIGN(<n>)

  • Datetime:

    • SYSDATE

    • CURRENT_DATE

    • CURRENT_TIMESTAMP(<precision>)

    • LOCALTIMESTAMP(<precision>)

    • NEXT_DAY(<date>,<weekday>)

    • LAST_DAY(<date>)

    • ADD_MONTHS(<date>,<months>)

    • MONTHS_BETWEEN(<date>,<date>)

    • EXTRACT(<format> FROM {<date><timestamp>)

    • ROUND(<date>[,<format>])

    • trUNC(<date>[,<format>])

  • Datatype conversions:

    • TO_NUMBER(<n>[,<format>])

    • TO_[N]CHAR(<string>[,<format>])

    • TO_DATE(<string>,<format>)

    • TO_[N]CHAR(<datetime>,<format>)

  • Miscellaneous:

    • DECODE(<expression>,<search>, <replace>

      [,<search>,<replace>...],<default>)
      

      • NULLIF(<expression>,<expression>)

      • NVL(<expression>,<expression>)

      • NVL2(<expression>,<expression>,<expression>)

      • USER

      • USERENV(<parameter>)

      • GREATEST(<expression>[,<expression>...])

      • LEAST(<expression>[,<expression>...])

Aggregate Functions

Summarize repeating groups in a row set into distinct groups, creating values such as sums or averages:

  • Simple summaries:

    • COUNT(*[DISTINCTALL] <expression>)

    • AVG([DISTINCTALL] <expression>)

    • MIN([DISTINCTALL] <expression>)

    • MAX([DISTINCTALL] <expression>)

    • SUM([DISTINCTALL] <expression>)

  • Simple statistics:

    • STDDEV([DISTINCTALL] <expression>)

    • VARIANCE([DISTINCTALL] <expression>)

    • CORR(<expression>,<expression>)

    • STDDEV_{POPSAMP}(<expression>)

    • VAR_{POPSAMP}(<expression>)