在sql plus中插入日期查询

时间:2022-07-28 15:40:20

so i'm trying to insert date in sql plus but it keeps on giving errors the query is:

所以我试图在sql plus中插入日期,但它继续给出错误查询是:

INSERT INTO Employee (empno, fname, lname, jobtittle, bdate, address, sex, salary, Superemp, dno)
VALUES (1, 'Anam', 'Irfan', 'Nurse', '1995-04-29', 'house1234', 'F', 8000, 455, 123 );

if it is inserted like this the error is 'literal does not match string format' if it is like 29-04-1995 pr 04-29-1995 or with '/' it says not a valid month

如果它是这样插入错误是'文字不匹配字符串格式'如果它像29-04-1995 pr 04-29-1995或'/'它说不是一个有效的月份

If I use the TO_DATE function it says SYSTEM.EMPLOYEE_DNO_FK violated-parent key not found

如果我使用TO_DATE函数,则表示SYSTEM.EMPLOYEE_DNO_FK违反了 - 未找到父键

2 个解决方案

#1


The date errors are sort of irrelevant; you know you can avoid those by specifying the format mask with to_date('1995-04-29', 'YYYY-MM-DD'), or you could also use a date literal with DATE '1995-04-29'.

日期错误有点无关紧要;你知道你可以通过使用to_date('1995-04-29','YYYY-MM-DD')指定格式掩码来避免这些,或者你也可以使用DATE'1995-04-29'的日期文字。

The important error is the one you mentioned in a comment, SYSTEM.EMPLOYEE_DNO_FK violated-parent key not found. What that means, based on the constraint name, is that you do not have a row with ID 123 in the parent department table. Either create a department with that ID, or change the dno you are inserting into your employee table to one that already exists in your department table.

重要的错误是您在评论中提到的错误,SYSTEM.EMPLOYEE_DNO_FK违反了未找到的父密钥。这意味着,基于约束名称,您在父部门表中没有ID为123的行。创建具有该ID的部门,或将要插入到employee表中的dno更改为department表中已存在的dno。

(As an aside, you should not be creating your own tables in the SYSTEM schema. Create your own schema and do all your work in that).

(顺便说一句,您不应该在SYSTEM模式中创建自己的表。创建自己的模式并完成所有工作)。

#2


Basically when you are entering the date in the month place please enter that month's short form and not the number. Ex: 22-MAY-1994 and not 22-05-1994

基本上,当您输入月份日期时,请输入该月份的简短形式而不是数字。例如:1994年5月22日,而不是22-05-1994

#1


The date errors are sort of irrelevant; you know you can avoid those by specifying the format mask with to_date('1995-04-29', 'YYYY-MM-DD'), or you could also use a date literal with DATE '1995-04-29'.

日期错误有点无关紧要;你知道你可以通过使用to_date('1995-04-29','YYYY-MM-DD')指定格式掩码来避免这些,或者你也可以使用DATE'1995-04-29'的日期文字。

The important error is the one you mentioned in a comment, SYSTEM.EMPLOYEE_DNO_FK violated-parent key not found. What that means, based on the constraint name, is that you do not have a row with ID 123 in the parent department table. Either create a department with that ID, or change the dno you are inserting into your employee table to one that already exists in your department table.

重要的错误是您在评论中提到的错误,SYSTEM.EMPLOYEE_DNO_FK违反了未找到的父密钥。这意味着,基于约束名称,您在父部门表中没有ID为123的行。创建具有该ID的部门,或将要插入到employee表中的dno更改为department表中已存在的dno。

(As an aside, you should not be creating your own tables in the SYSTEM schema. Create your own schema and do all your work in that).

(顺便说一句,您不应该在SYSTEM模式中创建自己的表。创建自己的模式并完成所有工作)。

#2


Basically when you are entering the date in the month place please enter that month's short form and not the number. Ex: 22-MAY-1994 and not 22-05-1994

基本上,当您输入月份日期时,请输入该月份的简短形式而不是数字。例如:1994年5月22日,而不是22-05-1994