13.5. SQL: Routines

The SQL standard uses the generic term routineto describe a body of code that can be invoked from some other code—this covers functions, procedures, and the methods of user-defined data types.

User Defined Functions (UDFs)

We’ll look first at functions, which, in simple terms, are bodies of code that return a result. The SQL standard defines a large number of built-in functions for calculating logarithms, generating random numbers, transforming character strings into all uppercase or all lowercase, and so on. These can be used wherever appropriate in SQL code. It’s also convenient to be able to define new functions to encapsulate pieces of code that are likely to be reused. In SQL, functions can return scalar (single) values ...

Get Information Modeling and Relational Databases, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.