--功能说明:当宾馆插入数据,或修改宾馆名称时,触发器自动生成宾馆名称的拼音名称.
--但现在此功能不功作,不知是否NEW.HOTEL_NO 这里有问题呢.create or replace trigger TRG_TEST_HOTEL_PINYIN
after insert or update on TEST_HOTEL for each row
begin
     if inserting then
       update TEST_HOTEL  set n_hotel_pinyin=get_pinyin(:new.hotel_name)
       where hotel_no= :new.hotel_no;
       commit;
    else -- if updating
       update TEST_HOTEL set n_hotel_pinyin=get_pinyin(:new.hotel_name)
       where hotel_no= :old.hotel_no;
       commit;
    end if;
exception
when others then
   htp.print('error='||SQLERRM);
end;

解决方案 »

  1.   

    在处罚期里不能对正在操作的标在进行select等操作了。
    create or replace trigger TRG_TEST_HOTEL_PINYIN 
    before insert or update 
    REFERENCING OLD AS OLD NEW AS NEW
    on TEST_HOTEL for each row 
    begin 
        :new.n_hotel_pinyin=get_pinyin(:new.hotel_name);
    exception 
    when others then 
       htp.print('error=' ¦ ¦SQLERRM); 
    end; 
      

  2.   

    记得在TEST_HOTEL的trigger里不能对TEST_HOTEL本身进行操作吧
      

  3.   

    [doer_ljy] 兄的代码有些问题,
    'REFERENCING OLD AS OLD NEW AS NEW ' 这句代码已去掉了.修改如下:测试通过.
    create or replace trigger TRG_TEST_HOTEL_PINYIN
    BEFORE  insert or update
     on TEST_HOTEL for each row
    begin
     :new.n_hotel_pinyin:=get_pinyin(:new.hotel_name); 
    exception
    when others then
       htp.print('error='||SQLERRM);
    end;