[英]Oracle SQL how to make database calculate a column?
我想讓數據庫計算一列。 例如:有一個名為“價格”的列。 每次我在價格中插入一個新值時,我希望另一個名為“百分比”的列自動計算新值的 1%。 像這樣;
Price Percent
100 1
250 2,5
我怎樣才能創建這個?
創建一個虛擬列:
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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.