Oracle Apex中的计算有问题吗?

时间:2019-01-11 14:28:01

标签: oracle-apex calculation

我有两个表:账单和产品。表产品中有产品的属性价格,表帐单中有数量和总价格的属性。因此,我需要通过乘以产品中的属性价格和账单中的数量来计算属性总价格。有人知道怎么做吗?

1 个答案:

答案 0 :(得分:1)

我以某种方式怀疑那些表仅包含您提到的列。他们两个都缺乏某种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

当您使用Apex标签标记问题时,尚不清楚您实际拥有什么。这是什么样的页面?如果它是报告(经典报告或交互式报告)之一,则您可以将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时使用动态操作设置值;假设它是第1页,那么您将P1_TOTAL_PRICE设置为

:P1_PRICE * :P1_QUANTITY

基本上,有很多选择。您将要使用的取决于您实际拥有的东西。