一、准备工作
1.打开Oracle所有的服务
2.开启数据库 sqlplus /nolog
3.scott用户登录 conn scott/tiger as sysdba
二、创建表
错误代号:ORA-01843
无法插入数据,无效的日期.
原因是这个TO_DATE的Format中的“MON”格式出现异常,但是这个格式完全符合Oracle的格式要求。
再查看nls_date_language参数,发现这个参数值为NULL
SELECT * FROM v$parameter WHERE name = 'nls_date_language';
因为是中文的环境,因此需要把这个参数改成AMERICAN
ALTER SESSION SET NLS_DATE_LANGUAGE='AMERICAN';
再次执行INSERT INTO EMP VALUES (7369,'SMITH','CLERK',7902,
TO_DATE('17-DEC-1980', 'DD-MON-YYYY'),800,NULL, 20);
则问题得到解决.
1.打开Oracle所有的服务
2.开启数据库 sqlplus /nolog
3.scott用户登录 conn scott/tiger as sysdba
二、创建表
create table emp(
EMPNO INT NOT NULL,
ENAME VARCHAR(10),
JOB VARCHAR(9),
MGR NUMBER(4),
HIERDATE DATE,
SAL NUMbER(7,2),
COMM NUMBER(7,2),
DEPTNO NUMBER(2)
);
三、插入数据
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIERDATE,SAL,COMM,DEPTNO) VALUES ('7369','SMITH','CLERK','7902',TO_DATE('17-DEC-1980','DD-MON-YYYY'),'800','','20');
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIERDATE,SAL,COMM,DEPTNO) VALUES ('7944','ALLEN','SALESMAN','7698',TO_DATE('20-FEB-81','DD-MON-YYYY'),'1600','300','30');
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIERDATE,SAL,COMM,DEPTNO) VALUES ('7521','WARD','SALESMAN','7698',TO_DATE('22-FEB-81','DD-MON-YYYY'),'1250','500','30');
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIERDATE,SAL,COMM,DEPTNO) VALUES ('7566','JONES','MANAGER','7839',TO_DATE('02-APR-81','DD-MON-YYYY'),'2975','','20');
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIERDATE,SAL,COMM,DEPTNO) VALUES ('7654','MARTIN','SALESMAN','7698',TO_DATE('28-SEP-81','DD-MON-YYYY'),'1250','1400','30');
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIERDATE,SAL,COMM,DEPTNO) VALUES ('7698','BLAKE','MANAGER','7839',TO_DATE('01-MAY-81','DD-MON-YYYY'),'2850','','30');
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIERDATE,SAL,COMM,DEPTNO) VALUES ('7782','CLARK','MANAGER','7839',TO_DATE('09-JUN-81','DD-MON-YYYY'),'2450','','10');
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIERDATE,SAL,COMM,DEPTNO) VALUES ('7839','KING','PRESIDENT','',TO_DATE('17-NOV-81','DD-MON-YYYY'),'5000','','10');
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIERDATE,SAL,COMM,DEPTNO) VALUES ('7844','TURNER','SALESMAN','7698',TO_DATE('08-SEP-81','DD-MON-YYYY'),'1500','0','30');
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIERDATE,SAL,COMM,DEPTNO) VALUES ('7900','JAMES','CLERK','7698',TO_DATE('03-DEC-81','DD-MON-YYYY'),'950','','30');
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIERDATE,SAL,COMM,DEPTNO) VALUES ('7902','FORD','ANALYST','7566',TO_DATE('03-DEC-81','DD-MON-YYYY'),'3000','','30');
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIERDATE,SAL,COMM,DEPTNO) VALUES ('7934','MILLER','CLERK','7782',TO_DATE('23-JAN-82','DD-MON-YYYY'),'1300','','10');
四、出现的问题
错误代号:ORA-01843
无法插入数据,无效的日期.
原因是这个TO_DATE的Format中的“MON”格式出现异常,但是这个格式完全符合Oracle的格式要求。
再查看nls_date_language参数,发现这个参数值为NULL
SELECT * FROM v$parameter WHERE name = 'nls_date_language';
因为是中文的环境,因此需要把这个参数改成AMERICAN
ALTER SESSION SET NLS_DATE_LANGUAGE='AMERICAN';
再次执行INSERT INTO EMP VALUES (7369,'SMITH','CLERK',7902,
TO_DATE('17-DEC-1980', 'DD-MON-YYYY'),800,NULL, 20);
则问题得到解决.