你好堆栈溢出我是sql的新手,我试图创建一个程序来添加新的顾问。我将重新使用顶点应用程序中的代码,并带有一个按钮来执行任务。此外,我已实施序列添加到顾问的新条目。不幸的是我有错误
编译失败,第10行(11:48:18) PLS-00103:遇到了符号" BEGIN"当期待以下之一时:使用外部确定性parallel_enable流水线result_cache可访问
将authid作为群集顺序我可以获得一些指导来解决这个问题,因为我对sql感谢新手并且研究没有帮助。
原始代码
create or replace procedure hirecst
(CST_NAME VARCHAR2,
START_DATE DATE,
LEAVE_DATE DATE,
LOCATION VARCHAR2,
SPECIALIST_AREA VARCHAR2)
RETURN NUMBER IS
new_cst NUMBER;
BEGIN
SELECT CONSULTANT_IDSEQ.NEXTVAL
INTO new_cst
FROM DUAL;
INSERT INTO LDS_CONSULTANT (CONSULTANT_ID, CST_NAME, START_DATE, LEAVE_DATE, LOCATION, SPECIALIST_AREA)
VALUES (new_cst, p_con_name, p_con_start, p_con_end, p_con_loc, p_con_spec);
RETURN(new_cst);
END;
删除了返回
create or replace procedure hirecst
(CST_NAME VARCHAR2,
START_DATE DATE,
LEAVE_DATE DATE,
LOCATION VARCHAR2,
SPECIALIST_AREA VARCHAR2)
BEGIN
new_cst NUMBER;
SELECT CONSULTANT_IDSEQ.NEXTVAL
INTO new_cst
FROM DUAL;
INSERT INTO LDS_CONSULTANT (CONSULTANT_ID, CST_NAME, START_DATE, LEAVE_DATE, LOCATION, SPECIALIST_AREA)
VALUES (new_cst, p_con_name, p_con_start, p_con_end, p_con_loc, p_con_spec);
END;
答案 0 :(得分:1)
注意:我忽略了声明的参数名称与INSERT语句中使用的参数名称之间的明显不匹配。
As documented in the manual您需要AS
(或IS
)关键字来启动实际的过程部分 - 之后需要编写变量声明:
create or replace procedure hirecst
(CST_NAME VARCHAR2,
START_DATE DATE,
LEAVE_DATE DATE,
LOCATION VARCHAR2,
SPECIALIST_AREA VARCHAR2)
AS --<< HERE
new_cst NUMBER;
BEGIN
SELECT CONSULTANT_IDSEQ.NEXTVAL
INTO new_cst
FROM DUAL;
INSERT INTO LDS_CONSULTANT
(CONSULTANT_ID, CST_NAME, START_DATE, LEAVE_DATE, LOCATION, SPECIALIST_AREA)
VALUES
(new_cst, p_con_name, p_con_start, p_con_end, p_con_loc, p_con_spec);
END;
但是,根本不需要SELECT INTO,您可以直接在nextval
语句中使用INSERT
。因此,您可以将过程简化为:
create or replace procedure hirecst
(CST_NAME VARCHAR2,
START_DATE DATE,
LEAVE_DATE DATE,
LOCATION VARCHAR2,
SPECIALIST_AREA VARCHAR2)
AS --<< Still needed!
BEGIN
INSERT INTO LDS_CONSULTANT
(CONSULTANT_ID, CST_NAME, START_DATE, LEAVE_DATE, LOCATION, SPECIALIST_AREA)
VALUES
(CONSULTANT_IDSEQ.NEXTVAL, p_con_name, p_con_start, p_con_end, p_con_loc, p_con_spec);
END;
如果要从过程中返回生成的ID,则需要OUT
参数:
create or replace procedure hirecst
(CST_NAME VARCHAR2,
START_DATE DATE,
LEAVE_DATE DATE,
LOCATION VARCHAR2,
SPECIALIST_AREA VARCHAR2,
p_consultant_id out integer) --<< HERE
AS
BEGIN
-- Assign the value to the OUT parameter
p_consultant_id := CONSULTANT_IDSEQ.NEXTVAL;
INSERT INTO LDS_CONSULTANT
(CONSULTANT_ID, CST_NAME, START_DATE, LEAVE_DATE, LOCATION, SPECIALIST_AREA)
VALUES
(p_consultant_id, p_con_name, p_con_start, p_con_end, p_con_loc, p_con_spec);
END;
/
答案 1 :(得分:0)
以下是procedre的语法 -
CREATE [OR REPLACE] PROCEDURE procedure_name
[ (parameter [,parameter]) ]
IS
[declaration_section]
BEGIN
executable_section
[EXCEPTION
exception_section]
END [procedure_name];
你忘了&#39; IS&#39;关键字
following is the code-
create or replace procedure hirecst
(CST_NAME VARCHAR2,
START_DATE DATE,
LEAVE_DATE DATE,
LOCATION VARCHAR2,
SPECIALIST_AREA VARCHAR2)
IS
new_cst NUMBER;
begin
SELECT CONSULTANT_IDSEQ.NEXTVAL
INTO new_cst
FROM DUAL;
INSERT INTO LDS_CONSULTANT (CONSULTANT_ID, CST_NAME, START_DATE, LEAVE_DATE, LOCATION, SPECIALIST_AREA)
VALUES (new_cst, p_con_name, p_con_start, p_con_end, p_con_loc, p_con_spec);
end;
;