【问题标题】:Stored procedure & trigger compiles but no data found error存储过程和触发器编译但未找到数据错误
【发布时间】:2018-09-14 16:26:43
【问题描述】:

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

--ERROR MESSAGE 错误从命令中的第 1,243 行开始:EXECUTE p_update_cust_fuzzy_perform_mv 错误报告:ORA-01403:未找到数据 ORA-01403: 未找到数据 ORA-06512: 在 “FUZZYTEST1.T_CUST_FUZZY_PERFORMANCE_MV”,第 23 行 ORA-04088:错误 在执行触发器“FUZZYTEST1.T_CUST_FUZZY_PERFORMANCE_MV”期间 ORA-06512:在“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;
/

【问题讨论】:

  • 它说“没有找到数据”;复制您的选择语句并单独运行它。如果您看到返回的行,那么这是一个问题;如果没有行,那么这不是问题。可能您的查询不正确。
  • 因为错误提示应该有查询没有返回任何内容,因此您必须先检查所有选择语句。

标签: sql oracle stored-procedures triggers


【解决方案1】:

您所做的就像加入 2 个表,而您的代码中缺少的是这样的 where 子句

where t1.col = t2.col

你也可以像这样使用 join 来做到这一点

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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-24
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-23
    • 2016-03-21
    相关资源
    最近更新 更多