remote dba support
More
    HomeOracle DBA TipsVirtual columns in Oracle

    Virtual columns in Oracle

    The blog post provides information about Virtual columns in Oracle, about how to create and what are the usage in Oracle 11g onward version.

    Virtual columns in Oracle 11g onward versions

    Virtual columns are one of the new features introduced in Oracle Database 11g and included in Express Edition 11g Version 2 and later. It consists of fields that obtain their values ​​from expressions that refer to other columns, such expressions can include calls to functions.

    A concrete example:

    - Advertisement -
    dbametrix

    We will create a table that records the sale of products by adding the following fields:
    purchase_id, product_id, price, quantity, amount.

    Run the SQL command line.
    Login as SYSTEM user:

    conn system/yourpassword@localhost:1521/TESDB1

    Create a user with name: Store.

    - Advertisement -
    dbametrix

    CREATE USER store IDENTIFIED BY abc123 DEFAULT TABLESPACE USERS;

    4. Grant CONNECT and RESOURCE roles.

    GRANT CONNECT, RESOURCE TO store;

    5. Disconnect with the disc command;
    SQL> disc;

    6. Login as a store user.
    CONN store/abc123 @ localhost: 1521 / XEPDB1

    7. Enter the following sentence:
    CREATE TABLE SALES (
    PRODUCT_ID NUMBER (6) NOT NULL,
    BUY_ID NUMBER (5) NOT NULL,
    QUANTITY NUMBER (7,3) NOT NULL,
    PRICE NUMBER (7,3) NOT NULL,
    AMOUNT NUMBER GENERATED ALWAYS AS
    (QUANTITY * PRICE) VIRTUAL
    );

    8. Insert a test record.
    INSERT INTO SALES (PRODUCT_ID,
    BUY_ID,
    QUANTITY,
    PRICE)
    VALUES (200,350,10,20.35);

    9. Select the record inserted with the statement:
    SELECT *
    FROM SALES;

    I hope it helps to understand how Virtual columns will be created and what is the usage.

    When you want to make a strong Oracle DBA career then you should be aware of database services and other database technology. Without having knowledge of Oracle internals, Oracle performance tuning, and skill of Oracle database troubleshooting you can’t be an Oracle DBA expert.

    This expert DBA Team club blog always provides you latest technology news and database news to keep yourself up to date. You should need to be aware of Cloud database technology like DBaaS. All Oracle DBA tips are available in a single unique resource at our orageek. Meanwhile, we are also providing some sql tutorials for Oracle DBA. This is the part of Dbametrix Group and you would enjoy more advanced topics from our partner resource.

    - Advertisement -
    dbametrix
    - Advertisment -
    remote dba services

    Most Popular