SQL*Plus User's Guide and Reference
Release 9.0.1

Part Number A88827-02
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to beginning of chapter Go to next page

Command Reference, 52 of 52


WHENEVER SQLERROR

Syntax

WHENEVER SQLERROR
{EXIT [SUCCESS|FAILURE|WARNING|n|variable|:BindVariable]
[COMMIT|ROLLBACK]|CONTINUE [COMMIT|ROLLBACK|NONE]}

Exits SQL*Plus if a SQL command or PL/SQL block generates an error.

Terms

Refer to the following list for a description of each term or clause:

EXIT [SUCCESS|FAILURE|WARNING|n|variable|:BindVariable]

CONTINUE

COMMIT

ROLLBACK

NONE

Usage

The WHENEVER SQLERROR command is triggered by SQL command or PL/SQL block errors, and not by SQL*Plus command errors.

Examples

The commands in the following command file cause SQL*Plus to exit and return the SQL error code if the SQL UPDATE command fails:

Keyboard icon
WHENEVER SQLERROR EXIT SQL.SQLCODE
UPDATE EMP_DETAILS_VIEW SET SALARY = SALARY*1.1

The following SQL command error causes SQL*Plus to exit and return the SQL error code:

Keyboard icon
WHENEVER SQLERROR EXIT SQL.SQLCODE
select column_does_not_exiSt from dual;

Screen icon
select column_does_not_exist from dual
       *
ERROR at line 1:
ORA-00904: invalid column name

Disconnected from Oracle.....

The following SQL command error causes SQL*Plus to exit and return the value of the variable my_error_var:

Keyboard icon
define my_error_var = 99
WHENEVER SQLERROR EXIT my_error_var
UPDATE non_existed_table set col1 = col1 + 1;

Screen icon
UPDATE NON_EXISTED_TABLE set col1 = col1 + 1
       *
ERROR at line 1:
ORA-00942: table or view does not exist

Disconnected from Oracle.....

The following examples show that the WHENEVER SQLERROR command does not have any effect on SQL*Plus commands, but does on SQL commands and PL/SQL blocks:

Keyboard icon
WHENEVER SQLERROR EXIT SQL.SQLCODE
column LAST_name headIing "Employee Name"

Screen icon
Unknown COLUMN option "headiing"

Keyboard icon
SHOW non_existed_option

Screen icon
Unknown SHOW option "non_exist_option"
Keyboard icon
GET non_existed_file.sql

Screen icon
Unable to open "non_exist_file.sql"

The following PL/SQL block error causes SQL*Plus to exit and return the SQL error code:

Keyboard icon
WHENEVER SQLERROR EXIT SQL.SQLCODE
begin
  SELECT COLUMN_DOES_NOT_EXIST FROM DUAL;
END;
/

Screen icon
SELECT COLUMN_DOES_NOT_EXIST FROM DUAL;
       *
ERROR at line 2:
ORA-06550: line 2, column 10:
PLS-00201: identifier 'COLUMN_DOES_NOT_EXIST' must be declared
ORA-06550: line 2, column 3:
PL/SQL: SQL Statement ignored

Disconnected from Oracle.....


Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 1996-2001, Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback