2016-11-07 113 views
1

现在,为了完全透明,这是作业。第一部分是创建一个存储函数来计算物品的折扣价格。它接受项目ID的一个参数并返回折扣价格的值。函数名称是discount_price。这我已经完成,它工作正常。如何在功能中使用功能

接下来的部分是:“5.编写一个脚本,创建并调用名为item_total的存储函数,该函数计算Order_Items表中的项目总量(折扣价格乘以数量)。为此,此函数应该接受物品ID的一个参数,它应该使用您在练习2中创建的discount_price函数,并且应该返回该物品的总价值。“

我的问题是,我如何将一个函数的值传递给另一个?我只需要基本的语法。我的教科书不包含任何示例,我无法在任何地方找到明确的答案。

+0

这是什么语言,sql? –

+0

它在oracle pl/sql中 – Itsonlyme

回答

1

Believe this link有你正在寻找的例子。 基本上你会这么称呼它,就像你通常在sql-plus或sql-developer中调用它。

例如:

returl_val := SUBSTR(string_in,4,1);

4

您可以在一个函数中恰好在你从一个语句或查询调用它以同样的方式调用一个函数;例如:

create function innerFunction(a number) return number is 
begin 
    return a * 2; 
end; 

create function outerFunction(a number) return number is 
begin 
    return innerFunction(a) * 3; 
end; 

create function calledFunction(a number) return number is 
    n number; 
begin 
    n := outerFunction(a) * 5; 
    return n; 
end; 

SQL> select calledFunction(1) from dual; 

CALLEDFUNCTION(1) 
----------------- 
       30 

SQL> select calledFunction(calledFunction(calledFunction(1))) from dual; 

CALLEDFUNCTION(CALLEDFUNCTION(CALLEDFUNCTION(1))) 
------------------------------------------------- 
              27000 


SQL> declare 
    2 x number; 
    3 begin 
    4 x := calledFunction(1); 
    5 dbms_output.put_line(x); 
    6 end; 
    7/
30