Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Function return value from CTE table

User_Z48MRMar 21 2022
create or replace function f_vsota_artiklov (par_warehouse_id in tbl_warehouses.warehouse_id%type)
       return temp.total%type
is
       retval temp.total%type;
begin
   with temp as
    (select t3.warehouse_id, sum(t1.quantity*t1.unit_price) total from tbl_order_items t1
    join tbl_products t2 on t1.product_id = t2.product_id
    join tbl_inventories t3 on t2.product_id = t3.product_id
    group by t3.warehouse_id
    order by t3.warehouse_id)
          
    select temp.total
    into retval
    from temp
    where t3.warehouse_id = par_warehouse_id
    return retval;  
end;
/

I have the following code, the temp table returns:
r11.PNGHowever, I'm not sure why is not returning temp.total or did I define return/retval wrong?
I'm trying to return total based on warehouse_id input

Comments
Post Details
Added on Mar 21 2022
4 comments
624 views