1 create or replace function mca_detail_material_val(p_material_code VARCHAR2, --实参 2 p_material_name VARCHAR2, 3 p_mca_no VARCHAR2 4 ) 5 RETURN varchar2 AS 6 7 --物料编码/名称的验证,数据表(MATERIAL)中 不存在 该物料编码/名称,允许通过,填其他值都不允许通过 8 9 v_count1 NUMBER; -- 形参 10 v_count2 NUMBER; 11 v_count3 NUMBER; 12 v_count4 NUMBER; 13 14 CURSOR get_wl_material_code1 IS 15 SELECT count(m.material_code) -- count()函数:查询出来的记录条数(记录数) 16 FROM MATERIAL m 17 WHERE m.material_code = p_material_code; 18 19 CURSOR get_wl_material_code2 IS 20 SELECT count(material_code) 21 FROM mca_detail m 22 WHERE m.material_code = p_material_code AND m.mca_no <> p_mca_no; 23 -- m.mca_no <> p_mca_no:在编辑时,排除此单号(不做比较)---物料编码 24 CURSOR get_wl_material_name1 IS 25 SELECT count(m.material_name) 26 FROM MATERIAL m 27 WHERE m.material_name = p_material_name; 28 29 CURSOR get_wl_material_name2 IS 30 SELECT count(m.material_name) 31 FROM mca_detail m 32 WHERE m.material_name = p_material_name AND m.mca_no <> p_mca_no; 33 BEGIN -- m.mca_no <> p_mca_no:在编辑时,排除此单号(不做比较)---物料名称 34 OPEN get_wl_material_code1; 35 FETCH get_wl_material_code1 INTO v_count1; 36 CLOSE get_wl_material_code1; 37 38 OPEN get_wl_material_code2; 39 FETCH get_wl_material_code2 INTO v_count3; 40 CLOSE get_wl_material_code2; 41 42 OPEN get_wl_material_name1; 43 FETCH get_wl_material_name1 INTO v_count2; 44 CLOSE get_wl_material_name1; 45 46 OPEN get_wl_material_name2; 47 FETCH get_wl_material_name2 INTO v_count4; 48 CLOSE get_wl_material_name2; 49 50 IF v_count1+v_count3 <> 0 THEN 51 RETURN ‘4823272‘; -- 错误信息码(信息码表),物料编码已存在,不允许出现相同值! 52 ELSIF v_count2+v_count4 <> 0 THEN 53 RETURN ‘4823273‘; -- 错误信息码(信息码表),物料名称已存在,不允许出现相同值! 54 END IF; 55 56 RETURN ‘0‘; 57 58 end mca_detail_material_val;
时间: 2024-11-06 20:50:09