SQL command not properly ended 错误数据库oracle

SQL command not properly ended errror database oracle

我有一个添加数据的请求,该数据会触发检查一个条件的触发器,并且仅在此之后才将其添加到购买中 table。他还对初始化行 total_rasr 和 id_buyer 无效数字发誓,尽管 table 和触发器中的类型相同。最大的问题是,这个触发器有效,但在某一时刻它停止并给出了这些错误。

INSERT INTO PAYMENT (ID, ADDRESS, DATE_PAYMENT, PAYMENT_METHOD_ID, EMPLOYEE_ID, BUYER_ID) 
VALUES (Key('PAYMENT'), 'Moscow', TO_DATE('2002-08-23', 'YYYY-MM-DD'),'005!00002','1','002!00005');

触发器

create or replace TRIGGER checking_the_availability_work
    BEFORE INSERT
    ON PAYMENT
    FOR EACH ROW
    
DECLARE
    rasr_is_possible boolean := true;
    total_rasr VARCHAR(10);
    id_buyer VARCHAR(10);
    AVAILABILITY_OF_WORK VARCHAR(5);
    xSQL VARCHAR(100);
BEGIN
    total_rasr := :NEW.PAYMENT_METHOD_ID;
    id_buyer := :NEW.BUYER_ID;

    IF total_rasr = '005!00002' THEN
            xSQL := 'select AVAILABILITY_OF_WORK FROM BUYER WHERE ID =' || id_buyer;
            execute immediate xSQL into AVAILABILITY_OF_WORK;
                    IF AVAILABILITY_OF_WORK = 'Нет' THEN
                         rasr_is_possible := false;
                    END IF;
     END IF;

    if not rasr_is_possible THEN
        Raise_application_error(-20201, 'У вас нет места работы!');
    end if;
END;

为什么要在这里使用动态 SQL?它看起来真的很复杂并且会导致错误,也许当 :new.buyer_id 为 null 或具有其他一些意外值时?尝试这样的事情,也许考虑检查 :new.buyer_id 以确保它具有预期的值。

DECLARE
    L_AVAILABILITY_OF_WORK VARCHAR(5);
BEGIN
    IF :NEW.PAYMENT_METHOD_ID = '005!00002' THEN
        select AVAILABILITY_OF_WORK into L_AVAILABILITY_OF_WORK 
            FROM BUYER WHERE ID = :NEW.BUYER_ID;

        IF L_AVAILABILITY_OF_WORK = 'Нет' THEN
            Raise_application_error(-20201, 'У вас нет места работы!');
        END IF;
    END IF;
END;