2

to_date('1311313', 'yymmdd')私は実際に言って例外をスローする以下のコードを持っていますinvalid month。次のように管理できます

exception
when others then
  sop('date format is wrong');

ここでの問題は、他のエラーが発生したかのようにやりたくないすべてがキャッチされ、メッセージが渡されることですdate format is wrong。また、ユーザー定義の例外を作成したくありません。以下のようにコードで使用できるように、どの例外がスローされているかを知りたいだけです

exception
when name_of_exception then
  sop('date format is wrong');
4

2 に答える 2

9

『 Oracle Database PL/SQL 言語リファレンス』の「内部的に定義された例外」セクションには、次のように記載されています。

内部的に定義された例外には、PL/SQLが名前を付けるか(「事前定義の例外」を参照)、ユーザーが名前を付けない限り、名前はありません。

あなたのコードは例外をスローしますORA-01830:

SQL> select to_date('1311313', 'yymmdd') from dual
               *
ERROR at line 1:
ORA-01830: date format picture ends before converting entire input string

これは事前定義された例外の 1 つではないため、自分で名前を付ける必要があります。

declare
  ex_date_format exception;
  pragma exception_init(ex_date_format, -1830);

  v_date date;
begin
   select to_date('1311313', 'yymmdd')
     into v_date
     from dual;
exception
  when ex_date_format then
    sop('date format is wrong');
end;
/
于 2013-11-18T07:25:56.780 に答える