OceanBase Database stores multiple versions of data. In a table, ORA_ROWSCN can be considered as a column in the table that represents the latest version number of each data row. Assume that two transactions t1 and t2 are committed in order. The ORA_ROWSCN value obtained after t1 is committed is smaller than that obtained after t2 is committed. In OceanBase Database, the value of ORA_ROWSCN monotonically increments. In Oracle Database, ORA_ROWSCN is a logical number in the system and has no actual meaning. In OceanBase Database, ORA_ROWSCN is the system time when the transaction where the data modification occurs is committed. The value can be converted into a meaningful time.
Considerations
ORA_ROWSCNcan be used only in entity tables, but not in queries on views.ORA_ROWSCNcan appear as a regular column in the expression part, such as in aWHEREclause.ORA_ROWSCNis not a reserved keyword. If a column is namedORA_ROWSCNin a table, theORA_ROWSCNpseudocolumn does not take effect in the table.- You cannot use
ORA_ROWSCNin flashback queries. If you do, the semantics ofORA_ROWSCNwill be ambiguous.
Examples
Create a table named
tbl1.CREATE TABLE tbl1(col1 INT);Insert a test data record into the
tbl1table.INSERT INTO tbl1 VALUES(10);Insert three more test data records into the
tbl1table.INSERT INTO tbl1 VALUES(30),(40),(50);Obtain the
ORA_ROWSCNvalue wherecol1 = 10in thetbl1table.SELECT ORA_ROWSCN FROM tbl1 WHERE col1 = 10;The return result is as follows:
+---------------------+ | ORA_ROWSCN | +---------------------+ | 1721975097797659000 | +---------------------+ 1 row in setObtain the data with the specified
ORA_ROWSCNvalue. Data committed in the same transaction has the sameORA_ROWSCNvalue.Obtain the
ORA_ROWSCNvalues wherecol1 = 30/40/50in thetbl1table.SELECT col1, ORA_ROWSCN FROM tbl1 WHERE col1 IN (30,40,50);The return result is as follows:
+------+---------------------+ | COL1 | ORA_ROWSCN | +------+---------------------+ | 30 | 1721975326593884000 | | 40 | 1721975326593884000 | | 50 | 1721975326593884000 | +------+---------------------+ 3 rows in setLocate the row in the
tbl1table based on the specifiedORA_ROWSCNvalue and change thecol1value of the row to20.UPDATE tbl1 SET col1 = 20 WHERE ORA_ROWSCN = 1721975326593884000;The return result is as follows:
Query OK, 3 rows affected Rows matched: 3 Changed: 3 Warnings: 0
Use
ORA_ROWSCNin an expression.SELECT col1, ORA_ROWSCN FROM tbl1 WHERE ORA_ROWSCN + 1 = 1721975097797659001;The return result is as follows:
+------+---------------------+ | COL1 | ORA_ROWSCN | +------+---------------------+ | 10 | 1721975097797659000 | +------+---------------------+ 1 row in set