oracle sql developer 执行pl/sql 语句出现错误
代码如下:declareemp_idnumber;dep_idnumber;fnamevarchar2;lnamevarchar(25);c_emailvarchar(2...
代码如下:
declare
emp_id number;
dep_id number;
fname varchar2;
lname varchar(25);
c_email varchar(25);
phone varchar2;
job varchar2;
n_salary number;
m_id number;
it_id number;
select department_id into it_id from hr.departments where department_name = 'IT';cursor curl is select department_id,employee_id,first_name,last_name,email, phone_number,job_id,salary,manager_id from hr.employees;
begin
open curl;
fetch curl into dep_id,emp_id,f_name,l_name,c_email, phone,job,n_salary,m_id;
loop
exit when curl%NOTFOUND;
if dep_id = it_id then
insert into IT_EMPLOYEES
values(emp_id,fname,lname,c_email,phone,job,n_salary,m_id);
else
end if;
fetch curl into dep_id,emp_id,f_name,l_name,c_email, phone,job,n_salary,m_id;
end loop;
close curl;
end;
执行后出现错误信息:
ORA-06550: 第 13 行, 第 1 列:
PLS-00103: 出现符号 "SELECT"在需要下列之一时:
begin function pragma
procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior
符号 "begin" 被替换为 "SELECT" 后继续。
ORA-06550: 第 14 行, 第 8 列:
PLS-00103: 出现符号 "CURL"在需要下列之一时:
:= . ( @ % ;
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
在sql*plus中执行也是这样,是什么原因那? 展开
declare
emp_id number;
dep_id number;
fname varchar2;
lname varchar(25);
c_email varchar(25);
phone varchar2;
job varchar2;
n_salary number;
m_id number;
it_id number;
select department_id into it_id from hr.departments where department_name = 'IT';cursor curl is select department_id,employee_id,first_name,last_name,email, phone_number,job_id,salary,manager_id from hr.employees;
begin
open curl;
fetch curl into dep_id,emp_id,f_name,l_name,c_email, phone,job,n_salary,m_id;
loop
exit when curl%NOTFOUND;
if dep_id = it_id then
insert into IT_EMPLOYEES
values(emp_id,fname,lname,c_email,phone,job,n_salary,m_id);
else
end if;
fetch curl into dep_id,emp_id,f_name,l_name,c_email, phone,job,n_salary,m_id;
end loop;
close curl;
end;
执行后出现错误信息:
ORA-06550: 第 13 行, 第 1 列:
PLS-00103: 出现符号 "SELECT"在需要下列之一时:
begin function pragma
procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior
符号 "begin" 被替换为 "SELECT" 后继续。
ORA-06550: 第 14 行, 第 8 列:
PLS-00103: 出现符号 "CURL"在需要下列之一时:
:= . ( @ % ;
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
在sql*plus中执行也是这样,是什么原因那? 展开
4个回答
展开全部
先随便指出几个语法错误:
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;
/
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |