Section 14 in Foundation > module Language.SQL.SimpleSQL.SQL2011DataManipulation (sql2011DataManipulationTests) where > import Language.SQL.SimpleSQL.TestTypes > sql2011DataManipulationTests :: TestItem > sql2011DataManipulationTests = Group "sql 2011 data manipulation tests" [] 14 Data manipulation 14.1 This Subclause is modified by Subclause 12.1, “”, in ISO/IEC 9075-4. Function Declare a standing cursor. Format ::= DECLARE FOR Syntax Rules 1)  04  If a is contained in an M, then: a) The shall not be equivalent to the of any other , , or in M. b) The scope of the is M with the exception of any contained in M. c) Any contained in the shall be defined in a in the that contains an that specifies the and is contained in the scope of that . NOTE 463 — See the Syntax Rules of Subclause 13.1, “”. Access Rules None. General Rules 1) A cursor declaration descriptor CDD is created. CDD includes indications that: a) The kind of cursor is a standing cursor. b)  04  The provenance of the cursor is an indication of the SQL-client module whose contains the . Data manipulation 929 IWD 9075-2:201?(E) 14.1 c) The name of the cursor is the . d) The cursor's origin is the contained in the . e) The cursor's declared properties are as determined by the . Conformance Rules 1) Without Feature F831, “Full cursor update”, conforming SQL language shall not contain a that contains both a that contains an that specifies FOR UPDATE and that contain a . 930 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.2 14.2 Function Specify the declared properties of a cursor. Format ::= [ ] [ ] CURSOR [ ] [ ] ::= SENSITIVE | INSENSITIVE | ASENSITIVE ::= SCROLL | NO SCROLL ::= WITH HOLD | WITHOUT HOLD ::= WITH RETURN | WITHOUT RETURN Syntax Rules 1) If is not specified, then ASENSITIVE is implicit. 2) If is not specified, then NO SCROLL is implicit. 3) If is not specified, then WITHOUT HOLD is implicit. 4) If is not specified, then WITHOUT RETURN is implicit. Access Rules None. General Rules 1) The declared properties of the cursor declaration descriptor associated with are given by: a) The declared sensitivity property is the explicit or implicit . b) The declared scrollability property is the explicit or implicit . Data manipulation 931 IWD 9075-2:201?(E) 14.2 c) The declared holdability property is the explicit or implicit . d) The declared returnability property is the explicit or implicit . Conformance Rules 1) Without Feature T231, “Sensitive cursors”, conforming SQL language shall not contain a that immediately contains SENSITIVE. 2) Without Feature F791, “Insensitive cursors”, conforming SQL language shall not contain a that immediately contains INSENSITIVE. 3) Without Feature F791, “Insensitive cursors”, or Feature T231, “Sensitive cursors”, conforming SQL language shall not contain a that immediately contains ASENSITIVE. 4) Without Feature F431, “Read-only scrollable cursors”, conforming SQL language shall not contain a . 5) Without Feature T471, “Result sets return value”, conforming SQL language shall not contain a . 6) Without Feature T551, “Optional key words for default syntax”, conforming SQL language shall not contain a that immediately contains WITHOUT HOLD. 932 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.3 14.3 Function Define a result set. Format ::= [ ] ::= FOR { READ ONLY | UPDATE [ OF ] } Syntax Rules 1) Let CS be the . 2) Let QE be the immediately contained in CS. 3) Case: a) If CS is contained in a DC that contains a , then let CP be that . b) If CS is a being prepared by a or re-prepared by an or a , then: i) Let STMT be the that is preparing CS, or the or that is re-preparing CS. Let SCMD be the that contains STMT. ii) Case: 1) If CS is being prepared by a , then let PS be that . 2) Otherwise, let PS be the that previously prepared CS. iii) Let SSV be the contained in PS. iv) Case: 1) If CS is being prepared by a , then: Case: A) If SSV is a and there is exactly one DDC contained in SCMD whose is equivalent to SSV, then let CP1 be the contained in DDC. B) If SSV is an that specifies or implies a that is LOCAL, and there is exactly one ACS contained in SCMD whose specifies or implies LOCAL, then let CP1 be the contained in ACS. Data manipulation 933 IWD 9075-2:201?(E) 14.3 C) Otherwise, let CP1 be a zero-length string. 2) If CS is being re-prepared by an ACS, then let CP1 be the contained in ACS. 3) If CS is being re-prepared by a , then let DDC be the whose is equivalent to the contained in STMT. Let CP1 be the contained in DDC. v) If PS contains an , then let CP2 be the value of that ; otherwise, let CP2 be the zero-length string. vi) Case: 1) If CP2 contains , then let SENS be that . 2) If CP1 contains , then let SENS be that . 3) Otherwise, let SENS be the zero-length string. vii) Case: 1) If CP2 contains , then let SCRO be that . 2) If CP1 contains , then let SCRO be that . 3) Otherwise, let SCRO be the zero-length string. viii) Case: 1) If CP2 contains , then let HOLD be that . 2) If CP1 contains , then let HOLD be that . 3) Otherwise, let HOLD be the zero-length string. ix) Case: 1) If CP2 contains , then let RET be that . 2) If CP1 contains , then let RET be that . 3) Otherwise, let RET be the zero-length string. x) Let CP be the : SENS SCRO CURSOR HOLD RET 4) If is not specified and either CS is contained in a or is being re- prepared by an or a , then Case: a) If CP contains INSENSITIVE or SCROLL, or QE immediately contains an , or QE is not a simply updatable , then an of READ ONLY is implicit. b) Otherwise, an of FOR UPDATE without a is implicit. 934 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.3 NOTE 464 — If CS is being prepared by a , then defaulting the is postponed until CS is re-prepared. 5) If an of FOR UPDATE with or without a is specified, then CP shall not contain INSENSITIVE, QE shall be updatable, and QE shall have only one leaf underlying table LUT such that QE is one-to-one with respect to LUT. 6) Case: a) If an specifying FOR UPDATE is specified or implicit, then CS is updatable. b) If an specifying FOR READ ONLY is specified or implicit, then CS is not updatable. c) Otherwise, the determination of updatability of CS is postponed until CS is re-prepared. 7) If CS is updatable, then let LUTN be a that references LUT. LUTN is an exposed
whose scope is . 8) If an of FOR UPDATE without a is specified or implicit, then a that consists of the of every column of LUT is implicit. 9) If an of FOR UPDATE with a is specified, then each in the shall be the of a column of LUT. Access Rules None. General Rules None. Conformance Rules 1) Without Feature F831, “Full cursor update”, conforming SQL language shall not contain a that contains both an that specifies FOR UPDATE and an . 2) Without Feature T111, “Updatable joins, unions, and columns”, in conforming SQL language, if FOR UPDATE is specified, then QE shall be simply updatable. Data manipulation 935 IWD 9075-2:201?(E) 14.4 14.4 This Subclause is modified by Subclause 12.2, “”, in ISO/IEC 9075-4. Function Open a standing cursor. Format ::= OPEN Syntax Rules 1)  04  Let CN be the in the . CN shall be contained within the scope of a that is equivalent to CN. 2) CN shall identify a standing cursor. 3) Let CDD be the cursor declaration descriptor of the standing cursor identified by CN. Access Rules 1) The Access Rules for the simply contained in the identified by the are applied. General Rules 1) Let CR be the cursor instance descriptor in the current SQL-session whose cursor declaration descriptor is CDD. 2) The General Rules of Subclause 15.1, “Effect of opening a cursor”, are applied with CR as CURSOR. Conformance Rules None. 936 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.5 14.5 This Subclause is modified by Subclause 12.3, “”, in ISO/IEC 9075-4. This Subclause is modified by Subclause 11.15, “”, in ISO/IEC 9075-10. This Subclause is modified by Subclause 14.1, “”, in ISO/IEC 9075-14. Function Position a standing cursor on a specified row of the standing cursor's result set and retrieve values from that row. Format  10  ::= FETCH [ [ ] FROM ] INTO ::= NEXT | PRIOR | FIRST | LAST | { ABSOLUTE | RELATIVE }  14  ::= [ { }... ] Syntax Rules 1) shall not contain a that specifies a . 2) If the is omitted, then NEXT is implicit. 3)  04   10  Let CN be the in the . CN shall be contained within the scope of a that is equivalent to CN. 4) CN shall identify a standing cursor. 5) Let CDD be the cursor declaration descriptor of the standing cursor identified by CN. 6) Let T be the result set defined by the of CDD. 7) If the implicit or explicit is not NEXT, then the declared scrollability property of CDD shall be SCROLL. 8) If a that contains a is specified, then the declared type of that shall be exact numeric with a scale of 0 (zero). 9) Case: a) If the contains a single TS and the degree of T is greater than 1 (one), then the declared type of TS shall be a row type. Case: Data manipulation 937 IWD 9075-2:201?(E) 14.5 i)  04  If TS is an , then the Syntax Rules of Subclause 9.2, “Store assignment”, are applied with TS as TARGET and an arbitrary value of the row type of T as VALUE. ii) Otherwise, the Syntax Rules of Subclause 9.1, “Retrieval assignment”, are applied with TS as TARGET and an arbitrary value of the row type of T as VALUE. b) Otherwise: i) The number of s NTS in the shall be the same as the degree of T. The i-th , 1 (one) ≤ i ≤ NTS, in the corre- sponds with the i-th column of T. ii) For i varying from 1 (one) to NTS, let CSi be an arbitrary value of the declared type of the i-th column of T. iii)  04  For each TS1i, 1 (one) ≤ i ≤ NTS, that is either an or a , Case: 1) If TS1i contains a , then the Syntax Rules of Subclause 9.2, “Store assignment”, are applied with an arbitrary site whose declared type is the declared type of TS1i as TARGET and CSi as VALUE. 2) Otherwise, the Syntax Rules of Subclause 9.2, “Store assignment”, are applied with TS1i as TARGET and CSi as VALUE. iv)  10  For each TS2i, 1 (one) ≤ i ≤ NTS, that is a , the Syntax Rules of Subclause 9.1, “Retrieval assignment”, are applied with TS2i as TARGET and CSi as VALUE. v) For each TS2i, 1 (one) ≤ i, ≤ NTS, that is an , the Syntax Rules of Subclause 9.1, “Retrieval assignment”, are applied with TS2i as TARGET and CSi as VALUE. Access Rules None. General Rules 1) Let CR be the cursor instance descriptor of the current SQL-session whose cursor declaration descriptor is CDD. 2) If CR is not in the open state, then an exception condition is raised: invalid cursor state. 3) The General Rules of Subclause 15.3, “Determination of the current row of a cursor”, are applied with CR as CURSOR and as FETCH ORIENTATION. 4) If a completion condition no data has been raised, then no further General Rules of this Subclause are applied. 938 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.5 5) Case: a) If the contains a single TS and the degree of T is greater than 1 (one), then the current row is assigned to TS and Case: i)  04   14  If TS is an , then the General Rules of Subclause 9.2, “Store assignment”, are applied with TS as TARGET and the current row as VALUE. ii) Otherwise, the General Rules of Subclause 9.1, “Retrieval assignment”, are applied with TS as TARGET and the current row as VALUE. b)  10  Otherwise, if the contains more than one , then values from the current row are assigned to their corresponding targets identified by the . The assignments are made in an implementation-dependent order. Let TV be a target and let SV denote its corresponding value in the current row of CR. Case: i)  04  If TV is either an or a , then for each in the , let TVi be the i-th in the and let SVi denote the i-th corresponding value in the current row of CR. Case: 1) If is specified, then Case: A) If the value of TVi is the null value, then an exception condition is raised: data exception — null value in array target. B) Otherwise: I) Let N be the maximum cardinality of TVi. II) Let M be the cardinality of the value of TVi. III) Let I be the value of the immediately contained in TVi. IV) Let EDT be the element type of TVi. V) Case: 1) If I is greater than zero and less than or equal to M, then the value of TVi is replaced by an array A with element type EDT and cardinality M derived as follows: a) For j varying from 1 (one) to I–1 and from I+1 to M, the j-th element in A is the value of the j-th element in TVi. b)  14  The General Rules of Subclause 9.2, “Store assignment”, are applied with I-th element of A as TARGET and SVi as VALUE. Data manipulation 939 IWD 9075-2:201?(E) 14.5 2) If I is greater than M and less than or equal to N, then the value of TVi is replaced by an array A with element type EDT and cardinality I derived as follows: a) For j varying from 1 (one) to M, the j-th element in A is the value of the j-th element in TVi. b) For j varying from M+1 to I, the j-th element in A is the null value. c)  14  The General Rules of Subclause 9.2, “Store assignment”, are applied with I-th element of A as TARGET and SVi as VALUE. 3) Otherwise, an exception condition is raised: data exception — array element error. 2)  14  Otherwise, the General Rules of Subclause 9.2, “Store assignment”, are applied with TVi as TARGET and SVi as VALUE. ii) If TV is a , then the General Rules of Subclause 9.1, “Retrieval assign- ment”, are applied with TV as TARGET and SV as VALUE. iii) If TV is an , then the General Rules of Subclause 9.1, “Retrieval assignment”, are applied with TV as TARGET and SV as VALUE. NOTE 465 — SQL parameters cannot have as their data types any row type. 6) If an exception condition occurs during the assignment of a value to a target, then the values of all targets are implementation-dependent. NOTE 466 — It is implementation-dependent whether CR remains positioned on the current row when an exception condition is raised during the derivation of any . Conformance Rules 1) Without Feature F431, “Read-only scrollable cursors”, in conforming SQL language, a shall not contain a . 940 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.6 14.6 This Subclause is modified by Subclause 12.4, “”, in ISO/IEC 9075-4. Function Close a standing cursor. Format ::= CLOSE Syntax Rules 1)  04  Let CN be the in the . CN shall be contained within the scope of a that is equivalent to CN. 2) CN shall identify a standing cursor. 3) Let CDD be the cursor declaration descriptor of the standing cursor identified by CN. Access Rules None. General Rules 1) Let CR be the cursor instance descriptor of the current SQL-session whose cursor declaration descriptor is CDD. 2) The General Rules of Subclause 15.4, “Effect of closing a cursor”, are applied with CR as CURSOR and DESTROY as DISPOSITION. Conformance Rules None. Data manipulation 941 IWD 9075-2:201?(E) 14.7 This Subclause is modified by Subclause 12.5, “”, in ISO/IEC 9075-10. This Subclause is modified by Subclause 14.2, “ ::= SELECT [ ]
 14  shall not contain a that specifies a . 2) Let T be the table defined by the
