先随便指出几个语法错误:
1、
select department_id into it_id from hr.departments where department_name = 'IT';
这一行不应该出现在DECLARE部分
2、
fname varchar2;
phone varchar2;
job varchar2;
VARCHAR2没有定义长度
3、
else之后没有语句
其它的还没有细看。
你这个貌似是把HR的员工表里所有IT部的员工信息插入另一张表IT_EMPLOYEES,完全不用这么复杂:
declare
it_id number;
begin
select department_id into it_id from hr.departments where department_name = 'IT';
for it_emp in (select employee_id,first_name,last_name,email, phone_number,job_id,salary,manager_id from hr.employees where department_id=it_id) loop
insert into IT_EMPLOYEES values(it_emp.employee_id,it_emp.first_name,it_emp.last_name,it_emp.email, it_emp.phone_number,it_emp.job_id,it_emp.salary,it_emp.manager_id);
end loop;
commit;
end;
/
感觉很乱,在声明中不应该出现select...into...吧(select department_id into it_id from hr.departments where department_name = 'IT';)把它放入begin语句块里试试。
问题太多了。。
ddsfsdafsd sdasd