In Oracle mode of OceanBase Database, you can add, modify, and drop a VIRTUAL column.
Add a VIRTUAL column
The syntax for adding a VIRTUAL column is as follows:
ALTER TABLE table_name ADD (column_name [datatype ][ GENERATED ALWAYS ] AS (column_expression) [VIRTUAL]);
Here is an example:
obclient> CREATE TABLE t1(c1 INT,c2 VARCHAR(50),c3 INT GENERATED ALWAYS AS (c1 * 10) VIRTUAL);
Query OK, 0 rows affected
obclient> ALTER TABLE t1 ADD (c4 INT GENERATED ALWAYS AS (c1 + 1) VIRTUAL);
Query OK, 0 rows affected
Drop a VIRTUAL column
The syntax for dropping a VIRTUAL column is as follows:
ALTER TABLE table_name DROP COLUMN column_name;
Here is an example:
obclient> ALTER TABLE t1 DROP COLUMN c3;
Query OK, 0 rows affected