Previous Topic: SQL States TableNext Topic: Specifying Result Tables


Application Tasks Using Embedded SQL

The following chapters contain examples on embedding SQL statements in a host program. The following table lists the chapters in this part and what each contains:

Chapter/Section

Contains

Specifying Result Tables

Examples on different ways to use the select-statement to retrieve the desired data.

Selecting All Columns

An example on selecting all columns in a table.

Selecting Some Columns

An example on selecting specific columns in a table.

Selecting Using Search Conditions

An example on using search conditions to limit the rows in the result table.

Ordering by Column Values

An example on ordering returned data by values in the column(s).

Eliminating Duplicate Rows

An example on eliminating duplicate rows in the returned data.

Counting

An example on counting the rows in a result table.

Calculating Values

Examples on using column values to calculate values which are not contained in the table, and also using a subquery (nested subselects).

Summarizing Group Values

An example on grouping columns by value.

Testing for Existence

An example on testing for existence of certain rows.

Selecting Data from Multiple Tables

Discusses the join and union operations on data from multiple tables.

Joining Tables

An example on deriving a result table which includes all specified data from two or more tables.

Using the UNION Operator

An example on deriving a result table which is a set formed by the union of two result tables.

Inserting Rows

Examples on using the INSERT statement to insert rows into a table.

Updating a Table

An example on using the UPDATE statement to update rows in a table.

Deleting Rows

An example on using the DELETE statement to delete rows from a table.

Committing and Backing Out Transactions

An example on using the COMMIT WORK statement to commit transactions and the ROLLBACK WORK statement to back out transactions.

The embedded examples include the following statements, clauses, functions and predicates.

Statements:

Clauses:

Functions:

Predicates:

CLOSE
COMMIT WORK
DECLARE CURSOR
DELETE
FETCH
INSERT
OPEN
ROLLBACK WORK
SELECT
SELECT INTO
UPDATE
WHENEVER

FROM
GROUP BY
HAVING
ORDER BY
WHERE

AVG
COUNT (DISTINCT column-name)
COUNT (*)
MAX
MIN
SUM

EXISTS

With regard to the SELECT statement listed previously, note that in the examples the select-statement form of the SELECT statement is a component of the DECLARE CURSOR statement, and that the examples could be executed interactively by omitting the "DECLARE CURSOR FOR" clause. See DECLARE CURSOR for more information on the DECLARE CURSOR statement and SELECT for more information on the SELECT statement.

Note: All examples use the CUSTOMERS and ORDERS tables listed in Sample Data Tables.

For examples using other SQL statements, such as CREATE and DROP, see the appropriate chapter in the section starting on Using the Interactive SQL Service Facility.

For examples involving the use of dynamic SQL, see Dynamic SQL. Also see the descriptions and examples of the dynamic SQL statements in SQL Statements.