Returns the last Oracle error code raised on a connection.
FUNCTION EXEC_SQL.Last_Error_Code
[Connid IN CONNTYPE]
RETURN PLS_INTEGER;
Connid | Is the handle to the connection you want to use. If you do not specify a connection, EXEC_SQL.Default_Connection retrieves the primary Oracle Developer connection handle from the cache. |
An integer.
Use this function immediately after the EXEC_SQL.Package_Error exception is raised.
/*
** In the following procedure, we execute a statement that is passed in. If there
** are any exceptions shown, we check to see its nature using LAST_ERROR_CODE
** and LAST_ERROR_MESG.
*/
procedure eslastfunccode(sqlstr varchar2) is
connection_id exec_sql.connType;
cursor_number exec_sql.CursType;
sql_str VARCHAR2(256);
nIgnore pls_integer;
BEGIN
connection_id := exec_sql.open_connection('connection_str');
cursor_number := exec_sql.open_cursor(connection_id);
exec_sql.parse(connection_id, cursor_number, sql_str, exec_sql.V7);
nIgnore := exec_sql.execute(connection_id, cursor_number);
exec_sql.close_cursor(connection_id, cursor_number);
exec_sql.close_connection(connection_id);
--
-- check the error in the exception block
--
EXCEPTION
WHEN exec_sql.package_error THEN
text_io.put_line('error :' ||
to_char(exec_sql.last_error_code(connection_id)) || ' ' ||
exec_sql.last_error_mesg(connection_id) );
--
-- ensure that even though an error has occurred, the cursor and connection
-- are closed.
--
IF exec_sql.is_connected(connection_id) THEN
IF exec_sql.is_open(connection_id, cursor_number) THEN
exec_sql.close_cursor(connection_id, cursor_number);
END IF;
exec_sql.close_connection(connection_id);
END IF;
END;