如果表1中的记录数超过300条记录,请告诉我如何使Oracle存储过程失败?
我应该使用自定义异常处理吗?
答案 0 :(得分:0)
CREATE OR REPLACE PROCEDURE test
IS
D_count_exceeded EXCEPTION;
D_Count NUMBER;
BEGIN
SELECT COUNT (*) INTO d_count FROM your_table;
IF D_count > 300 THEN
RAISE D_Count_Exceeded;
END IF;
END;
答案 1 :(得分:0)
使用引发异常的触发器:
CREATE OR REPLACE TRIGGER TOO_MANY_RECS_TRIGGER
BEFORE INSERT ON SOME_TABLE
-- Note: *not* FOR EACH ROW
DECLARE
nCount NUMBER;
BEGIN
SELECT COUNT(*)
INTO nCount
FROM SOME_TABLE;
IF nCount >= 300 THEN
RAISE_APPLICATION_ERROR(-20001, 'Too many records (' || nCount ||
') found in SOME_TABLE');
END IF;
END TOO_MANY_RECS_TRIGGER;
分享并享受。