Search code examples
databaseoracleinsertderived-table

Insert derived sum value of a column into another table as a record in oracle database


I got error on oracle database

ORA-00936: missing expression

I dont know how to properly insert a record on a table which is a sum of all the value from another table.

    INSERT INTO initial_transaction_inventory
    VALUES (10000, SELECT SUM (pyi_total_price) FROM payable_inventory, SELECT SUM (pai_total_cost) FROM paid_inventory, SYSDATE, utl_raw.cast_to_raw ('C:\Users\username\Documents'));

This is what i'm trying to do with my codes.


Solution

  • You just need to use the brackets as follows:

    INSERT INTO initial_transaction_inventory
    VALUES (10000,
            (SELECT SUM (pyi_total_price) FROM payable_inventory),
            (SELECT SUM (pai_total_cost) FROM paid_inventory),
            SYSDATE,
            utl_raw.cast_to_raw ('C:\Users\username\Documents'));