Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle ORA-01403:在businesshr触发器中未找到数据错误_Oracle_Sqlplus - Fatal编程技术网

Oracle ORA-01403:在businesshr触发器中未找到数据错误

Oracle ORA-01403:在businesshr触发器中未找到数据错误,oracle,sqlplus,Oracle,Sqlplus,我正在尝试在以下表上触发oracle sqlplus SQL> create table Employees1727 2 ( 3 emp_id number(4) primary key, 4 last_name varchar2(15), 5 first_name varchar2(15), 6 email varchar2(30), 7 phone_no varchar2(12), 8 hire_date date, 9 job_id v

我正在尝试在以下表上触发oracle sqlplus

SQL> create table Employees1727
  2  (
  3  emp_id number(4) primary key,
  4  last_name varchar2(15),
  5  first_name varchar2(15),
  6  email varchar2(30),
  7  phone_no varchar2(12),
  8  hire_date date,
  9  job_id varchar2(10), 
 10  salary number(10),
 11  commission_pct number(2,2),
 12  manager_id number(4) references Employees1727(emp_id), 
 13  dept_id number(3)
 14  );
表已创建

SQL> 
SQL> 
SQL> create table Departments1727
  2  (
  3  dept_id number(4),
  4  dept_name varchar2(15),
  5  manager_id number(4) references Employees1727(emp_id), 
  6  loc_id number(4)
  7  );
SQL> create or replace trigger businesshr
  2  before insert or update or delete on Employees1727
  3  for each row
  4  begin
  5  if to_char(sysdate, 'hh24') >= '05' AND
  6     to_char(sysdate, 'hh24') <= '18'
  7  then
  8  select * into 
  9  :new.emp_id,
 10  :new.last_name,
 11  :new.first_name,
 12  :new.email,
 13  :new.phone_no,
 14  :new.hire_date,
 15  :new.job_id, 
 16  :new.salary,
 17  :new.commission_pct,
 18  :new.manager_id, 
 19  :new.dept_id
 20  from Employees1727 ;
 21  else
 22  raise_application_error (-20000, 'Employee info may not be modified at this time!') ;
 23  end if;
 24  end businesshr;
 25  /
表已创建

SQL> 
SQL> 
SQL> create table Departments1727
  2  (
  3  dept_id number(4),
  4  dept_name varchar2(15),
  5  manager_id number(4) references Employees1727(emp_id), 
  6  loc_id number(4)
  7  );
SQL> create or replace trigger businesshr
  2  before insert or update or delete on Employees1727
  3  for each row
  4  begin
  5  if to_char(sysdate, 'hh24') >= '05' AND
  6     to_char(sysdate, 'hh24') <= '18'
  7  then
  8  select * into 
  9  :new.emp_id,
 10  :new.last_name,
 11  :new.first_name,
 12  :new.email,
 13  :new.phone_no,
 14  :new.hire_date,
 15  :new.job_id, 
 16  :new.salary,
 17  :new.commission_pct,
 18  :new.manager_id, 
 19  :new.dept_id
 20  from Employees1727 ;
 21  else
 22  raise_application_error (-20000, 'Employee info may not be modified at this time!') ;
 23  end if;
 24  end businesshr;
 25  /
第1行出错:
ORA-01403:未找到任何数据
ORA-06512:SCOTT.BUSINESSHR第5行
ORA-04088:执行触发器“SCOTT.BUSINESSHR”时出错


在触发器中,您不应该从正在运行触发器的表中进行选择,因为您可能会得到
变异表
错误。在这种情况下,根本不需要选择,只需按如下方式编写:

create or replace trigger businesshr
  before insert or update or delete on Employees1727 
  for each row
  begin
    if to_char(sysdate, 'hh24') < '05' or '18' < to_char(sysdate, 'hh24') then
      raise_application_error (-20000, 'Employee info may not be modified at this time!') ;
    end if;
  end businesshr;
创建或替换触发器businesshr
在插入、更新或删除员工之前1727
每行
开始
如果to_char(sysdate,'hh24')<'05'或'18'
您的问题仍然不清楚…还要格式化代码删除行号。是的,但我只想在业务hr上对db执行操作,这就是为什么我必须使用select into在工作时间插入记录。这就是此触发器的作用。如果您尝试在工作时间之前或之后插入数据,它将抛出错误。否则将成功插入。