【问题标题】:Can't compile PL/SQL in oracle sql developer无法在 oracle sql developer 中编译 PL/SQL
【发布时间】:2015-08-23 15:49:55
【问题描述】:

这是我的包裹:

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"

这是我第一次使用该程序,我正在使用示例解决方案。

【问题讨论】:

    标签: oracle syntax plsql package pls-00103


    【解决方案1】:

    别忘了在脚本之间加上/

    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;
    

    如果您同时编译两个脚本,则在您的第一个脚本末尾包含/逐个编译它们。

    【讨论】:

    • 然后我得到这个错误:错误(15,1):PLS-00103:遇到符号“/”
    • 好的..尝试执行我的脚本,我已经在我的答案中发布了该脚本。一次,编译,然后你可以一一包含你的函数并编译它们。另外,请确保在每个脚本的末尾使用/
    • @downvoter 可以分享他/她的知识。您可以尝试编译我的脚本 withwithout /,然后分享您的知识。
    【解决方案2】:

    所以你已经做了一个包。

    编写包体的正确方法是右键单击包名,然后单击“创建主体”。

    那么如果你想运行包你首先需要编译包规范,然后是包体。然后右键单击包并选择“运行”。在那里你可以编写 PL SQL 块然后运行它。

    【讨论】:

    • 我在一个 sql 脚本中编写了这一切...感谢您提供的信息,现在它可以工作了。
    猜你喜欢
    • 1970-01-01
    • 2021-09-11
    • 1970-01-01
    • 1970-01-01
    • 2015-09-16
    • 2021-11-08
    • 1970-01-01
    • 2015-12-13
    • 2013-08-30
    相关资源
    最近更新 更多