存储过程&触发编译但没有发现数据错误

时间:2018-04-05 00:24:58

标签: sql oracle stored-procedures triggers

我已成功运行以下过程和触发器,但是当我运行整个脚本时,我收到错误消息,后跟代码。请帮助我理解我在这里收到的错误消息。我看到桌子上的数据,但它没有抓住?

  

- ERROR MESSAGE在命令的第1,243行开始出错:EXECUTE p_update_cust_fuzzy_perform_mv错误报告:ORA-01403:未找到数据   ORA-01403:未找到数据ORA-06512:at   " FUZZYTEST1.T_CUST_FUZZY_PERFORMANCE_MV",第23行ORA-04088:错误   在执行触发器期间' FUZZYTEST1.T_CUST_FUZZY_PERFORMANCE_MV'   ORA-06512:at" FUZZYTEST1.P_UPDATE_CUST_FUZZY_PERFORM_MV",第30行   ORA-06512:第1行   01403. 00000 - "未找到数据"

*原因:
*操作:

CREATE or REPLACE 
PROCEDURE p_update_cust_fuzzy_perform_mv is

v_customer_no wt_net.customer_no%type;
v_lname  wt_net.lname%type;
v_fname wt_net.fname%type;
v_report_date date;
v_mem_set int;
v_fuzzy_status int;

CURSOR performance_cur is
select t1.customer_no,t1.lname,t1.fname, sysdate,t2.mem_set, t2.status
FROM 
(
SELECT customer_no, lname, fname, sysdate
FROM wt_net)t1,
(
select DISTINCT MEM_SET as mem_set, status
from fuzzy_param_triangle
where status=1)t2;



BEGIN
OPEN performance_cur;

LOOP
    FETCH performance_cur into v_customer_no,  v_lname, v_fname, v_report_date, v_mem_set, v_fuzzy_status;
    EXIT when performance_cur%notfound;
    IF v_fuzzy_status =1 THEN
INSERT INTO CUST_FUZZY_PERFORMANCE_mv (customer_no, lname, fname, report_date, mem_set) VALUES(v_customer_no, v_lname, v_fname, v_report_date, v_mem_set);
END IF;
END LOOP;
CLOSE performance_cur;
END;
/

--drop trigger t_CUST_FUZZY_PERFORMANCE_mv;
CREATE OR REPLACE TRIGGER t_CUST_FUZZY_PERFORMANCE_mv 
BEFORE INSERT ON CUST_FUZZY_PERFORMANCE_mv
FOR EACH ROW
--This trigger will update the emp_fuzzy_performance and 
--emp_fuzzy_performance_weight  tables when an insert is made on the 
--emp_fuzzy_performance_mv materialized view.


DECLARE

v_s_customer_no cust_fuzzy_TOTAL_TIME.customer_no%type;
v_s_excellent cust_fuzzy_TOTAL_TIME.excellent%type;
v_s_average cust_fuzzy_TOTAL_TIME.average%type;
v_s_POOR cust_fuzzy_TOTAL_TIME.POOR%type;
v_s_mem_set cust_fuzzy_TOTAL_TIME.mem_set%type;

v_o_excellent cust_fuzzy_NUM_OF_FOLLOWUP.excellent%type;
v_o_average cust_fuzzy_NUM_OF_FOLLOWUP.average%type;
v_o_POOR cust_fuzzy_NUM_OF_FOLLOWUP.POOR%type;


count_rec int;

BEGIN


select count (*) into count_rec from fuzzy_param_trapezoid where MEM_SET = (:new.mem_set);
if(count_rec = 0) then


SELECT DISTINCT s.customer_no, s.POOR, s.average, s.excellent, s.mem_set, o.POOR, o.average, o.excellent

INTO v_s_customer_no, v_s_POOR, v_s_average, v_s_excellent, v_s_mem_set, v_o_POOR, v_o_average, v_o_excellent


FROM cust_fuzzy_TOTAL_TIME s, cust_fuzzy_NUM_OF_FOLLOWUP o
WHERE s.customer_no = o.customer_no

AND s.customer_no = :new.customer_no
AND s.mem_set = o.mem_set

AND s.mem_set = :new.mem_set;   


--update fuzzy fields in emp_fuzzy_performance_mv
--if there is an overlap in values, the highest rating will be used.  
--for example if the employee has a value in both average and below average, average will be
 --used. 
:new.NUM_OF_FOLLOWUP := case 
when v_o_excellent >0 then 'EXCELLENT'
when v_o_average > 0 then 'AVG'
when  v_o_POOR > 0 then 'POOR'  
end;


:new.TOTAL_TIME := case 
when v_s_excellent >0 then 'EXCELLENT'
when v_s_average > 0 then 'AVG'
when  v_s_POOR > 0 then 'POOR'  
end;

INSERT INTO CUST_FUZZY_PERFORMANCE values(:new.customer_no, v_s_mem_set, :new.lname, :new.fname, :new.report_date, 
case 
when v_o_excellent >0 then 'EXCELLENT'
when v_o_average > 0 then 'AVG'
when  v_o_POOR > 0 then 'POOR'  
end,


case 
when v_s_excellent >0 then 'EXCELLENT'
when v_s_average > 0 then 'AVG'
when  v_s_POOR > 0 then 'POOR'  
end);

INSERT INTO CUST_FUZZY_PERFORMANCE_weight values(:new.customer_no,v_s_mem_set, :new.lname, :new.fname, :new.report_date, 
case 
when v_o_excellent >0 then 'EXCELLENT'
when v_o_average > 0 then 'AVG'
when  v_o_POOR > 0 then 'POOR'  
end,

case 
when v_o_excellent >0 then v_o_excellent
when v_o_average > 0 then v_o_average 
when  v_o_POOR > 0 then v_o_POOR  
end,


case 
when v_s_excellent >0 then 'EXCELLENT'
when v_s_average > 0 then 'AVG'
when  v_s_POOR > 0 then 'POOR'  
end,

case 
when v_s_excellent >0 then v_s_excellent 
when v_s_average > 0 then v_s_average 
when  v_s_POOR > 0 then v_s_POOR
 end);

END IF;

END;
/

1 个答案:

答案 0 :(得分:0)

你在做什么就像加入2个表,你的代码中缺少什么是这样的where子句

where t1.col = t2.col

你也可以使用像这样的连接

来做到这一点
select t1.customer_no, t1.lname, t1.fname, sysdate, t2.mem_set, t2.status
FROM 
(SELECT customer_no, lname, fname, sysdate
FROM wt_net) t1
JOIN
(select DISTINCT MEM_SET as mem_set, status
from fuzzy_param_triangle
where status=1) t2
ON t1.col = t2.col;