I am using three tables for this, customer table, orders table and orderline table. When a user enters a orderid, the program should display the total order for a certain orderid. how can i use the SUM function in such a way that i can store the total order cost(price of orders) in a variable and display it in the ouput line function?? SET SERVEROUTPUT ON; DECLARE v_odNum NUMBER(8):= &sv_orderNum; v_price NUMBER(7,2); v_quantity NUMBER(5); v_fname VARCHAR2(30); v_lname VARCHAR2(30); v_add VARCHAR2(30); BEGIN SELECT first, last, cadd, order_price, quantity, SUM(order_price * quantity) AS TOTAL INTO v_fname, v_lname, v_add, v_price, v_quantity FROM customer c, orders o, orderline ordl WHERE c.custid = o.custid AND o.orderid = ordl.orderid AND v_odNum = o.orderid DBMS_OUTPUT.PUT_LINE('The total order for' ||v_odNum|| ' '|| 'is' || TOTAL); END; / Code (markup): If you like to see how the tables look tell me please.
SELECT first, last, cadd, order_price, quantity, SUM(order_price * quantity) AS TOTAL INTO v_fname, v_lname, v_add, v_price, v_quantity, v_total FROM customer c, orders o, orderline ordl WHERE c.custid = o.custid AND o.orderid = ordl.orderid AND v_odNum = o.orderid group by first, last, cadd, order_price, quantity