我收到的错误取决于我是否删除了" /"或者离开它。
使用/
:
PLS-00103:遇到符号
/
没有/
:
PLS-00103:遇到符号
CREATE
我做错了什么?
CREATE OR REPLACE PACKAGE EMP_PACKAGE AS
TYPE EMP_TYPE IS RECORD
( /* Employee Type */
employee_id NUMBER(6,0),
first_name VARCHAR2(20),
last_name VARCHAR2(25),
email VARCHAR2(25),
phone_number VARCHAR2(20),
hire_date DATE,
job_id VARCHAR2(10),
salary NUMBER(6,2),
commission_pct NUMBER(2,2),
manager_id NUMBER(6,0),
department_id NUMBER(4,0)
);
PROCEDURE add_emp(employee_id NUMBER);
PROCEDURE edit_first_name(employee_id NUMBER, first_name employees.first_name%TYPE);
FUNCTION get_emp(employee_id NUMBER) RETURN employee_id;
END;
/
CREATE OR REPLACE PACKAGE BODY EMP_PACKAGE AS
-- procedure will edit an employee's first name
PROCEDURE edit_first_name(employee_id NUMBER) IS
BEGIN
INSERT INTO employees (employees.first_name)
VALUES (first_name);
END edit_first_name;
END;
/
答案 0 :(得分:2)
在包装规范中,您有以下行:
FUNCTION get_emp(employee_id NUMBER) RETURN employee_id;
employee_id
不是有效的数据类型。
将其更改为有效类型后,您将看到包体中的错误:
ADD_EMP
程序和GET_EMP
功能。PROCEDURE edit_first_name(employee_id NUMBER)
与包规范中的声明不匹配,因为它缺少first_name employees.first_name%TYPE
参数。INSERT INTO employees (employees.first_name) VALUES (first_name);
中,该列为first_name
而非employees.first_name
。答案 1 :(得分:0)
您的代码中有一些错误。 也许你需要这个东西? 我在sql developer中编译它没有任何错误
create or replace PACKAGE EMP_PACKAGE AS
TYPE EMP_TYPE IS RECORD
( /* Employee Type */
employee_id NUMBER(6,0),
first_name VARCHAR2(20),
last_name VARCHAR2(25),
email VARCHAR2(25),
phone_number VARCHAR2(20),
hire_date DATE,
job_id VARCHAR2(10),
salary NUMBER(6,2),
commission_pct NUMBER(2,2),
manager_id NUMBER(6,0),
department_id NUMBER(4,0)
);
PROCEDURE add_emp(p_employee_id NUMBER);
PROCEDURE edit_first_name(p_employee_id NUMBER, p_first_name employees.first_name%TYPE);
FUNCTION get_emp(p_employee_id NUMBER) RETURN EMP_TYPE;
END;
/
create or replace PACKAGE BODY EMP_PACKAGE AS
-- procedure will edit an employee's first name
PROCEDURE edit_first_name(p_employee_id NUMBER, p_first_name employees.first_name%TYPE) IS
BEGIN
update employees emp
set emp.first_name = p_first_name
where emp.employee_id = p_employee_id;
END edit_first_name;
PROCEDURE add_emp(p_employee_id NUMBER) IS BEGIN
null;
END;
FUNCTION get_emp(p_employee_id NUMBER) RETURN EMP_TYPE IS
BEGIN
return null;
END;
END;