从程序调用功能

时间:2018-11-23 13:44:57

标签: sql oracle stored-procedures

我正在尝试创建一个PL / SQL过程,该过程将调用一个我已经运行的名为GET_HIGHORDER_FUNC的函数:

create or replace FUNCTION GET_HIGHORDER_FUNC
  return number
AS
  c_hiorder number;
BEGIN 
  select max(sum(product.product_standardprice * orderline.ordered_quantity)) into c_hiorder
    from customer, product, orderline, orders
    where customer.customer_id = orders.customer_id 
    and orders.order_id = orderline.order_id
    and orderline.product_id = product.product_id 
    group by customer_name;
  RETURN c_hiorder;
END GET_HIGHORDER_FUNC;

create or replace procedure PRINT_CUST_PROC(
    p_hiordername in number)
as 

begin
 /* This procedure should show the name of the customer who have the highest
    amount of order which will be available upon invoking the function above */
end;

1 个答案:

答案 0 :(得分:0)

就像使用任何函数一样调用它吗?

这是根据您的最新评论尝试的方式

create or replace FUNCTION GET_HIGHORDER_FUNC(c_customer_name out varchar2,c_hiorder out int)
  return number
AS
  c_hiorder number;
BEGIN 
select y.customer_name
      ,y.summed_price
 into customer_name
     ,c_hiorder 
 from (
         select x.customer_name
               ,x.summed_price
               ,row_number() over(order by x.summed_price desc) as rnk
        from (     
          select customer_name
                 ,sum(product.product_standardprice * orderline.ordered_quantity) as summed_price
            from customer, product, orderline, orders
            where customer.customer_id = orders.customer_id 
            and orders.order_id = orderline.order_id
            and orderline.product_id = product.product_id 
         group by customer_name    
             )x
      )y
where y.rnk=1;

  RETURN 1;
END GET_HIGHORDER_FUNC;

create or replace procedure PRINT_CUST_PROC(
    p_hiordername in number)
as 
l_return int;
l_customer_name varchar2(1000);
l_hiorder int;
begin
 /* This procedure should show the name of the customer who have the highest
    amount of order which will be available upon invoking the function above 
    */
l_return : = GET_HIGHORDER_FUNC(l_customer_name,l_hiorder);
dbms_output.put_line(l_customer_name);
dbms_output.put_line(l_hiorder);
end;