【发布时间】:2016-04-12 03:52:27
【问题描述】:
我在 oracle 中有一个包,其中包含几个程序,在其中一个程序中,我需要根据特定条件计算一些费用,如下所示:
if X_flag = 1
then
fee = (.5 * orders.total_count) + (.3 * orders.total_amount)
else
fee = (.7 * orders.total_count) + (.4 * orders.total_amount)
那么,有什么更好的方法呢?
我需要在其上添加此计算的过程:
procedure informatonRPT (
p_customerID in number,
p_orderID in number)
as
begin
select
cusromers.costomerId,
cusromers.costomerName,
cusromers.coustomerPhone,
orders.price
from cusromers
inner join orders
on cusromers.orderId = orders.orderID
when
p_customerID is null or p_customerID = cusromers.costomerId
and p_orderID is null or p_orderID = orders.orderID ;
end informatonRPT;
客户表列:
- 客户ID
- 客户姓名
- 客户电话
- 有序ID
订单表列:
- 订单号
- 价格
- total_Amount
- total_count
请注意: 数据库中不存在费用列,我必须在查询中计算它
【问题讨论】:
-
我认为您需要添加更多信息,因为首先您会说
X_flagfee、table和table_count但您的程序没有这些信息。那么这些字段定义在哪里呢? -
你在哪里得到
X_flag? -
来自数据库中的另一个表,我在该过程中没有使用它
-
你检查我的答案了吗?
-
我必须在同一过程中将其添加为子查询吗?还是作为包中的单独函数?
标签: oracle stored-procedures package conditional