Modifies the data at the current location of a cursor.
UPDATE WHERE CURRENT OF cursor-name { USING [ SQL ] DESCRIPTOR sqlda-name | { [ FROM ] | [ USING ] } hostvar-list }
UPDATE update-table, ... SET set-item, ... WHERE CURRENT OF cursor-name
hostvar-list : indicator variables allowed
update-table :
[owner-name.]object-name [ [ AS ] correlation-name ]
set-item : [ correlation-name.]column-name = { expression | DEFAULT } | [owner-name.]object-name.column-name = { expression | DEFAULT }
object-name : identifier (a table or view name)
sqlda-name : identifier
USING DESCRIPTOR clause When assigning a variable, the variable must already be declared, and its name must begin with the "at" sign (@). Variable and column assignments can be mixed together, and any number can be used. If a name on the left side of an assignment in the SET list matches a column in the updated table and the variable name, the statement updates the column.
SET clause The columns that are referenced in set-item must be in the table or view that is updated. They cannot refer to aliases, nor to columns from other tables or views. If the table or view you are updating is given a correlation name in the cursor specification, you must use the correlation name in the SET clause.
Each set-item is associated with a single update-table, and the corresponding column of the matching table in the cursor's query is modified. The expression references columns of the tables identified in the UPDATE list and may use constants, host variables, variables, expressions from the SELECT list of the query, or combinations of the above using operators such as +, -, ..., COALESCE, IF, and so on. The expression can not reference aliases of expressions from the cursor's query, nor can they reference columns of other tables of the cursor's query which do not appear in the UPDATE list. Subselects, subquery predicates, and aggregate functions can not be used in the set-items.
Each update-table is matched to a table in the query for the cursor as follows:
If a correlation name is specified, it is matched to a table in the cursor's query that has the same table-or-view-name and the same correlation-name.
Otherwise, if there is a table in the cursor's query that has the same table-or-view-name that does not have a correlation name specified, or has a correlation name that is the same as the table-or-view-name, then the update table is matched with this table in the cursor's query.
Otherwise, if there is a single table in the cursor's query that has the same table-or-view-name as the update table, then the update table is matched with this table in the cursor's query.
If a column has a default defined, you can use the SET clause to set a column to its default value. For an example of this, see the Examples section of UPDATE statement.
This form of the UPDATE statement updates the current row of the specified cursor. The current row is defined to be the last row successfully fetched from the cursor, and the last operation on the cursor must not have been a positioned DELETE statement.
For syntax 1, columns from the SQLDA or values from the host variable list correspond one-to-one with the columns returned from the specified cursor. If the sqldata pointer in the SQLDA is the null pointer, the corresponding SELECT list item is not updated.
In syntax 2, the requested columns are set to the specified values for the row at the current row of the specified query. The columns do not need to be in the SELECT list of the specified open cursor. This format can be prepared.
Also, when assigning a variable, the variable must already be declared, and its name must begin with the "at" sign (@). Variable and column assignments can be mixed together, and any number can be used. If a name on the left side of an assignment in the SET list matches a column in the updated table and the variable name, the statement updates the column.
The USING DESCRIPTOR, FROM hostvar-list, and hostvar formats are for embedded SQL only.
Must have UPDATE permission on the columns being modified.
None.
SQL/2008 Syntax 1 is a vendor extension. Syntax 2 is a core feature of the SQL/2008 standard. If used within an embedded SQL program, Syntax 2 comprises part of optional SQL language feature B031, "Basic dynamic SQL". The ability to specify more than one table to be updated is a vendor extension.
The range of cursors that can be updated is dependent upon the setting of the ansi_update_constraints option. The ability to perform a positioned update over a cursor that is ordered—that is the SQL query has an ORDER BY clause—comprises optional SQL/2008 language feature F831, "Full cursor update". Performing a positioned update over more complex SQL constructions may involve additional vendor extensions.
The following is an example of an UPDATE statement WHERE CURRENT OF cursor:
UPDATE Employees SET Surname = 'Jones' WHERE CURRENT OF emp_cursor; |
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |