无法在 oracle sql 开发人员中编译 PL/SQL
Can't compile PL/SQL in oracle sql developer
这是我的包裹:
CREATE OR REPLACE PACKAGE DEPARTMENT_INFO AS
TYPE t_dep_loc IS RECORD(region_name regions.region_name%type,
country_name countries.country_name%type,
state locations.state_province%type,
city locations.city%type);
TYPE t_dep_mgr IS RECORD(first_name employees.first_name%type,
last_name employees.last_name%type,
email employees.email%type,
phone_number employees.phone_number%type);
FUNCTION location_department(p_department_id departments.department_id%TYPE)
RETURN t_dep_loc;
FUNCTION manager_department(p_department_id departments.department_id%TYPE)
RETURN t_dep_mgr;
END DEPARTMENT_INFO;
CREATE OR REPLACE PACKAGE BODY department_info AS
FUNCTION location_department(p_department_id departments.department_id%TYPE)
RETURN t_dep_loc
AS
v_dep_loc t_dep_loc;
begin
select r.region_name, co.country_name, l.state_province, l.city
into v_dep_loc.region_name, v_dep_loc.country_name, v_dep_loc.state, v_dep_loc.city
from regions r
join countries co on r.region_id = co.region_id
join locations l on l.country_id = co.country_id
join departments d on l.location_id = d.location_id
where d.department_id = p_department_id;
return v_dep_loc;
end;
FUNCTION manager_department(p_department_id departments.department_id%TYPE)
RETURN t_dep_mgr
AS
v_dep_mgr t_dep_mgr;
begin
select e.first_name, e.last_name, e.email, e.phone_number
into v_dep_mgr.first_name, v_dep_mgr.last_name, v_dep_mgr.email, v_dep_mgr.phone_number
from employees e
join departments d on e.employee_id = d.manager_id
where d.department_id = p_department_id;
return v_dep_mgr;
end;
END;
我尝试使用 /
来标记 PL/SQL 块的结束,但后来我得到了同样的错误,但不是来自 CREATE,而是来自 /
.
这是错误:
Error(18,1): PLS-00103: Encountered the symbol "CREATE"
这是我第一次使用该程序,我使用的是示例解决方案。
不要忘记在脚本之间包含 /
CREATE OR REPLACE
PACKAGE DEPARTMENT_INFO AS
end DEPARTMENT_INFO;
/ <--- use this one after package script and before package body script
CREATE OR REPLACE
PACKAGE BODY DEPARTMENT_INFO AS
end DEPARTMENT_INFO;
如果您同时编译这两个脚本,请在第一个脚本的末尾包含 /
或 一个一个地编译它们。
所以你已经打包了。
写包体的正确方法是右击包名然后点击'create body'。
然后如果你想运行包你首先需要编译包规范,然后是包体。然后右键单击该包并选择 'run'。在那里你可以写 PL SQL 块然后 运行 它。
这是我的包裹:
CREATE OR REPLACE PACKAGE DEPARTMENT_INFO AS
TYPE t_dep_loc IS RECORD(region_name regions.region_name%type,
country_name countries.country_name%type,
state locations.state_province%type,
city locations.city%type);
TYPE t_dep_mgr IS RECORD(first_name employees.first_name%type,
last_name employees.last_name%type,
email employees.email%type,
phone_number employees.phone_number%type);
FUNCTION location_department(p_department_id departments.department_id%TYPE)
RETURN t_dep_loc;
FUNCTION manager_department(p_department_id departments.department_id%TYPE)
RETURN t_dep_mgr;
END DEPARTMENT_INFO;
CREATE OR REPLACE PACKAGE BODY department_info AS
FUNCTION location_department(p_department_id departments.department_id%TYPE)
RETURN t_dep_loc
AS
v_dep_loc t_dep_loc;
begin
select r.region_name, co.country_name, l.state_province, l.city
into v_dep_loc.region_name, v_dep_loc.country_name, v_dep_loc.state, v_dep_loc.city
from regions r
join countries co on r.region_id = co.region_id
join locations l on l.country_id = co.country_id
join departments d on l.location_id = d.location_id
where d.department_id = p_department_id;
return v_dep_loc;
end;
FUNCTION manager_department(p_department_id departments.department_id%TYPE)
RETURN t_dep_mgr
AS
v_dep_mgr t_dep_mgr;
begin
select e.first_name, e.last_name, e.email, e.phone_number
into v_dep_mgr.first_name, v_dep_mgr.last_name, v_dep_mgr.email, v_dep_mgr.phone_number
from employees e
join departments d on e.employee_id = d.manager_id
where d.department_id = p_department_id;
return v_dep_mgr;
end;
END;
我尝试使用 /
来标记 PL/SQL 块的结束,但后来我得到了同样的错误,但不是来自 CREATE,而是来自 /
.
这是错误:
Error(18,1): PLS-00103: Encountered the symbol "CREATE"
这是我第一次使用该程序,我使用的是示例解决方案。
不要忘记在脚本之间包含 /
CREATE OR REPLACE
PACKAGE DEPARTMENT_INFO AS
end DEPARTMENT_INFO;
/ <--- use this one after package script and before package body script
CREATE OR REPLACE
PACKAGE BODY DEPARTMENT_INFO AS
end DEPARTMENT_INFO;
如果您同时编译这两个脚本,请在第一个脚本的末尾包含 /
或 一个一个地编译它们。
所以你已经打包了。
写包体的正确方法是右击包名然后点击'create body'。
然后如果你想运行包你首先需要编译包规范,然后是包体。然后右键单击该包并选择 'run'。在那里你可以写 PL SQL 块然后 运行 它。