简体   繁体   中英

Oracle SQL Developer - Error message does not appear

CREATE OR REPLACE FUNCTION func_totalStaffOrders( v_staffID IN INTEGER) RETURN VARCHAR AS v_totalOrders NUMBER; MESSAGE VARCHAR2(100); AS v_totalOrders NUMBER; MESSAGE VARCHAR2(100); BEGIN IF v_staffID IS NOT NULL THEN SELECT COUNT(order_id) INTO v_totalOrders FROM orders WHERE staff_ID = v_staffID; MESSAGE := 'Staff with the ID ' || v_staffID ||' has took an overall of ' || v_totalOrders || ' order/s.'; RETURN MESSAGE; ELSE MESSAGE:='Null values are not allowed.'; RETURN MESSAGE; END IF; EXCEPTION WHEN NO_DATA_FOUND THEN MESSAGE := 'Invalid staff ID entered.'; RETURN MESSAGE; WHEN OTHERS THEN MESSAGE := 'Error! ' || SQLERRM; RETURN MESSAGE; END;

This function counts the total number of orders made by a single staff member. It takes in a staff ID and returns the total number of orders. If I enter a staff ID that is not in the system, it does not show the exception message. Can anyone, help me please?

Your query is always going to return a value. If there are no matches, then the count will be 0, so v_totalorders will be zero.

No exception is generated. You want explicit if logic on v_totalorders .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM