一、 不知何故,怀疑那些表只包含您提到的列。他们都缺乏某种
ID
这将使加入成为可能。否则,那就没有意义了。
例如(连同一些示例数据):
SQL> create table product (product_id number, price number);
Table created.
SQL> create table bill (product_id number, quantity number, total_price number);
Table created.
SQL> insert all
2 into product (product_id, price) values (1, 100)
3 into product (product_id, price) values (2, 200)
4 into bill (product_id, quantity) values (1, 5)
5 select * from dual;
3 rows created.
SQL> select * from product;
PRODUCT_ID PRICE
---------- ----------
1 100
2 200
SQL> select * from bill;
PRODUCT_ID QUANTITY TOTAL_PRICE
---------- ---------- -----------
1 5
SQL> commit;
Commit complete.
total_price
列值,可以使用
UPDATE
SQL> update bill b set
2 b.total_price = (select b.quantity * p.price
3 from product p
4 where p.product_id = b.product_id
5 );
1 row updated.
SQL> select * From bill;
PRODUCT_ID QUANTITY TOTAL_PRICE
---------- ---------- -----------
1 5 500
SQL> rollback;
Rollback complete.
或
MERGE
:
SQL> merge into bill b
2 using (select p.product_id, p.price
3 from product p
4 ) x
5 on (b.product_id = x.product_id)
6 when matched then update set b.total_price = b.quantity * x.price;
1 row merged.
SQL> select * From bill;
PRODUCT_ID QUANTITY TOTAL_PRICE
---------- ---------- -----------
1 5 500
当你用一个顶点标记这个问题时,你实际上拥有什么还不清楚。这是什么样的一页?如果它是一个报表(经典的或交互式的),您可以在
product_id
SQL> select b.product_id, b.quantity, p.price, b.quantity * p.price as total_price
2 from product p join bill b on b.product_id = p.product_id;
PRODUCT_ID QUANTITY PRICE TOTAL_PRICE
---------- ---------- ---------- -----------
1 5 100 500
如果是表单页,则使用动态操作
设置值
P1_PRICE
和/或
P1_QUANTITY
P1_TOTAL_PRICE
:P1_PRICE * :P1_QUANTITY
基本上,有很多选择。你要用的那个取决于你真正拥有什么。