. 3) Case: a) If the shall be the same as the number of elements in the corresponds with the i-th element of the that is either an or a , and let SLi be the i-th element of the . Case: 942 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.7 as VALUE. iii) For each TS2i, 1 (one) ≤ i ≤ NOE, that is a , the Syntax Rules of Subclause 9.1, “Retrieval assignment”, are applied with TS2i as TARGET and corresponding element of the as VALUE. 4) Let S be a whose
are those specified in the . S shall be a valid . 5) A column in the result of the is possibly non-deterministic if S is possibly non-deterministic. Access Rules None. General Rules 1) Let Q be the result of S. 2) Case: a) If the cardinality of Q is greater than 1 (one), then an exception condition is raised: cardinality violation. It is implementation-dependent whether or not SQL-data values are assigned to the targets identified by the , and a completion condition is raised: no data. c) Otherwise, values in the row of Q are assigned to their corresponding targets. 3) If a completion condition no data has been raised, then no further General Rules of this Subclause are applied. 4) Case: a) If the i)  14  If TS is an , then the General Rules of Subclause 9.2, “Store assignment”, are applied with TS as TARGET and the current row as VALUE. ii) Otherwise, the General Rules of Subclause 9.1, “Retrieval assignment”, are applied with TS as TARGET and the current row as VALUE. b) Otherwise: i) Let NOE be the number of elements in the that is either an or a , and let SLi denote the corresponding (i-th) value in the row of Q. The assignment of values to targets in the c)  14  The General Rules of Subclause 9.2, “Store assignment”, are applied with I-th element of A as TARGET and SLi as VALUE. 3) Otherwise, an exception condition is raised: data exception — array element error. 2)  14  Otherwise, the General Rules of Subclause 9.2, “Store assignment”, are applied with TSi as TARGET and corresponding value SLi in the row of Q as VALUE. iii) For each TS that is a , the General Rules of Subclause 9.1, “Retrieval assignment”, are applied with TS as TARGET and the corresponding value in the row of Q as VALUE. The assignment of values to targets in the is in an implementation-dependent order. 5) If an exception condition is raised during the assignment of a value to a target, then the values of all targets are implementation-dependent. Conformance Rules None. Data manipulation 945 IWD 9075-2:201?(E) 14.8 14.8 This Subclause is modified by Subclause 12.6, “”, in ISO/IEC 9075-4. This Subclause is modified by Subclause 11.12, “”, in ISO/IEC 9075-10. Function Delete a row of a table. Format  10  ::= DELETE FROM [ [ AS ] ] WHERE CURRENT OF ::=
| ONLY
Syntax Rules 1)  04  Let DSP be the and let CN be the immediately contained in DSP. CN shall be contained within the scope of a that is equivalent to CN. 2) CN shall identify a standing cursor. 3) Let CDD be the cursor declaration descriptor of the standing cursor identified by CN. 4) The cursor specification of CDD shall be updatable. 5) Let TU be the simply underlying table of the cursor identified by CN. Let LUT be the leaf underlying table of TU such that TU is one-to-one with respect to LUT. 6) Let TT be the and let TN be the
contained in TT. TN shall identify LUT. 7) LUT shall not be an old transition table or a new transition table. 8) If TT immediately contains ONLY and LUT is not a typed table, then TT is equivalent to TN. 9) TT shall specify ONLY if and only if the
contained in TU that references LUT specifies ONLY. 10) The schema identified by the explicit or implicit qualifier of TN shall include the descriptor of LUT. 11) Case: a) If is specified, then let COR be that . COR is an exposed . b) Otherwise, let COR be TN. COR is an exposed
. NOTE 467 — CN has no scope. 946 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.8 Access Rules 1) Case: a) If DSP is contained, without an intervening that specifies SQL SECURITY INVOKER, in an , then let A be the authorization identifier that owns that schema. The applicable privileges for A shall include DELETE for the table identified by TN. b) Otherwise, the current privileges shall include DELETE for the table identified by TN. General Rules 1) Let CR be the cursor instance descriptor of the current SQL-session whose cursor declaration descriptor is CDD. 2) The General Rules of Subclause 15.5, “Effect of a positioned delete”, are applied with CR as CURSOR, DSP as STATEMENT, and TT as TARGET. Conformance Rules 1) Without Feature S111, “ONLY in query expressions”, conforming SQL language shall not contain a that contains ONLY. Data manipulation 947 IWD 9075-2:201?(E) 14.9 14.9 This Subclause is modified by Subclause 14.3, “”, in ISO/IEC 9075-14. Function Delete rows of a table. Format  14  ::= DELETE FROM [ FOR PORTION OF FROM TO ] [ [ AS ] ] [ WHERE ] Syntax Rules 1) Let DSS be the and let TT be the . 2) Let TN be the
contained in TT. Let T be the table identified by TN. 3) T shall be an updatable table or a trigger deletable table. 4) T shall not be an old transition table or a new transition table. 5) If WHERE is not specified, then WHERE TRUE is implicit. 6) Let DSC be the implicit or explicit . DSC shall not generally contain a whose subject routine is an SQL-invoked routine that possibly modifies SQL-data. Case: a) If T is a system-versioned table, then let ENDCOL be the system-time period end column of T. Let ENDVAL be the highest value supported by the declared type of ENDCOL. Let TSC be ( DSC ) AND ( ENDCOL = ENDVAL ) b) Otherwise, let TSC be DSC. 7) Case: a) If FOR PORTION OF ATPN is specified, then the table descriptor of T shall include a period descriptor whose period name is equivalent to ATPN. i) Let BSTARTCOL be the name of the ATPN period start column of T; let BENDCOL be the name of the ATPN period end column of T. ii) Let FROMVAL be . FROMVAL shall not generally contain a reference to a column of T or a whose subject routine is an SQL-invoked routine that is possibly non-deterministic or that possibly modifies SQL-data. 948 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.9 iii) Let TOVAL be . TOVAL shall not generally contain a reference to a column of T or a whose subject routine is an SQL-invoked routine that is possibly nondeterministic or that possibly modifies SQL-data. iv) Let SC be TSC AND (FROMVAL < TOVAL) AND (BENDCOL > FROMVAL) AND (BSTARTCOL < TOVAL) b) Otherwise, let SC be TSC. 8) If DSS is contained in a , then SC shall not contain a that specifies a parameter reference. 9) Case: a) If is specified, then let CN be that . CN is an exposed . b) Otherwise, let CN be TN. CN is an exposed
. 10) The scope of CN is SC. Access Rules 1) Case: a) If DSS is contained, without an intervening that specifies SQL SECURITY INVOKER, in an , then let A be the that owns that schema. i) The applicable privileges for A shall include DELETE for T. ii) If TT immediately contains ONLY, then the applicable privileges for A shall include SELECT WITH HIERARCHY OPTION on at least one supertable of T. b) Otherwise, i) The current privileges shall include DELETE for T. ii) If TT immediately contains ONLY, then the current privileges shall include SELECT WITH HIERARCHY OPTION on at least one supertable of T. General Rules 1) If the transaction access mode of the current SQL-transaction or the transaction access mode of the branch of the current SQL-transaction at the current SQL-connection is read-only, and T is not a temporary table, then an exception condition is raised: invalid transaction state — read-only SQL-transaction. 2) If there is any sensitive cursor CR that is currently open in the SQL-transaction in which this SQL-statement is being executed, then Case: Data manipulation 949 IWD 9075-2:201?(E) 14.9 a) If CR has not been held into a subsequent SQL-transaction, then either the change resulting from the successful execution of this statement shall be made visible to CR or an exception condition is raised: cursor sensitivity exception — request failed. b) Otherwise, whether the change resulting from the successful execution of this SQL-statement is made visible to CR is implementation-defined. 3) If there is any open, insensitive cursor CR, then either the change resulting from the successful execution of this statement shall be invisible to CR, or an exception condition is raised: cursor sensitivity exception — request failed. 4) The extent to which an SQL-implementation may disallow independent changes that are not significant is implementation-defined. 5) SC is effectively evaluated for each row of T with the exposed s or
s bound to that row. 6) Case: a) If TT contains ONLY, then the rows for which the result of SC is True and for which there is no subrow in a proper subtable of T are identified for deletion from T. b) Otherwise, the rows for which the result of SC is True are identified for deletion from T. NOTE 468 — Identifying a row for deletion is an implementation-dependent mechanism. 7) Let S be the set consisting of every row identified for deletion from T. S is the old delta table of delete operation on T. If FOR PORTION OF is specified, then FROMVAL and TOVAL are associated with every row in S as the associated for portion of from-value and the associated for portion of to-value, respectively. 8) Case: a) If T is a base table, then: i) Case: 1) If TT specifies ONLY, then T is identified for deletion processing without subtables. 2) Otherwise, T is identified for deletion processing with subtables. NOTE 469 — Identifying a base table for deletion processing, with or without subtables, is an implementation- dependent mechanism. ii) The General Rules of Subclause 15.7, “Effect of deleting rows from base tables”, are applied. b) If T is a viewed table, then the General Rules of Subclause 15.9, “Effect of deleting some rows from a viewed table”, are applied with TT as VIEW NAME. 9) If any row that is marked for deletion by DSS has been marked for deletion by any , , or that identifies some open cursor CR or updated by any , , or that identifies some open cursor CR, then a completion condition is raised: warning — cursor operation conflict. 10) If no rows are marked for deletion, then a completion condition is raised: no data. 950 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.9 Conformance Rules 1) Without Feature F781, “Self-referencing operations”, conforming SQL language shall not contain a in which either of the following is true: a) A leaf generally underlying table of T is an underlying table of any broadly con- tained in the . b) The broadly contains a , , , or whose subject routine is an external routine that possibly reads SQL-data. 2) Without Feature T111, “Updatable joins, unions, and columns”, conforming SQL language shall not contain a that contains a that identifies a table that is not simply updatable. 3) Without Feature T181, “Application-time period tables”, in conforming SQL language, a shall not contain FOR PORTION OF. Data manipulation 951 IWD 9075-2:201?(E) 14.10 14.10 Function Delete all rows of a base table without causing any triggered action. Format ::= TRUNCATE TABLE [ ] ::= CONTINUE IDENTITY | RESTART IDENTITY Syntax Rules 1) Let TTS be the and let TT be the contained in TTS. 2) Let TN be the
contained in TT and let T be the table identified by TN. The schema identified by the explicit or implicit of TN shall include the descriptor of T. 3) T shall be a base table and shall not be a system-versioned table. 4) T shall not be identified by the name of the referenced table in any referential constraint descriptor. 5) If is not specified, then CONTINUE IDENTITY is implicit. Access Rules 1) Let A be the that owns the schema identified by the of T. 2) The enabled authorization identifiers shall include A. General Rules 1) If the transaction access mode of the current SQL-transaction or the transaction access mode of the branch of the current SQL-transaction at the current SQL-connection is read-only, and T is not a temporary table, then an exception condition is raised: invalid transaction state — read-only SQL-transaction. 2) If there is any sensitive cursor CR that is currently open in the SQL-transaction in which this SQL-statement is being executed, then Case: a) If CR has not been held into a subsequent SQL-transaction, then either the change resulting from the successful execution of this statement shall be made visible to CR or an exception condition is raised: cursor sensitivity exception — request failed. b) Otherwise, whether the change resulting from the successful execution of this SQL-statement is made visible to CR is implementation-defined. 952 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.10 3) If there is any open, insensitive cursor CR, then either the change resulting from the successful execution of this statement shall be invisible to CR, or an exception condition is raised: cursor sensitivity exception — request failed. 4) The extent to which an SQL-implementation may disallow independent changes that are not significant is implementation-defined. 5) Case: a) If TT contains ONLY, then the rows for which there is no subrow in a proper subtable of T are deleted from T. b) Otherwise, all rows are deleted from T. 6) If any row that is deleted from T by TTS has been marked for deletion by any , , or that iden- tifies some open cursor CR or updated by any , , or that identifies some open cursor CR, then a completion condition is raised: warning — cursor operation conflict. 7) If no rows are deleted from T, then a completion condition is raised: no data. 8) If RESTART IDENTITY is specified and the table descriptor of T includes a column descriptor IDCD of an identity column, then: a) Let CN be the column name included in IDCD and let SV be the start value included in IDCD. b) The following is effectively executed without further Access Rule checking: ALTER TABLE TN ALTER COLUMN CN RESTART WITH SV Conformance Rules 1) Without Feature F200, “TRUNCATE TABLE statement”, conforming SQL language shall not contain a . 2) Without Feature F202, “TRUNCATE TABLE: identity column restart option”, conforming SQL language shall not contain an . Data manipulation 953 IWD 9075-2:201?(E) 14.11 14.11 This Subclause is modified by Subclause 14.4, “”, in ISO/IEC 9075-14. Function Create new rows in a table. Format  14  ::= INSERT INTO ::=
::= | | ::= [ ] [ ] ::= [ ] [ ] ::= OVERRIDING USER VALUE | OVERRIDING SYSTEM VALUE ::= DEFAULT VALUES ::= Syntax Rules 1) Let IS be the . 2) Let TN be the
contained in . Let T be the table identified by TN. 3) T shall be an insertable-into table or a trigger insertable-into table. 4) T shall not be an old transition table or a new transition table. 5) For each leaf generally underlying table of T whose descriptor includes a user-defined type name UDTN, the data type descriptor of the user-defined type UDT identified by UDTN shall indicate that UDT is instantiable. 954 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.11 6) An that specifies DEFAULT VALUES is implicitly replaced by an that specifies a of the form VALUES (DEFAULT, DEFAULT, ..., DEFAULT) where the number of instances of “DEFAULT” equal to the number of columns of T. 7) If the is omitted, then an that identifies all columns of T in the ascending sequence of their ordinal positions within T is implicit. 8) A column identified by the is an object column. No of T shall be identified more than once. 9) If T is not trigger insertable-into, then T shall be an updatable table; each object column shall be an updatable column of T . NOTE 470 — The notion of updatable columns of base tables is defined in Subclause 4.15, “Tables”. The notion of updatable columns of viewed tables is defined in Subclause 11.32, “”. 10) If CTTVC is specified, then every simply contained in CTTVC whose positionally corresponding in references a column of which some underlying column is a generated column shall be a . 11) Case: a) If some underlying column of a column referenced by a contained in is a system-generated self-referencing column or a derived self-referencing column, then shall be specified. b) If for some n, some underlying column of the column referenced by the CN contained in the n-th ordinal position in is an identity column, system-time period start column, or system-time period end column whose descriptor includes an indication that values are always generated, then Case: i) If is specified, then shall be specified. ii) If any simply contained in the is a , then shall be specified. iii) If the n-th simply contained in any simply contained in the is not a , then shall be specified. NOTE 471 — The preceding subrule does not cover all possibilities. The remaining possibilities are where is specified for every identity column, or for a system-time period start column or system-time period end column, in which case it is immaterial whether is specified or not. c) If for some n, some underlying column of the column referenced by the CN contained in the n-th ordinal position in is an identity column whose descriptor includes an indication that values are generated by default, then if is specified, then shall specify OVERRIDING USER VALUE. d) If for some n, some underlying column of the column referenced by the CN contained in the n-th ordinal position in is a system-time period start column or a system- Data manipulation 955 IWD 9075-2:201?(E) 14.11 time period end column whose descriptor includes an indication that values are always generated and is specified, then shall specify OVERRIDING USER VALUE. e) Otherwise, shall not be specified. 12) If CVC is specified, then the data type of every CVS specified in every CRVS con- tained in CVC is the data type DT indicated in the column descriptor for the positionally corresponding column in the explicit or implicit . If CVS is an that specifies ARRAY, then DT shall be an array type. If CVS is an that specifies MULTISET, then DT shall be a multiset type. 13) Let QT be the table specified by the or . The degree of QT shall be equal to the number of s in the . The column of table T identified by the i-th in the corresponds with the i-th column of QT. 14) The Syntax Rules of Subclause 9.2, “Store assignment”, are applied with corresponding columns of T as TARGET and QT as VALUE. 15) If IS is contained in a , then shall not contain a that specifies a parameter reference. 16) A simply contained in a shall not be a
. NOTE 472 — This rule removes a syntactic ambiguity; otherwise, “VALUES (1)” could be parsed either as ::= ::= ::=
::= VALUES (1) or ::= ::= ::= VALUES (1) Access Rules 1) Case: a) If IS is contained in, without an intervening that specifies SQL SECURITY INVOKER, an , then let A be the that owns that schema. The applicable privileges for A for T shall include INSERT for each object column. b) Otherwise, the current privileges for T shall include INSERT for each object column. 956 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.11 General Rules 1) If the transaction access mode of the current SQL-transaction or the transaction access mode of the branch of the current SQL-transaction at the current SQL-connection is read-only, and T is not a temporary table, then an exception condition is raised: invalid transaction state — read-only SQL-transaction. 2) If there is any sensitive cursor CR that is currently open in the SQL-transaction in which this SQL-statement is being executed, then Case: a) If CR has not been held into a subsequent SQL-transaction, then either the change resulting from the successful execution of this statement shall be made visible to CR or an exception condition is raised: cursor sensitivity exception — request failed. b) Otherwise, whether the change resulting from the successful execution of this SQL-statement is made visible to CR is implementation-defined. 3) If there is any open, insensitive cursor CR, then either the change resulting from the successful execution of this statement shall be invisible to CR, or an exception condition is raised: cursor sensitivity exception — request failed. 4) The extent to which an SQL-implementation may disallow independent changes that are not significant is implementation-defined. 5) QT is effectively evaluated before insertion of any rows into T. 6) Let Q be the result of evaluating QT. 7) For each row R of Q: a) A candidate row of T is effectively created in which the value of each column is its default value, as specified in the General Rules of Subclause 11.5, “”. The candidate row consists of every column of T. b) For each object column in the candidate row, let Ci be the object column identified by the i-th in the and let SVi be the i-th value of R. c) For every Ci such that Ci is not marked as unassigned and no underlying column of Ci is a self-refer- encing column, the General Rules of Subclause 9.2, “Store assignment”, are applied with Ci as TARGET and SVi as VALUE. Ci is no longer marked as unassigned. d) If T has a column RC of which some underlying column is a self-referencing column, then Case: i) If RC is a system-generated self-referencing column, then the value of RC is effectively replaced by the REF value of the candidate row. ii) If RC is a derived self-referencing column, then the value of RC is effectively replaced by a value derived from the columns in the candidate row that correspond to the list of attributes of the derived representation of the reference type of RC in an implementation-dependent manner. e) For every Ci for which one of the following conditions is true: i) Some underlying column of Ci is a user-generated self-referencing column. Data manipulation 957 IWD 9075-2:201?(E) 14.11 ii) Some underlying column of Ci is a self-referencing column and OVERRIDING SYSTEM VALUE is specified. iii) Some underlying column of Ci is an identity column and the i-th column of R is not derived from and OVERRIDING SYSTEM VALUE is specified. iv) Some underlying column of Ci is an identity column whose descriptor includes an indication that values are generated by default and neither OVERRIDING USER VALUE is specified nor is the i-th column derived from . The General Rules of Subclause 9.2, “Store assignment”, are applied with Ci as TARGET and SVi as VALUE. Ci is no longer marked as unassigned. NOTE 473 — If OVERRIDING USER VALUE is specified, then some columns of the candidate row(s) may continue to be marked as unassigned as a result of the preceding rules. The value of such columns is ultimately determined by the General Rules of Subclause 15.10, “Effect of inserting tables into base tables”, which has the effect of overriding user values specified in . NOTE 474 — The data values allowable in the candidate row may be constrained by a WITH CHECK OPTION constraint. The effect of a WITH CHECK OPTION constraint is defined in the General Rules of Subclause 15.12, “Effect of inserting a table into a viewed table”. 8) Let S be the table consisting of the candidate rows. Case: a) If T is a base table, then: i) T is identified for insertion of source table S. NOTE 475 — Identifying a base table for insertion of a source table is an implementation-dependent operation. ii) The General Rules of Subclause 15.10, “Effect of inserting tables into base tables”, are applied. b) If T is a viewed table, then the General Rules of Subclause 15.12, “Effect of inserting a table into a viewed table”, are applied with S as SOURCE and T as TARGET. 9) If Q is empty, then a completion condition is raised: no data. Conformance Rules 1) Without Feature F781, “Self-referencing operations”, conforming SQL language shall not contain an in which either of the following is true: a) The
of a leaf generally underlying table of T is broadly contained in the except as the table name of a qualifying table of a column reference. b) The broadly contains a , , , or whose subject routine is an external routine that possibly reads SQL-data. 2) Without Feature F222, “INSERT statement: DEFAULT VALUES clause”, conforming SQL language shall not contain a . 3) Without Feature S024, “Enhanced structured types”, in conforming SQL language, for each column C identified in the explicit or implicit , if the declared type of C is a structured type TY, 958 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.11 then the declared type of the corresponding column of the or shall be TY. 4) Without Feature S043, “Enhanced reference types”, conforming SQL language shall not contain an . 5) Without Feature T111, “Updatable joins, unions, and columns”, conforming SQL language shall not contain an that contains an that identifies a table that is not simply updatable. Data manipulation 959 IWD 9075-2:201?(E) 14.12 14.12 This Subclause is modified by Subclause 14.5, “”, in ISO/IEC 9075-14. Function Conditionally update and/or delete rows of a table and/or insert new rows into a table. Format  14  ::= MERGE INTO [ [ AS ] ] USING
ON ::= ::= ... ::= | ::= WHEN MATCHED [ AND ] THEN ::= | ::= WHEN NOT MATCHED [ AND ] THEN ::= UPDATE SET ::= DELETE ::= INSERT [ ] [ ] VALUES ::= [ { }... ] ::= | 960 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.12 Syntax Rules 1) Let TN be the
contained in TT and let T be the table identified by TN. 2) If is specified, then T shall be insertable-into or trigger insertable-into. 3) If is specified, then T shall be updatable or trigger updatable. 4) If is specified, then T shall be updatable or trigger deletable. 5) T shall not be an old transition table or a new transition table. 6) For each leaf generally underlying table of T whose descriptor includes a user-defined type name UDTN, the data type descriptor of the user-defined type UDT identified by UDTN shall indicate that UDT is instantiable. 7) If T is a view, then is effectively replaced by: ONLY ( TN ) 8) Case: a) If is specified, then let CN be the contained in . CN is an exposed . b) Otherwise, let CN be the
contained in . CN is an exposed
. 9) The scope of CN is the immediately contained in the , the immediately contained in a , the immediately contained in a , and the . 10) Let TR be the
immediately contained in . TR shall not directly contain a . 11) The or
that is exposed by TR shall not be equivalent to CN. 12) If an is omitted, then an that identifies all columns of T in the ascending sequence of their ordinal position within T is implicit. 13) Case: a) If some underlying column of a column referenced by a contained in is a system-generated self-referencing column or a derived self-referencing column, then shall be specified. b) If for some n, some underlying column of the column referenced by the contained in the n-th ordinal position in is an identity column, system-time period start column, or system-time period end column whose descriptor includes an indication that values are always generated, and the n-th simply contained in any simply contained in the is not a , then shall be specified. c) If for some n, some underlying column of the column referenced by the contained in the n-th ordinal position in is an identity column whose descriptor includes an indication that values are generated by default and is specified, then shall specify OVERRIDING USER VALUE. Data manipulation 961 IWD 9075-2:201?(E) 14.12 d) If for some n, some underlying column of the column referenced by the contained in the n-th ordinal position in is a system-time period start column or a system- time period end column whose descriptor includes an indication that values are always generated and is specified, then shall specify OVERRIDING USER VALUE. e) Otherwise, shall not be specified. 14) The immediately contained in a , the immediately contained in a , and the immediately contained in a shall not generally contain a whose subject routine is an SQL-invoked routine that possibly modifies SQL-data. 15) Each column identified by an in a is an update object column. Each column identified by a in an implicit or explicit is an insert object column. Each update object column and each insert object column is an object column. 16) If is specified and if T is not trigger insertable-into or if is specified and if T is not trigger updatable, then every object column shall identify an updatable column of T. NOTE 476 — The notion of updatable columns of base tables is defined in Subclause 4.15, “Tables”. The notion of updatable columns of viewed tables is defined in Subclause 11.32, “”. 17) No of T shall be identified more than once in an . 18) For each : a) Let NI be the number of s contained in . Let EXP1, EXP2, ... , EXPNI be those s. b) The number of s in the shall be equal to NI. c) The declared type of every CVS in a is the data type DT indicated in the column descriptor for the positionally corresponding column in the explicit or implicit . If CVS is an that specifies ARRAY, then DT shall be an array type. If CVS is an that specifies MULTISET, then DT shall be a multiset type. d) Every whose positionally corresponding in references a column of which some underlying column is a generated column shall be a . e) For 1 (one) ≤ i ≤ NI, the Syntax Rules of Subclause 9.2, “Store assignment”, are applied with EXPi as VALUE and the column of table T identified by the i-th in the as TARGET. 19) Let DSC be the immediately contained in . Case: a) If T is a system-versioned table, then let ENDCOL be the system-time period end column of T. Let ENDVAL be the highest value supported by the declared type of ENDCOL. Let SC1 be (DSC) AND (ENDCOL = ENDVAL) b) Otherwise, let SC1 be DSC. 962 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.12 Access Rules 1) Case: a) If is contained, without an intervening that specifies SQL SECURITY INVOKER, in an , then let A be the that owns that schema. i) If is specified, then the applicable privileges for A shall include UPDATE for each update object column. ii) If is specified, then the applicable privileges for A shall include DELETE for T. iii) If is specified, then the applicable privileges for A shall include INSERT for each insert object column. iv) If TT immediately contains ONLY, then the applicable privileges for A shall include SELECT WITH HIERARCHY OPTION on at least one supertable of T. b) Otherwise, i) If is specified, then the current privileges shall include UPDATE for each update object column. ii) If is specified, then the applicable privileges for A shall include DELETE for T. iii) If is specified, then the current privileges shall include INSERT for each insert object column. iv) If TT immediately contains ONLY, then the current privileges shall include SELECT WITH HIERARCHY OPTION on at least one supertable of T. General Rules 1) If the transaction access mode of the current SQL-transaction or the transaction access mode of the branch of the current SQL-transaction at the current SQL-connection is read-only, and T is not a temporary table, then an exception condition is raised: invalid transaction state — read-only SQL-transaction. 2) If there is any sensitive cursor CR that is currently open in the SQL-transaction in which this SQL-statement is being executed, then Case: a) If CR has not been held into a subsequent SQL-transaction, then either the change resulting from the successful execution of this statement shall be made visible to CR or an exception condition is raised: cursor sensitivity exception — request failed. b) Otherwise, whether the change resulting from the successful execution of this SQL-statement is made visible to CR is implementation-defined. 3) If there is any open, insensitive cursor CR, then either the change resulting from the successful execution of this statement shall be invisible to CR, or an exception condition is raised: cursor sensitivity exception — request failed. Data manipulation 963 IWD 9075-2:201?(E) 14.12 4) The extent to which an SQL-implementation may disallow independent changes that are not significant is implementation-defined. 5) Let QT be the table specified by the
. QT is effectively evaluated before update, deletion, or insertion of any rows in T. Let Q be the result of evaluating QT. 6) For each , in the order specified in the , Case: a) If MWMC is specified, then: i) For each row R1 of T: 1) SC1 and the SC2 immediately contained in MWMC, if any, are effec- tively evaluated for R1 with the exposed
of the TT bound to R1 and to each row of Q with the exposed s or
s of the
bound to that row. Both SC1 and SC2 are effectively evaluated for R1 before updating or deleting any row of T and prior to the invocation of any caused by the update or deletion of any row of T and before inserting any rows into T and prior to the invocation of any caused by the insert of any row of T. Case: A) If TT contains ONLY, then R1 is a subject row if R1 has no subrow in a proper subtable of T and the result of both SC1 and SC2 are True for some row R2 of Q and R1 is not a subject row identified by any other that precedes MWMC in the . R2 is the matching row. B) Otherwise, R1 is a subject row if the result of both SC1 and SC2 are True for some row R2 of Q and R1 is not a subject row identified by any other that precedes MWMC in the . R2 is the matching row. 2) If R1 is a subject row, then: A) Let M be the number of matching rows in Q for R1. B) If M is greater than 1 (one), then an exception condition is raised: cardinality violation. C) If is specified, then: I) The of each is effectively evaluated for R1 before any row of T is updated and prior to the invocation of any caused by the update of any row of T. The resulting value is the update value. II) A candidate new row is constructed by copying the subject row and updating it as specified by each by applying the General Rules of Subclause 14.15, “”. ii) Let S be the set consisting of every subject row. S is the old delta table of merge operation on T. iii) If T is a base table, then each subject row is also an object row; otherwise, an object row is any row of a leaf generally underlying table of T from which a subject row is derived. 964 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.12 NOTE 477 — The data values allowable in the object rows may be constrained by a WITH CHECK OPTION constraint. The effect of a WITH CHECK OPTION constraint is defined in the General Rules of Subclause 15.15, “Effect of replacing some rows in a viewed table”. iv) If any row in the set of object rows has been marked for deletion by any , , or that identifies some open cursor CR or updated by any , , or that identifies some open cursor, then a completion condition is raised: warning — cursor operation conflict. v) If is specified, then: 1) Let CL be the columns of T identified by the s contained in the . 2) Each subject row SR is identified for replacement, by its corresponding candidate new row CNR, in T. The set of (SR, CNR) pairs is the replacement set for T. NOTE 478 — Identifying a row for replacement, associating a replacement row with an identified row, and associating a replacement set with a table are implementation-dependent operations. 3) Case: A) If T is a base table, then: I) Case: 1) If TT specifies ONLY, then T is identified for replacement processing without subtables with respect to object columns CL. 2) Otherwise, T is identified for replacement processing with subtables with respect to object columns CL. NOTE 479 — Identifying a base table for replacement processing, with or without subtables, is an implementation-dependent mechanism. In general, though not here, the list of object columns can be empty. II) The General Rules of Subclause 15.13, “Effect of replacing rows in base tables”, are applied. B) If T is a viewed table, then the General Rules of Subclause 15.15, “Effect of replacing some rows in a viewed table”, are applied with TT as VIEW NAME and the replacement set for T as REPLACEMENT SET FOR VIEW NAME. vi) If is specified, then: 1) Each subject row is identified for deletion from T. 2) Case: A) If T is a base table, then: I) Case: 1) If TT specifies ONLY, then T is identified for deletion processing without subtables. 2) Otherwise, T is identified for deletion processing with subtables. Data manipulation 965 IWD 9075-2:201?(E) 14.12 NOTE 480 — Identifying a base table for deletion processing, with or without subta- bles, is an implementation-dependent mechanism. II) The General Rules of Subclause 15.7, “Effect of deleting rows from base tables”, are applied. B) Otherwise, T is a viewed table and the General Rules of Subclause 15.9, “Effect of deleting some rows from a viewed table”, are applied with TT as VIEW NAME. b) If MWNMC is specified, then: i) Let TR1 be the immediately contained in and let TR2 be the
immediately contained in . If is specified, then let MCN be “AS ”; otherwise, let MCN be a zero- length string. If MWNMC immediately contains a SC2, then let ONSC2 be “OR NOT SC2”; otherwise, let ONSC2 be a zero-length string. Let S1 be the result of SELECT * FROM TR1 MCN, TR2 WHERE SC1 ONSC2 ii) Let S2 be the collection of rows of Q for which there exists in S1 some row that is the concate- nation of some row R1 of T and some row R2 of Q. iii) Let S3 be the collection of rows of Q that are not in S2. Let SN3 be the effective distinct name for S3. Let EN be the exposed or
of TR2. iv) Let S4 be the result of: SELECT EXP1, EXP2, ... , EXPNI FROM SN3 AS EN v) Let S5 be the collection of rows of S4 for which no candidate rows have been effectively created by any other that precedes MWNMC in the . vi) S5 is effectively evaluated before deletion of any rows from, insertion of any rows into, or update of any rows in T. vii) For each row R of S5: 1) A candidate row of T is effectively created in which the value of each column is its default value, as specified in the General Rules of Subclause 11.5, “”. The candidate row consists of every column of T. 2) If T has a column RC of which some underlying column is a self-referencing column, then Case: A) If RC is a system-generated self-referencing column, then the value of RC is effectively replaced by the REF value of the candidate row. B) If RC is a derived self-referencing column, then the value of RC is effectively replaced by a value derived from the columns in the candidate row that correspond to the list of attributes of the derived representation of the reference type of RC in an implemen- tation-dependent manner. 966 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.12 3) For each object column in the candidate row, let Ci be the object column identified by the i-th in the and let SVi be the i-th value of R. 4) For every Ci for which one of the following conditions is true: A) Ci is not marked as unassigned and no underlying column of Ci is a self-referencing column. B) Some underlying column of Ci is a user-generated self-referencing column. C) Some underlying column of Ci is a self-referencing column and OVERRIDING SYSTEM VALUE is specified. D) Some underlying column of Ci is an identity column and the i-th column of R is not derived from and OVERRIDING SYSTEM VALUE is speci- fied. E) Some underlying column of Ci is an identity column whose descriptor includes an indication that values are generated by default and neither OVERRIDING USER VALUE is specified nor is the i-th column derived from . the General Rules of Subclause 9.2, “Store assignment”, are applied with Ci as TARGET and SVi as VALUE. Ci is no longer marked as unassigned. NOTE 481 — If OVERRIDING USER VALUE is specified, then some columns of the candidate row(s) may continue to be marked as unassigned as a result of the preceding rules. The value of such columns is ultimately determined by the General Rules of Subclause 15.10, “Effect of inserting tables into base tables”, which has the effect of overriding user values specified in . NOTE 482 — The data values allowable in the candidate row may be constrained by a WITH CHECK OPTION constraint. The effect of a WITH CHECK OPTION constraint is defined in the General Rules of Subclause 15.12, “Effect of inserting a table into a viewed table”. viii) Let S be the table consisting of the candidate rows. Case: 1) If T is a base table, then: A) T is identified for insertion of source table S. NOTE 483 — Identifying a base table for insertion of a source table is an implementation-dependent operation. B) The General Rules of Subclause 15.10, “Effect of inserting tables into base tables”, are applied. 2) If T is a viewed table, then the General Rules of Subclause 15.12, “Effect of inserting a table into a viewed table”, are applied with S as SOURCE and T as TARGET. 7) If Q is empty, then a completion condition is raised: no data. Conformance Rules 1) Without Feature F781, “Self-referencing operations”, conforming SQL language shall not contain a in which either of the following is true: Data manipulation 967 IWD 9075-2:201?(E) 14.12 a) A leaf generally underlying table of T is broadly contained in a immediately contained in the
except as the
or of a column reference. b) A immediately contained in the
broadly contains a , , , or whose subject routine is an external routine that possibly reads SQL-data. 2) Without Feature F781, “Self-referencing operations”, conforming SQL language shall not contain a in which either of the following is true: a) A leaf generally underlying table of T is an underlying table of any broadly con- tained in any . b) Any broadly contains a , , , or whose subject routine is an external routine that possibly reads SQL-data. 3) Without Feature S024, “Enhanced structured types”, conforming SQL language shall not contain a that does not satisfy the condition: for each column C identified in the explicit or implicit , if the declared type of C is a structured type TY, then the declared type of the corresponding column of the or is TY. 4) Without Feature F312, “MERGE statement”, conforming SQL language shall not contain a . 5) Without Feature T111, “Updatable joins, unions, and columns”, conforming SQL language shall not contain a that contains an that identifies a table that is not simply updatable. 6) Without Feature F313, “Enhanced MERGE statement”, in conforming SQL language, a shall not contain each of and more than once. 7) Without Feature F313, “Enhanced MERGE statement”, in conforming SQL language, a or a shall not immediately contain a . 8) Without Feature F314, “MERGE statement with DELETE branch”, in conforming SQL language, a shall not immediately contain a . 968 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.13 14.13 This Subclause is modified by Subclause 12.7, “”, in ISO/IEC 9075-4. This Subclause is modified by Subclause 11.13, “”, in ISO/IEC 9075-10. This Subclause is modified by Subclause 14.6, “”, in ISO/IEC 9075-14. Function Update a row of a table. Format  10   14  ::= UPDATE [ [ AS ] ] SET WHERE CURRENT OF Syntax Rules 1)  04  Let USP be the and let CN be the immediately contained in USP. CN shall be contained within the scope of a that is equivalent to CN. 2) CN shall identify a standing cursor. 3) Let CDD be the cursor declaration descriptor of the standing cursor identified by CN. 4) The cursor specification of CDD shall be updatable. 5) Let TU be the simply underlying table of the cursor identified by CN. Let LUT be the leaf underlying table of TU such that TU is one-to-one with respect to LUT. 6) Let TT be the and let TN be the
contained in TT. TN shall identify LUT. 7) LUT shall not be an old transition table or a new transition table. 8) It TT immediately contains ONLY and LUT is not a typed table, then TT is equivalent to TN. 9) TT shall specify ONLY if and only if the
contained in TU that references LUT specifies ONLY. 10) The schema identified by the explicit or implicit qualifier of TN shall include the descriptor of LUT. 11) Case: a) If is specified, then let COR be that . COR is an exposed . b) Otherwise, let COR be the
contained in TT. COR is an exposed
. 12) The scope of COR is . 13) If the declared CS of CDD is ordered, then for each OC contained in , no generally underlying column of a in the simply con- tained in the of CS shall be OC or a generally underlying column of OC. Data manipulation 969 IWD 9075-2:201?(E) 14.13 14) Each specified as an shall identify a column in the explicit or implicit contained in the explicit or implicit of the of CDD. Access Rules 1) Case: a) If USP is contained, without an intervening that specifies SQL SECURITY INVOKER, in an , then let A be the that owns that schema. The applicable privileges for A shall include UPDATE for each . b) Otherwise, the current privileges shall include UPDATE for each . General Rules 1) Let CR be the cursor instance descriptor of the current SQL-session whose cursor declaration descriptor is CDD. 2) Let SCL be the . 3) The General Rules of Subclause 15.6, “Effect of a positioned update”, are applied with CR as CURSOR, SCL as SET CLAUSE LIST, USP as STATEMENT, and TT as TARGET. Conformance Rules 1) Without Feature F831, “Full cursor update”, conforming SQL language shall not contain an in which the declared of CDD is ordered. 970 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.14 14.14 This Subclause is modified by Subclause 14.7, “”, in ISO/IEC 9075-14. Function Update rows of a table. Format  14  ::= UPDATE [ FOR PORTION OF FROM TO ] [ [ AS ] ] SET [ WHERE ] Syntax Rules 1) Let USS be the , let TT be the contained in USS, and let SCL be the contained in USS. 2) Let TN be the
contained in TT and let T be the table identified by TN. 3) T shall be an updatable table or a trigger updatable table. 4) T shall not be an old transition table or a new transition table. 5) If WHERE is not specified, then WHERE TRUE is implicit. 6) Let DSC be the implicit or explicit . DSC shall not generally contain a whose subject routine is an SQL-invoked routine that possibly modifies SQL-data. Case: a) If T is a system-versioned table, then let ENDCOL be the system-time period end column of T. Let ENDVAL be the highest value supported by the declared type of ENDCOL. Let TSC be (DSC) AND (ENDCOL = ENDVAL) b) Otherwise, let TSC be DSC. 7) Case: a) If FOR PORTION OF ATPN is specified, then the table descriptor of T shall include a ATPN period descriptor. i) Let BSTARTCOL be the name of the ATPN period start column of T; let BENDCOL be the name of the ATPN period end column of T. Let BCD be the declared type of the ATPN period start column of T. Data manipulation 971 IWD 9075-2:201?(E) 14.14 ii) Neither BSTARTCOL nor BENDCOL shall be an explicit contained in the . iii) Let FROMVAL be . FROMVAL shall not generally contain a reference to a column of T or a whose subject routine is an SQL-invoked routine that is possibly non-deterministic or that possibly modifies SQL-data. iv) Let TOVAL be . TOVAL shall not generally contain a reference to a column of T or a whose subject routine is an SQL-invoked routine that is possibly non-deterministic or that possibly modifies SQL-data. v) Let SC be TSC AND (FROMVAL < TOVAL) AND (BENDCOL > FROMVAL) AND (BSTARTCOL < TOVAL) vi) The following two s are implicitly added to SCL: BSTARTCOL = CASE WHEN BSTARTCOL > FROMVAL THEN BSTARTCOL ELSE CAST ( FROMVAL AS BCD ) END, BENDCOL = CASE WHEN BENDCOL < TOVAL THEN BENDCOL ELSE CAST ( TOVAL AS BCD ) END b) Otherwise, let SC be TSC. 8) If UPS is contained in a , then SC shall not contain a that specifies a parameter reference. 9) Case: a) If is specified, then let CN be that . CN is an exposed . b) Otherwise, let CN be the
contained in TT. CN is an exposed
. 10) The scope of CN is SCL and SC. Access Rules 1) Case: a) If USS is contained, without an intervening that specifies SQL SECURITY INVOKER, in an , then let A be the that owns that schema. i) The applicable privileges for A for T shall include UPDATE for each . 972 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.14 ii) If TT immediately contains ONLY, then the applicable privileges for A shall include SELECT WITH HIERARCHY OPTION on at least one supertable of T. b) Otherwise, i) The current privileges for T shall include UPDATE for each . ii) If TT immediately contains ONLY, then the current privileges shall include SELECT WITH HIERARCHY OPTION on at least one supertable of T. General Rules 1) If the transaction access mode of the current SQL-transaction or the transaction access mode of the branch of the current SQL-transaction at the current SQL-connection is read-only and T is not a temporary table, then an exception condition is raised: invalid transaction state — read-only SQL-transaction. 2) If there is any sensitive cursor CR that is currently open in the SQL-transaction in which this SQL-statement is being executed, then Case: a) If CR has not been held into a subsequent SQL-transaction, then either the change resulting from the successful execution of this statement shall be made visible to CR or an exception condition is raised: cursor sensitivity exception — request failed. b) Otherwise, whether the change resulting from the successful execution of this SQL-statement is made visible to CR is implementation-defined. 3) If there is any open, insensitive cursor CR, then either the change resulting from the successful execution of this statement shall be invisible to CR, or an exception condition is raised: cursor sensitivity exception — request failed. 4) The extent to which an SQL-implementation may disallow independent changes that are not significant is implementation-defined. 5) Case: a) If TT contains ONLY, then SC is effectively evaluated for each row of T with the exposed s or
s bound to that row, and the subject rows are those rows for which the result of SC is True and for which there is no subrow in a proper subtable of T. SC is effectively evaluated for each row of T before updating any row of T. b) Otherwise, SC is effectively evaluated for each row of T with the exposed s or
s of TT bound to that row, and the subject rows are those rows for which the result of SC is True. SC is effectively evaluated for each row of T before updating any row of T. 6) Let S be the set consisting of every subject row. S is the old delta table of update operation on T. If FOR PORTION OF is specified, then FROMVAL and TOVAL are associated with every row in S as the associated for portion of from-value and the associated for portion of to-value, respectively. 7) If T is a base table, then each subject row is also an object row; otherwise, an object row is any row of a leaf generally underlying table of T from which a subject row is derived. 8) If any row in the set of object rows has been marked for deletion by any , , or that iden- Data manipulation 973 IWD 9075-2:201?(E) 14.14 tifies some open cursor CR or updated by any , , or that identifies some open cursor CR, then a completion condition is raised: warning — cursor operation conflict. 9) SC is evaluated for each row of T prior to the invocation of any caused by the update of any row of T. 10) The of each contained in SCL is effectively evaluated for each row of T before any row of T is updated. 11) For each subject row, a candidate new row is constructed by copying the subject row and updating it as specified by each contained in SCL by applying the General Rules of Subclause 14.15, “”. NOTE 484 — The data values allowable in the object rows may be constrained by a WITH CHECK OPTION constraint. The effect of a WITH CHECK OPTION constraint is defined in the General Rules of Subclause 15.15, “Effect of replacing some rows in a viewed table”. 12) Let CL be the columns of T identified by the s contained in SCL. 13) Each subject row SR is identified for replacement, by its corresponding candidate new row CNR, in T. The set of (SR, CNR) pairs is the replacement set for T. NOTE 485 — Identifying a row for replacement, associating a replacement row with an identified row, and associating a replacement set with a table are implementation-dependent operations. 14) Case: a) If T is a base table, then: i) Case: 1) If TT specifies ONLY, then T is identified for replacement processing without subtables with respect to object columns CL. 2) Otherwise, T is identified for replacement processing with subtables with respect to object columns CL. NOTE 486 — Identifying a base table for replacement processing, with or without subtables, is an implemen- tation-dependent mechanism. In general, though not here, the list of object columns can be empty. ii) The General Rules of Subclause 15.13, “Effect of replacing rows in base tables”, are applied. b) If T is a viewed table, then the General Rules of Subclause 15.15, “Effect of replacing some rows in a viewed table”, are applied with TT as VIEW NAME and the replacement set for T as REPLACEMENT SET FOR VIEW NAME. 15) If the set of object rows is empty, then a completion condition is raised: no data. Conformance Rules 1) Without Feature F781, “Self-referencing operations”, conforming SQL language shall not contain an in which either of the following is true: a) A leaf generally underlying table of T is an underlying table of any broadly con- tained in the . 974 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.14 b) The broadly contains a , , , or whose subject routine is an external routine that possibly reads SQL-data. 2) Without Feature T111, “Updatable joins, unions, and columns”, conforming SQL language shall not contain an that contains a that identifies a table that is not simply updatable. 3) Without Feature T181, “Application-time period tables”, in conforming SQL language, an shall not contain FOR PORTION OF. Data manipulation 975 IWD 9075-2:201?(E) 14.15 14.15 Function Specify a list of updates. Format ::= [ { }... ] ::= | ::= | ::= ::= [ { }... ] ::= ::= | ::= ::= ::= | ::= | Syntax Rules 1) Let T be the table identified by the contained in the containing , , or . 2) If T is not trigger updatable, then each specified as an shall identify an updatable column of T. 976 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.15 NOTE 487 — The notion of updatable columns of base tables is defined in Subclause 4.15, “Tables”. The notion of updatable columns of viewed tables is defined in Subclause 11.32, “”. 3) No shall reference a column of which some underlying column is a system-time period start column or a system-time period end column. 4) Each SC that immediately contains a is effectively replaced by a MSCL as follows: a) Let STN be the number of s contained in . b) STN shall be equal to the degree of the AR contained in SC. c) Let STi, 1 (one) ≤ i ≤ STN, be the i-th contained in the of SC and let DTi be the declared type of the i-th field of AR. The i-th in MSCL is: STi = CAST ( AR AS ROW ( F1 DT1, F2 DT2, ..., FSTN DTSTN ) ).Fi NOTE 488 — “Fn” here stands for the consisting of the letter “F” followed, with no intervening by the decimal or s comprising a corresponding to the value n. 5) If SC specifies an that references a column of which some underlying column is either a generated column or an identity column whose descriptor indicates that values are always gen- erated, then the specified in SC shall consist of a . 6) A simply contained in an in a shall not directly contain a . 7) If the OSCL contains one or more s that contain a , then: a) Let N be the number of s in OSCL that contain a . b) For 1 (one) ≤ i ≤ N: i) Let SCi be the i-th that contains a . ii) Let RCVEi be the immediately contained in SCi. iii) Let MSCi be the immediately contained in the immediately contained in SCi. iv) Let OCi be the contained in MSCi. The declared type of the column identified by OCi shall be a structured type. v) Let Mi be the number of s contained in MSCi. vi) For 1 (one) ≤ j ≤ Mi: Case: 1) If j = 1 (one), then A) Let MTi,1 be the immediately contained in MSCi. Data manipulation 977 IWD 9075-2:201?(E) 14.15 B) Let MNi,1 be the immediately contained in MSCi. C) Let Vi,1 be: MTi,1 . MNi,1 ( RCVEi ) 2) Otherwise: A) Let MTi,j be the immediately contained in the immediately contained in MTi,j-1. B) Let MNi,j be the immediately contained in the immediately contained in MTi,j-1. C) Let Vi,j be MTi,j . MNi,j ( Vi,j-1 ) c) OSCL is equivalent to a NSCL derived as follows: i) Let NSCL be a derived from OSCL by replacing every SCa, 1 (one) ≤ a ≤ N, that contains a with: MTa,Ma = Va,Ma ii) For 1 (one) ≤ b ≤ N, if there exists a c such that c < b and OCc is equivalent to OCb, then: 1) Every occurrence of OCb in Vb,Mb is replaced by Vc,Mc. 2) SCc is deleted from NSCL. 8) Equivalent s shall not appear more than once in a . NOTE 489 — Multiple occurrences of equivalent s within s are eliminated by the preceding Syntax Rule of this Subclause. 9) If the of SC specifies a CVS, then the data type of CVS is the data type DT of the or specified in SC. 10) If CVS is an , then DT shall be a collection type or a distinct type whose source type is a collection type. If CVS specifies ARRAY, then DT shall be an array type or a distinct type whose source type is an array type. If CVS specifies MULTISET, then DT shall be a multiset type or a distinct type whose source type is a multiset type. 11) For every in a , Case: a) If the immediately contains , then the declared type of the column of T identified by the shall be an array type or a distinct type whose source type is an array type. The Syntax Rules of Subclause 9.2, “Store assignment”, are applied with a temporary site whose declared type is element type of the column of T identified by the as TARGET and the of the as VALUE. 978 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.15 b) Otherwise, the Syntax Rules of Subclause 9.2, “Store assignment”, are applied with the column of T identified by the as TARGET and the of the as VALUE. Access Rules None. General Rules 1) A specifies one or more object columns and an update value. An object column is a column identified by an in the . The update value is the value specified by the contained in the . 2) The value of the i-th object column denoted by C, is replaced as follows. Case: a) If the i-th contains an that immediately contains a , then Case: i) If the value of C is the null value, then an exception condition is raised: data exception — null value in array target. ii) Otherwise: 1) Let N be the maximum cardinality of C. 2) Let M be the cardinality of the value of C. 3) Let I be the value of the immediately contained in . 4) Let EDT be the element type of C. 5) Case: A) If I is greater than zero and less than or equal to M, then the value of C is replaced by an array A with element type EDT and cardinality M derived as follows: I) For j varying from 1 (one) to I–1 and from I+1 to M, the j-th element in A is the value of the j-th element in C. II) The General Rules of Subclause 9.2, “Store assignment”, are applied with I-th element of A as TARGET and the i-th update value, denoted by SV as VALUE. B) If I is greater than M and less than or equal to N, then the value of C is replaced by an array A with element type EDT and cardinality I derived as follows: I) For j varying from 1 (one) to M, the j-th element in A is the value of the j-th element in C. II) For j varying from M+1 to I–1, the j-th element in A is the null value. Data manipulation 979 IWD 9075-2:201?(E) 14.15 III) The General Rules of Subclause 9.2, “Store assignment”, are applied with I-th element of A as TARGET and the i-th update value, denoted by SV as VALUE. C) Otherwise, an exception condition is raised: data exception — array element error. b) Otherwise, the value of C is replaced by the i-th update value, denoted by SV. The General Rules of Subclause 9.2, “Store assignment”, are applied with C as TARGET and SV as VALUE. Conformance Rules 1) Without Feature F781, “Self-referencing operations”, conforming SQL language shall not contain a in which either of the following is true: a) A leaf generally underlying table of T is an underlying table of any broadly con- tained in any simply contained in an or immedi- ately contained in the . b) An or immediately contained in the broadly contains a , , , or whose subject routine is an external routine that possibly reads SQL-data. 2) Without Feature S091, “Basic array support”, conforming SQL language shall not contain an that immediately contains a . 3) Without Feature S024, “Enhanced structured types”, conforming SQL language shall not contain a in which the declared type of the in the is a structured type TY and the declared type of the or corresponding field of the contained in the is not TY. 4) Without Feature S024, “Enhanced structured types”, conforming SQL language shall not contain a that contains a and in which the declared type of the last identifies a structured type TY, and the declared type of the contained in the is not TY. 5) Without Feature T641, “Multiple column assignment”, conforming SQL language shall not contain a . 980 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.16 14.16 This Subclause is modified by Subclause 12.8, “”, in ISO/IEC 9075-4. Function Declare a declared local temporary table. Format ::= DECLARE LOCAL TEMPORARY TABLE
[ ON COMMIT
ROWS ] Syntax Rules 1) Let TN be the
of a TTD, and let T be the of TN. 2)  04  TTD shall be contained in an . 3) Case: a) If TN contains a LSQ, then LSQ shall be “MODULE”. b) If TN does not contain a , then “MODULE” is implicit. 4)  04  If a is contained in an M, then the of TN shall not be equivalent to the of the
of any other that is contained in M. 5) The descriptor of the table defined by a includes TN and the column descriptor specified by each . The i-th column descriptor is given by the i-th . 6)
shall contain at least one or at least one . 7)
shall not contain a
that is a
. 8) If ON COMMIT is not specified, then ON COMMIT DELETE ROWS is implicit. Access Rules None. General Rules 1) Let U be the implementation-dependent of the schema that contains the declared local temporary table such that U does not contain a table whose
is equivalent to TN. 2) Let UI be the current user identifier and let R be the current role name. Data manipulation 981 IWD 9075-2:201?(E) 14.16 Case: a) If UI is not the null value, then let A be UI. b) Otherwise, let A be R. 3)  04  The definition of T within an SQL-client module is effectively equivalent to the definition of a persistent base table U.T. Within the SQL-client module, any reference to MODULE.T is equivalent to a reference to U.T. 4) A set of privilege descriptors is created that define the privileges INSERT, SELECT, UPDATE, DELETE, and REFERENCES on this table and INSERT, SELECT, UPDATE, and REFERENCES for every in the table definition to A. These privileges are not grantable. The grantor for each of these privilege descriptors is set to the special grantor value “_SYSTEM”. The grantee is “PUBLIC”. 5) The definition of a temporary table persists for the duration of the SQL-session. The termination of the SQL-session is effectively followed by the execution of the following with the current authorization identifier A and current U without further Access Rule checking: DROP TABLE T CASCADE 6) The definition of a declared local temporary table does not appear in any view of the Information Schema. NOTE 490 — The Information Schema is defined in [ISO9075-11]. Conformance Rules 1) Without Feature F531, “Temporary tables”, conforming SQL language shall not contain a . 982 Foundation (SQL/Foundation) IWD 9075-2:201?(E) 14.17 14.17 Function Remove the association between a locator variable and the value that is represented by that locator. Format ::= FREE LOCATOR [ { }... ] ::= | | Syntax Rules 1) Each host parameter identified by immediately contained in shall be a binary large object locator parameter, a character large object locator parameter, an array locator parameter, a multiset locator parameter, or a user-defined type locator parameter. 2) Each host variable identified by the immediately contained in shall be a binary large object locator variable, a character large object locator variable, an array locator variable, a multiset locator variable, or a user-defined type locator variable. Access Rules None. General Rules 1) For every LR immediately contained in , let L be the value of LR. Case: a) If L is not a valid locator value, then an exception condition is raised: locator exception — invalid specification. b) Otherwise, L is marked invalid. Conformance Rules 1) Without Feature T561, “Holdable locators”, conforming SQL language shall not contain a . Data manipulation 983 IWD 9075-2:201?(E) 14.18 14.18 Function Mark a locator variable as being holdable. Format ::= HOLD LOCATOR [ { }... ] Syntax Rules 1) Each host parameter identified by immediately contained in shall be a binary large object locator parameter, a character large object locator parameter, an array locator parameter, a multiset locator parameter, or a user-defined type locator parameter. Access Rules None. General Rules 1) For every LR immediately contained in , let L be the value of LR. Case: a) If L is not a valid locator value, then an exception condition is raised: locator exception — invalid specification. b) Otherwise, L is marked holdable. Conformance Rules 1) Without Feature T561, “Holdable locators”, conforming SQL language shall not contain a .