插入员工的过程:忽略PL / SQL语句

时间:2012-05-04 09:44:31

标签: sql oracle stored-procedures

我正在尝试使用以下过程将值插入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;
/

6 个答案:

答案 0 :(得分: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;

如果您的示例过于简单,并且您实际上需要之前选择的值(例如,您也将这些值插入到Employees中),那么您需要使用“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;
    ...

答案 1 :(得分:2)

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

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

答案 2 :(得分:0)

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

E.g。

SELECT county_id into v_country
    FROM County WHERE county_name = p_emp_county;

答案 3 :(得分:0)

你应该输入;在变量定义之后改为逗号。

答案 4 :(得分:0)

检查列名

v_manager_id设施。 facilty _id%type;

FROM Facilities WHERE 设施 _name = p_emp_manager;

答案 5 :(得分: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;