我想让数据库计算一列。例如:有一个名为“price”的列。每次我在价格中插入一个新值时,我希望另一个名为“percent”的列自动计算新值的1%。像这样;
Price Percent
100 1
250 2,5
我如何创建它?
发布于 2020-12-08 11:20:40
创建虚拟列:
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>
https://stackoverflow.com/questions/65196751
复制