1. 程式人生 > 其它 >第一個HelloWorld.java編寫

第一個HelloWorld.java編寫

技術標籤:oracle

關於oracle11g建立表自增主鍵觸發器ora-04098:觸發器無效且未通過重新驗證問題

在plsql中:假如在網上直接ctrl c+ctrl v 到plsql中的sql視窗中會出現ora-04098:觸發器無效且未通過重新驗證問題,需要手敲一遍,千萬不能複製貼上直接用,可能建立的trigger不被識別會出現以下的問題:

在這裡插入圖片描述
並且
在這裡插入圖片描述
小紅叉
手敲的不會出現紅叉
在這裡插入圖片描述

示例:::

 --建立表
 create table Employee(
   id  number(6) primary key,
   salary number(10));
  

 --建立sequence:
 --觸發器從1開始
 --步長為1:就是每插入一條資料id+1
 create sequence employee_id_sequence
 start with 1
 increment by 1
 nomaxvalue
 nocache;

--建立觸發器:
 create or replace trigger Emp_id_autoincrement before 
 insert on Employee for each row
 when (new.id is null)
 begin 
 select employee_id_sequence.nextval into :new.id from dual;
 end;

 
`` 

不用序列、觸發器插入資料:

insert all
 into Employee(id,salary) values(2,400)
  into Employee(id,salary) values(3,200)
   into Employee(id,salary) values(4,300)
select * from dual;

應用觸發器後插入資料

insert into Employee(salary) values(500);

不應用觸發器直接應用序列插入資料

 insert into Employee(id,salary) values(employee_id_sequence.NEXTVAL,1100);