0

Employees我正在尝试使用以下过程将值插入表中。我收到错误。谁能向我解释这个问题?错误代码:第 29 行:忽略 SQL 语句。

CREATE OR REPLACE PROCEDURE insert_employee(
    p_emp_id IN NUMBER, 
    p_emp_fname IN VARCHAR2,
    p_emp_sname IN VARCHAR2,
    p_emp_add1 IN VARCHAR2, 
    p_emp_add2 IN VARCHAR2,
    p_emp_town IN VARCHAR2, 
    p_emp_county IN VARCHAR2,
    p_emp_telno IN NUMBER,
    p_emp_position IN VARCHAR2, 
    p_emp_manager IN VARCHAR2

) IS 
    v_county_id County.county_id%type;
    v_position_id Positions.position_id%type;
    v_manager_id Facilities.facilty_id%type;
BEGIN    

    SELECT county_id
    INTO v_county_id
    FROM County WHERE county_name = p_emp_county;

    SELECT position_id
    INTO v_position_id
    FROM Positions WHERE position_name = p_emp_position;

    SELECT facility_manager
    INTO v_manager_id
    FROM Facilities WHERE facility_name = p_emp_manager; 

    INSERT INTO Employees (emp_id, emp_fname, emp_sname, emp_add1, emp_add2, emp_town, emp_county, emp_telno, emp_position, emp_salary, emp_manager) 
    VALUES(p_emp_id, p_emp_fname, p_emp_sname, p_emp_add1, p_emp_add2, p_emp_town, v_county_id, p_emp_telno, v_position_id, p_emp_salary, v_manager_id);
END;
/
4

6 回答 6

2

删除 SELECT - 它们的语法无效,无论如何都不要在这里做任何必要的事情。还删除无意义的错误“处理程序”,它只是隐藏错误:

CREATE OR REPLACE PROCEDURE insert_employee(
    p_emp_id IN NUMBER, 
    p_emp_fname IN VARCHAR2,
    p_emp_sname IN VARCHAR2,
    p_emp_add1 IN VARCHAR2, 
    p_emp_add2 IN VARCHAR2,
    p_emp_town IN VARCHAR2, 
    p_emp_county IN VARCHAR2,
    p_emp_telno IN NUMBER,
    p_emp_position IN VARCHAR2, 
    p_emp_manager IN VARCHAR2

) IS
BEGIN    

    INSERT INTO Employees (emp_id, emp_fname, emp_sname, emp_add1, emp_add2, emp_town, emp_county, emp_telno, emp_salary, emp_position, emp_manager) 
    VALUES(p_emp_id, p_emp_fname, p_emp_sname, p_emp_add1, p_emp_add2, p_emp_town, p_emp_county, p_emp_telno, p_emp_salary, p_emp_position, p_emp_manager);

 END;

如果您的示例过于简单,并且您实际上需要之前选择的值(例如,您也将这些值插入到员工中),那么您需要使用“select into”语法,例如

...
) IS
    v_county_id county.county_id%type;
    v_xxx county.xxx%type;
BEGIN    

    SELECT county_id
    INTO   v_county_id
    FROM County WHERE county_name = p_emp_county;
    ...
于 2012-05-04T09:57:27.873 回答
2

您的局部变量声明应在每行末尾有分号:

) IS 
    v_county_id County.county_id%type;
    v_position_id Positions.position_id%type;
    v_manager_id Facilities.facilty_id%type;
于 2012-05-04T12:15:20.667 回答
0

您需要选择光标还是变量?

例如

SELECT county_id into v_country
    FROM County WHERE county_name = p_emp_county;
于 2012-05-04T09:46:33.200 回答
0

你应该输入;在变量定义之后而不是逗号。

于 2012-05-04T15:11:02.990 回答
0
create or replace procedure procOne(sid  OUT  number,sname OUT varchar,fee OUT number)
as
begin
insert into student values(sid,sname,fee);
end;
于 2013-10-24T17:58:48.080 回答
0

检查列名

v_manager_id 设施。设施_id%type;

FROM 设施 WHERE设施_name = p_emp_manager;

于 2013-06-03T10:29:00.490 回答