[英]not enough values insert with register type Oracle SQL Developer
I am trying to make a variable of a custom record type, set values to it, then insert it into a table. 我试图做一个自定义记录类型的变量,为其设置值,然后将其插入表中。 I am having difficulties, and I do not know where I am wrong.
我遇到了困难,我不知道自己在哪里错。 I checked the columns in the table and they are all the not-nullable colums in the register type.
我检查了表中的列,它们都是寄存器类型中所有不可为空的列。 Yet I get a "not enough values" error.
但是我收到“值不足”的错误。 I'm working in SQL Developer.
我正在使用SQL Developer。 Here is my code:
这是我的代码:
set serveroutput on;
DECLARE
TYPE ang_record IS RECORD
(cod employees.employee_id%TYPE,
nume employees.last_name%TYPE,
email employees.email%TYPE,
h_date employees.hire_date%TYPE,
job_id employees.job_id%TYPE,
sal employees.salary%TYPE,
dept employees.department_id%TYPE);
v_ang ang_record;
BEGIN
v_ang.cod := 500;
v_ang.nume := 'Profeanu';
v_ang.email := 'ileana.profeanu@gmail.com';
v_ang.h_date := SYSDATE;
v_ang.job_id := 'SH_CLERK';
v_ang.sal := 2000;
v_ang.dept := 50;
INSERT INTO empil (employee_id, last_name, email, hire_date, job_id, salary, department_id)
VALUES v_ang;
END;
/
ROLLBACK;
You made a record type of the employees table. 您已创建了employees表的记录类型。 And you want to use this type to insert a record into the empil table.
并且您想使用此类型将记录插入到empil表中。 You have mixed up the two ways to achieve this.
您已经混合了两种方法来实现此目的。 First:
第一:
set serveroutput on;
DECLARE
TYPE ang_record IS RECORD
(cod employees.employee_id%TYPE,
nume employees.last_name%TYPE,
email employees.email%TYPE,
h_date employees.hire_date%TYPE,
job_id employees.job_id%TYPE,
sal employees.salary%TYPE,
dept employees.department_id%TYPE);
v_ang ang_record;
BEGIN
v_ang.cod := 500;
v_ang.nume := 'Profeanu';
v_ang.email := 'ileana.profeanu@gmail.com';
v_ang.h_date := SYSDATE;
v_ang.job_id := 'SH_CLERK';
v_ang.sal := 2000;
v_ang.dept := 50;
INSERT INTO empil (employee_id, last_name, email, hire_date, job_id, salary, department_id)
VALUES (v_ang.code, v_ang.nume, v_ang.email, v_ang.h_date, v_ang.job_id, v_ang.sal, v_ang.dept);
END;
/
ROLLBACK;
Second: 第二:
set serveroutput on;
DECLARE
v_ang r_empil%rowtype;
BEGIN
v_ang.employee_id := 500;
v_ang.last_name := 'Profeanu';
v_ang.email := 'ileana.profeanu@gmail.com';
v_ang.hire_date := SYSDATE;
v_ang.job_id := 'SH_CLERK';
v_ang.salary := 2000;
v_ang.department_id := 50;
INSERT INTO empil (employee_id, last_name, email, hire_date, job_id, salary, department_id)
VALUES v_ang;
END;
/
ROLLBACK;
I hope that I have made it clear for you. 希望我已向您说明。
Good luck with your studies!!! 祝你学习顺利!!!
I believe the problem is that SQL treats the data type object separately than it does the data type members. 我认为问题在于,SQL会比对待数据类型成员单独对待数据类型对象。 v_ang is considered a single item even though it consists of multiple sub elements.
v_ang即使包含多个子元素,也被视为单个项目。
You either need to create a table who's column is of type ang_record, or insert the elements individually like this. 您或者需要创建一个列的类型为ang_record的表,或者像这样单独插入元素。
INSERT INTO empil (employee_id, last_name, email, hire_date,
job_id, salary, department_id)
VALUES (v_ang.employee_id, v_ang.last_name, v_ang.email,
v_ang.hire_date, v_ang.job_id, v_ang.salary,
v_ang.department_id);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.