0

I want to make database calculate a column. For example: There is a column named 'price'. every time I insert a new value into the price, I want another column named 'percent' automatically calculate 1% of the new value. Like this;

Price     Percent
100        1
250        2,5

How can I create this?

1
  • So you are saying that if the price of something is 100, that price is 1% of .... what? Commented Dec 8, 2020 at 14:20

1 Answer 1

3

Create a virtual column:

SQL> create table test
  2    (price       number,
  3     percent     number as (price * 0.01)        --> this
  4    );

Table created.

SQL> insert into test(price)
  2  select 100 from dual union all
  3  select 250 from dual;

2 rows created.

SQL> select * From test;

     PRICE    PERCENT
---------- ----------
       100          1
       250        2,5

SQL>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.