Oracle插入存储过程出错

时间:2016-05-02 11:08:56

标签: oracle stored-procedures insert

使用SQL Developer在Oracle中插入存储过程语句:

CREATE OR REPLACE PROCEDURE T_Department_INSERT 
AS 
BEGIN 
    insert INTO T_Department(dept_id, dept_name, dept_location, manager_id)
    values(select case count(*) when 0 then 1 else max(dept_id) + 1 (end.from T_Department),
           par_dept_id, par_dept_name, par_dept_location, par_manager_id);
      NULL;
END T_Department_INSERT;

1 个答案:

答案 0 :(得分:0)

您使用的工具(SQL Developer)对正确的答案没有任何区别。这是一种可能性:

    CREATE TABLE t_department
    (
       dept_id         INTEGER
     , dept_name       VARCHAR2 (20)
     , dept_location   VARCHAR2 (100)
     , manager_id      INTEGER
    );

    CREATE SEQUENCE t_department_seq;

    CREATE OR REPLACE TRIGGER t_department_trg
       BEFORE INSERT
       ON t_department
       REFERENCING NEW AS new OLD AS old
       FOR EACH ROW
    BEGIN
       :new.dept_id   := t_department_seq.NEXTVAL;
    END t_department_trg;

    CREATE OR REPLACE PROCEDURE t_department_insert (
       p_dept_name       IN t_department.name%TYPE
     , p_dept_location   IN t_department.location%TYPE
     , p_manager_id      IN t_department.manager_id%TYPE
    )
    AS
    BEGIN
       INSERT INTO t_department (
                 dept_name, dept_location, manager_id
                   )
            VALUES (p_dept_name, p_dept_location, p_manager_id);
    END t_department_insert;