create or replace function money_of_order1 return number is total_money number :=0; begin for row in (select food_number,food_price_initial from view_oder_1) loop total_money:=(row.food_number*row.food_price_initial)+total_money; end loop; return total_money; end; / DECLARE sit_number NUMBER := 1; money NUMBER := 0; BEGIN FOR row IN (SELECT sit_where, money_of_order1 FROM view_oder WHERE sit_where = sit_number) LOOP SELECT row.money_of_order1 INTO money FROM dual; UPDATE m_oder SET oder_money = money WHERE sit_where = row.sit_where; sit_number := sit_number + 1; END LOOP; END; /
时间: 2024-04-26 17:20:21 浏览: 187
根据您提供的代码,您似乎是在尝试将两个不同的代码块组合成一个程序。第一个代码块是一个函数,它计算视图`view_oder_1`中所有行的订单金额,并返回该金额。第二个代码块是一个PL/SQL块,它更新表`m_oder`中与视图`view_oder`中`sit_where`等于`sit_number`的行相关的订单金额。这种组合是可行的,但您需要确保视图`view_oder_1`已经存在并且包含正确的数据。否则,函数将计算不正确的金额,可能导致更新到`m_oder`表的数据也不正确。因此,建议您在运行第二个代码块之前确保视图`view_oder_1`已经存在并且包含正确的数据。
相关问题
CREATE OR REPLACE FUNCTION money_of_order1 (p_sit_where IN NUMBER) RETURN NUMBER IS total_money NUMBER := 0; BEGIN FOR row IN (SELECT food_number, food_price_initial FROM view_oder WHERE sit_where = p_sit_where) LOOP total_money := (row.food_number * row.food_price_initial) + total_money; END LOOP; RETURN total_money; END; / CREATE OR REPLACE procedure s_money(sit_where in number) is sit_number NUMBER := 1; money NUMBER := 0; BEGIN FOR row IN (SELECT sit_where FROM view_oder WHERE sit_where = sit_number) LOOP money := money_of_order1(row.sit_where); UPDATE m_oder SET oder_money = money WHERE sit_where = row.sit_where; sit_number := sit_number + 1; END LOOP; END; / declare begin for row in (select sit_where from m_oder) loop s_money(row.sit_where); end loop; end; /
这段代码是什么意思?
这段代码是一个 Oracle 数据库中的存储过程和函数,用于计算餐厅点餐的总金额。其中,函数 money_of_order1 用于计算某个桌位点餐的总金额,而存储过程 s_money 则用于遍历所有桌位并更新订单表中对应桌位的总金额。最后的 declare begin/end 则是用于调用 s_money 存储过程的代码。
阅读全文