我正在尝试创建一个存储过程来将值插入到EMPLOYEE TABLE中。 当我尝试使用值执行该过程时,它会引发错误。你能帮忙吗?提前谢谢。
存储过程----
create or replace PROCEDURE CREATE_EMP
(empid IN EMPLOYEE.EMP_ID%TYPE,
firstname IN EMPLOYEE.FIRST_NAME%TYPE,
surname IN EMPLOYEE.SURNAME%TYPE,
address IN EMPLOYEE.ADDRESS%TYPE,
city IN EMPLOYEE.CITY%TYPE,
county IN EMPLOYEE.COUNTY_STATE%TYPE,
postcode IN EMPLOYEE.POSTCODE_ZIP%TYPE,
country IN EMPLOYEE.COUNTRY%TYPE,
jobtitle IN EMPLOYEE.JOB_TITLE%TYPE,
startdate IN EMPLOYEE.START_DATE%TYPE,
enddate IN EMPLOYEE.END_DATE%TYPE)
AS
BEGIN
INSERT INTO EMPLOYEE
VALUES(empid, firstname, surname, address, city, county, postcode, country, jobtitle, startdate, enddate);
END CREATE_EMP;
执行命令---
EXECUTE CREATE_EMP(58,'John','Testy','Here Lane','Himble','UK','Skipper',2015/02/02,2017/02/02);
错误讯息----
Error starting at line : 1 in command -
EXECUTE CREATE_EMP(58,'John','Testy','Here Lane','Himble','UK','Skipper',2015/02/02,2017/02/02)
Error report -
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'CREATE_EMP'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
表-----
EMP_ID NUMBER(8,0)
FIRST_NAME VARCHAR2(30 BYTE)
SURNAME VARCHAR2(30 BYTE)
ADDRESS VARCHAR2(50 BYTE)
CITY VARCHAR2(30 BYTE)
COUNTY_STATE VARCHAR2(30 BYTE)
POSTCODE_ZIP VARCHAR2(10 BYTE)
COUNTRY VARCHAR2(5 BYTE)
JOB_TITLE VARCHAR2(20 BYTE)
START_DATE DATE
END_DATE DATE
答案 0 :(得分:0)
当然,您应该列出大括号内的表名后面的所有列,然后再输入值关键字。您必须按插入值的顺序匹配列。
但是,传递给过程的值的数量与声明的参数数量不同。
此外,
以下内容存在问题:
开始使用EMPLOYEE.START_DATE%TYPE,
在EMPLOYEE.END_DATE%TYPE
中结束2015/02 / 02,2017 / 02/02
因此,2015/02/02
和2017/02/02
不是DATE。你应该通过DATE。
要插入 DATE 值,请始终使用格式正确的TO_DATE
。
使用 TO_DATE :
传递参数值EXECUTE create_emp(58, 'John', 'Testy', 'Here Lane', 'Himble', 'UK', 'Skipper',
TO_DATE('2015/02/02','YYYY/MM/DD'), TO_DATE('2017/02/02','YYYY/MM/DD'));
答案 1 :(得分:0)
错误消息说:
PLS-00306:调用' CREATE_EMP'
时参数的数量或类型错误
我已将您给定的参数映射到方法所需的参数:
empid = 58
firstname = 'John'
surname = 'Testy'
address = 'Here Lane'
city = 'Himble'
county
postcode
country = 'UK'
jobtitle = 'Skipper'
startdate = 2015/02/02
enddate = 2017/02/02
由于没有参数具有默认值,因此您只需在调用中错过2个参数,如错误消息所示。
在匿名块中执行CREATE_EMP
。这对我有用:
begin
CREATE_EMP(58, 'John', 'Testy', 'Here Lane', 'Himble', 'Abc','1225', 'UK', 'Skipper', TO_DATE('2015/02/02','YYYY/MM/DD'), TO_DATE('2017/02/02','YYYY/MM/DD'));
end;
这是数据库创建和CREATE_EMP
定义:
CREATE TABLE EMPLOYEE (
EMP_ID NUMBER(8,0),
FIRST_NAME VARCHAR2(30),
SURNAME VARCHAR2(30),
ADDRESS VARCHAR2(50),
CITY VARCHAR2(30),
COUNTY_STATE VARCHAR2(30),
POSTCODE_ZIP VARCHAR2(10),
COUNTRY VARCHAR2(5),
JOB_TITLE VARCHAR2(20),
START_DATE DATE,
END_DATE DATE
);
//
create or replace PROCEDURE CREATE_EMP
(
empid IN EMPLOYEE.EMP_ID%TYPE,
firstname IN EMPLOYEE.FIRST_NAME%TYPE,
surname IN EMPLOYEE.SURNAME%TYPE,
address IN EMPLOYEE.ADDRESS%TYPE,
city IN EMPLOYEE.CITY%TYPE,
county IN EMPLOYEE.COUNTY_STATE%TYPE,
postcode IN EMPLOYEE.POSTCODE_ZIP%TYPE,
country IN EMPLOYEE.COUNTRY%TYPE,
jobtitle IN EMPLOYEE.JOB_TITLE%TYPE,
startdate IN EMPLOYEE.START_DATE%TYPE,
enddate IN EMPLOYEE.END_DATE%TYPE)
AS
BEGIN
INSERT INTO EMPLOYEE
(EMP_ID, FIRST_NAME, SURNAME, ADDRESS, CITY, COUNTY_STATE, POSTCODE_ZIP, COUNTRY, JOB_TITLE, START_DATE, END_DATE)
VALUES
(empid, firstname, surname, address, city, county, postcode, country, jobtitle, startdate, enddate);
END CREATE_EMP;
答案 2 :(得分:0)
to_date
函数,即:使用to_date('2015/02/02','YYYY/MM/DD')
而不是2015/02/02