A script-enabled browser is required for this page to function properly.

EXEC_SQL.LAST_ERROR_MESG built-in function

This procedure returns the text message of the last error code raised on a connection.

Syntax


FUNCTION EXEC_SQL.LAST_ERROR_MESG
[connid IN CONNTYPE]
RETURN VARCHAR2;
  

Parameter

Description

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 connection handle from the cache.

Returns

A string.

Usage notes

Use this function immediately after the EXEC_SQL.PACKAGE_ERROR exception is raised.

Example


/* 
** 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.CURSTYE;
 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;

See also

About the EXEC_SQL built-in package

EXEC_SQL built-in package