我有这个代码。 :P99_CAR,:P99_PARTS是列表你可以选择一个ID(通过查找表),:P99_AMOUNT是我表单中的一个简单输入。因此,您选择这3个部分并想要检查以下代码。因此,如果PART_ID为5,且CAR_ID为3且我从列表中选择相同的数字,则ERROR即将到来,我不知道原因。
DECLARE
--Varchar(100) or Number
l_car Varchar(100);
l_part Varchar(100);
BEGIN
SELECT CAR_ID, PART_ID INTO l_car, l_part FROM CAR_PARTS WHERE CAR_ID = :P99_CAR AND PARTS_ID = :P99_PARTS;
IF l_car IS NULL OR l_parts IS NULL THEN
INSERT INTO CAR_PARTS (CAR_ID, PARTS_ID, CUR_AMOUNT) VALUES (:P99_CAR, :P99_PARTS, :P99_AMOUNT);
ELSE
UPDATE CAR_PARTS
SET CAR_ID = :P99_CAR,
PARTS_ID = :P99_PARTS,
CUR_AMOUNT = CUR_AMOUNT + :P99_AMOUNT
WHERE CAR_ID = :P99_CAR AND PARTS_ID = :P99_PARTS;
END IF;
END;
但是我在处理时收到ORA-01403错误,并在提交时
Ajax调用返回服务器错误ORA-01403:未找到Execute数据 PL / SQL代码。
我知道我需要插入一个带有ERROR的Exception,但为什么它会出现呢?
答案 0 :(得分:1)
您的SELECT
语句未返回任何行。由于这适用于不同的环境,因此绑定变量不是您认为的那样。您应该在此过程中添加对apex_debug.message
的调用,然后检查调试日志中的值。
但是,我会用一个合并语句替换整个过程:
MERGE INTO car_parts cp
USING ( SELECT :P99_CAR_ID AS car_id, :P99_PARTS ID AS parts_id,
:P99_CUR_AMOUNT AS cur_amount ) src
ON ( cp.car_id = src.car_id AND cp.parts_id = src.parts_id )
WHEN NOT MATCHED THEN INSERT ( car_id, parts_id, cur_amount )
VALUES ( src.car_id, src.parts_id, src.cur_amount )
WHEN MATCED THEN UPDATE SET cur_amount = src.cur_amount
答案 1 :(得分:0)
以下查询似乎不会返回任何行:
SELECT CAR_ID, PART_ID INTO l_car, l_part FROM CAR_PARTS WHERE CAR_ID = :P99_CAR AND PARTS_ID = :P99_PARTS;
尝试将其包装在BEGIN END块中并处理异常:
BEGIN
SELECT CAR_ID, PART_ID
INTO l_car, l_part
FROM CAR_PARTS
WHERE CAR_ID = :P99_CAR AND PARTS_ID = :P99_PARTS;
EXCEPTION WHEN NO_DATA_FOUND THEN
-- Handle error here
END;