オラクルは、エラー情報であなたの意図が何であるかを知ることができません. 格納している変数名、またはその変数がどこから来たのかを知ることは、必ずしもエンド ユーザーやセキュリティにとって最善の利益になるとは限りません。
たとえば、エラーを簡単に生成できます。
SQL> declare
2 v_tooshort varchar2(3);
3 begin
4 select 'too long' into v_tooshort from dual;
5 end;
6 /
declare
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 4
エラーはすでに行番号を示しています。
変数名 ( ) を与えるエラーを希望しますv_tooshort
か? それはユーザーにとって役に立ちません。
正しい情報は「長すぎる」という値ですか? dual
または、それがテーブルのダミー列であるという事実は? (または実際の列とテーブル)?
エラーはステートメントではselect into
なくinsert
ステートメントから発生するため、例外が名前で識別できる特定のデータベース制約があるわけではありません。
編集(コメントで提起された問題に対処するため):
それは真実ではありません。insert
(ORA-12899として)を実行すると、列名と長さが返されselect into
ますが、テーブルのデータを使用している場合でも、を実行すると返されません。
SQL> create table test_length (tooshort varchar2(3));
Table created.
SQL> begin
2 insert into test_length(tooshort) values ('too long');
3 end;
4 /
begin
*
ERROR at line 1:
ORA-12899: value too large for column "MYUSER"."TEST_LENGTH"."TOOSHORT"
(actual: 8, maximum: 3)
ORA-06512: at line 2
SQL> insert into test_length(tooshort) values ('abc');
1 row created.
SQL> commit;
Commit complete.
SQL> declare
2 v_onechar varchar2(1);
3 begin
4 select tooshort into v_onechar from test_length;
5 end;
6 /
declare
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 4
編集2:
select into
独自の begin-exception-end ブロックにネストして、好きなエラーを発生させることができます (一意のエラー番号と説明的なエラー テキストを提供します)。
SQL> ed
Wrote file afiedt.buf
1 declare
2 v_onechar varchar2(1);
3 begin
4 select tooshort into v_onechar from test_length;
5 exception
6 when value_error then
7 RAISE_APPLICATION_ERROR(-20011, 'my variable named v_onechar is too short for the data returned from test_lengt
h.tooshort');
8* end;
SQL> /
declare
*
ERROR at line 1:
ORA-20011: my variable named v_onechar is too short for the data returned from
test_length.tooshort
ORA-06512: at line 7