【发布时间】:2018-01-18 05:22:58
【问题描述】:
这是我的部门表:
create table Department(
DeptNo int primary key,
DeptName varchar2(21) not null,
DeptLocation varchar2(13) not null
);
我正在尝试为 DeptName 列插入长度超过接受的值,即 21,这意味着我应该得到“VALUE_ERROR”异常。 我正在运行的plsql代码是:
begin
insert into department values(1, 'Some random department name', 'SomeLocation');
exception
when value_error then
dbms_output.put_line('Cannot store the value!');
end;
当我试图捕获异常时,它没有被捕获。我收到错误消息:
ORA-12899:列“SQL_ZIRHWMLFPCEAKPGYGJJZLSIFI”.“DEPARTMENT”.“DEPTNAME”的值太大(实际:27,最大值:21)ORA-06512:在第 2 行 ORA-06512:在“SYS.DBMS_SQL”,第 1721 行
但如果我将异常从“value_error”更改为“others”
begin
insert into department values(1, 'Some random department name', 'SomeLocation');
exception
when others then
dbms_output.put_line('Cannot store the value!');
end;
然后我得到预期的输出
无法存储值!
我哪里做错了?请告诉我。谢谢!
PS:我在 livesql.oracle.com 上运行所有代码
【问题讨论】:
-
如果您对某个问题投反对票,请留言说明您这样做的原因。