Restrictions; Upsert Using Rowsets; Example; Merge From One Table Into Another - HP Neoview SQL Reference Manual

Hide thumbs Also See for Neoview SQL:
Table of Contents

Advertisement

Restrictions

A merged table cannot be a view.
Merge is not allowed if the table has triggers or constraints.
Merge is not allowed with SET ON ROLLBACK.
on-clause must be unique. This statement is not allowed:
MERGE INTO t ON a > 0 ...
The key value specified in the on-clause and the VALUE clause must be the same. This
statement is not allowed:
MERGE INTO t ON a = 10
WHEN NOT MATCHED THEN INSERT VALUES (20, 30)
on-clause cannot contain a subquery. This statement is not allowed:
MERGE INTO t ON a = (SELECT a FROM t1) WHEN ...
UPDATE SET clause in a MERGE statement cannot contain a subquery. This statement is
not allowed:
MERGE INTO t ON a = 1 WHEN MATCHED THEN SET b = (SELECT a FROM t1)
INSERT VALUES clause in a MERGE statement cannot contain a subquery. This statement
is not allowed:
MERGE INTO t ON a = 1 WHEN NOT MATCHED THEN INSERT VALUES ((SELECT a FROM t1))

Upsert Using Rowsets

If the value is a rowset, each row of the rowset is treated as a separate single row upsert statement.
The behavior is the same as other statements that use rowsets. The restrictions are the same as
those for
"Upsert Using Single Row" (page

Example

This example uses a dynamic rowset of size 10, with unnamed parameters.
MERGE INTO t ON a = ?[10]
WHEN MATCHED THEN UPDATE SET b = ?[10]
WHEN NOT MATCHED THEN INSERT VALUES (?[10], ?[10]);
Each value from the rowset in the ON clause is used to find the matching row. For each matched
row, the corresponding row from the rowset in the UPDATE clause is used to update. For
non-matching rows, the rowset row from the INSERT VALUES clause is inserted.

MERGE From One Table Into Another

The MERGE statement can be used to upsert all matching rows from the source table into the
target table. Each row from the source table is treated as the source of a single upsert statement.
the using-clause contains the select-query whose output is used as the source to the
MERGE statement..
The source select-query must be renamed using the AS clause. For example:
MERGE INTO t ON col = Z.X
USING (select-query) AS Z(X)
WHEN MATCHED WHEN NOT MATCHED
For each row selected out of the select-query, the MERGE statement is evaluated. Values selected
are used in the ON clause to join with the column of the merged table. If the value is found, it is
updated. If it is not found, the insert is done. The restrictions are the same as those for
Using Single Row" (page 129)
130
SQL Statements
129)..
"Upsert

Advertisement

Table of Contents
loading

Table of Contents