Я хотел бы спросить Вас, что именно делает этот PL / SQL-код:

DECLARE
   table_doesnot_exists   EXCEPTION;
   PRAGMA EXCEPTION_INIT (table_doesnot_exists, -942);
BEGIN
   EXECUTE IMMEDIATE 'DROP TABLE TABLE_NAME';
EXCEPTION
   WHEN table_doesnot_exists
   THEN NULL;
END;

Я частично понимаю это, но мне это интересно -942.

1
dziki 11 Фев 2015 в 15:43

2 ответа

Лучший ответ

Я просмотрел и прокомментировал блок. В основном ваш код тестирует настраиваемую обработку ошибок.

DECLARE
  --Define the custom exception
  table_doesnot_exists   EXCEPTION;
  /*
   *In order to use the custom exception we have to declare it (typically used with ORA messages
   *that have no predefined name. Syntax: PRAGMA EXCEPTION_INIT (exception_name, -ORA_ERR_#);
   *In this case: 00942, 00000, "table or view does not exist"
   *Original code cited 942 but the oerr code is actually 00942, the leading 0's in this case are irrelevant
   */
  PRAGMA EXCEPTION_INIT (table_doesnot_exists, -942);
BEGIN
  --Attempt to drop the table
  EXECUTE IMMEDIATE 'DROP TABLE test_table_does_not_exist';
EXCEPTION
  --If the table we attempted does not exist then our custom exception will catch the ORA-00942
  WHEN table_doesnot_exists
  --Now lets throw out a debug output line
  THEN DBMS_OUTPUT.PUT_LINE('table does not exist');
END;
/
4
mmmmmpie 11 Фев 2015 в 15:00

Это просто код исключения Oracle для таблицы не существует

Из документации оракула:

ORA-00942 table or view does not exist

Cause: The table or view entered does not exist, a synonym that is not allowed here was used, or a view was referenced where a table is required. Existing user tables and views can be listed by querying the data dictionary. Certain privileges may be required to access the table. If an application returned this message, the table the application tried to access does not exist in the database, or the application does not have access to it.

Для получения дополнительной информации http://www.techonthenet.com/oracle/errors/ora00942.php < / а>

4
Sibster 11 Фев 2015 в 12:57