1

面临以下错误:

[Error] PLS-00049 (12: 11): PLS-00049: bad bind variable 'NEW.OPTION_D'

我正在尝试执行以下操作:

create or replace trigger check_option_for_stage
before insert on lot_option
for each row
when (new.stage_id > 0 and new.option_id > 0)
declare 
not_existing_option exception;
num_count number;
begin
    select count(*) into num_count 
    from option_cost os
    where :new.option_id = os.option_id and :new.stage_id = os.stage_id;
    if num_count = 1 then
        DBMS_OUTPUT.PUT_LINE('The option can be applied to the lot at the current stage');
    ELSE
        raise not_existing_option;    
    end if;
exception
    when not_existing_option then
        DBMS_OUTPUT.PUT_LINE('The option is not available on this stage, therefore rejected');
    when others then
        DBMS_OUTPUT.PUT_LINE('Oops!, something went wrong, it needs your attention!');
end;
/

我为什么要面对这个?为什么它是一个糟糕的绑定变量?我知道我应该能够通过键入来访问新值:new.whateverthecolumnname

我正在使用 Oracle 11g。

我正在玩的桌子的定义

SQL> desc option_cost
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 COST                                      NOT NULL NUMBER
 OPTION_ID                                 NOT NULL NUMBER(38)
 STAGE_ID                                  NOT NULL NUMBER(38)

SQL> desc lot_option;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 LOT_ID                                    NOT NULL NUMBER(38)
 OPTION_ID                                 NOT NULL NUMBER(38)
 COST                                      NOT NULL NUMBER
 DATE_CREATED                                       DATE
 STAGE_ID                                  NOT NULL NUMBER(38)
4

1 回答 1

3

是列option_idid末尾有一个)还是只是option_d(没有i)? option_id似乎更有意义。假设option_id是正确的,您的SELECT陈述中有一个错字,您缺少iin id。你想要类似的东西

select count(*) 
  into count 
  from option_cost oc
 where :new.option_id = oc.option_id 
   and :new.stage_id = oc.stage_id;

当然,既然count是保留字,那么声明一个名为 的局部变量并不是一个好主意countl_count例如,命名该变量或使用其他命名约定来标识局部变量并避免使用保留字会更有意义。

于 2012-11-26T21:50:43.827 回答