3.6 Using ERCALLBACK

ERCALLBACK is the basic user exit function for Oracle GoldenGate. It is used to pull the record context into user exit. It's like a package that contains multiple individual functions inside it. You can call these functions and get return values. For example, functions such as GET_BEFORE_AFTER_IND, or GET_COLUMN_VALUE_FROM_NAME can be called. These functions are called function_code.

Syntax

ERCALLBACK (function_code, buffer, result_code );
function_code

The function to be executed by the callback routine. The user callback routine behaves differently based on the function code passed to the callback routine. While some functions can be used for both Extract and Replicat, the validity of the function in one process or the other is dependent on the input parameters that are set for that function during the callback routine. See Function Codes for a full description of available function codes.

buffer

A void pointer to a buffer containing a predefined structure associated with the specified function code.

result_code

The status of the function executed by the callback routine. The result code returned by the callback routine indicates whether or not the callback function was successful. A result code can be one of the values in Table 3-4.

Table 3-4 Result Codes

Code Description

EXIT_FN_RET_BAD_COLUMN_DATA

Invalid data was encountered when retrieving or setting column data.

EXIT_FN_RET_BAD_DATE_TIME

A date, timestamp, or interval type of column contains an invalid date or time value.

EXIT_FN_RET_BAD_NUMERIC_VALUE

A numeric type of column contains an invalid numeric value.

EXIT_FN_RET_COLUMN_NOT_FOUND

The column was not found in a compressed update record (update by a database that only logs the values that were changed).

EXIT_FN_RET_ENV_NOT_FOUND

The specified environment value could not be found in the record.

EXIT_FN_RET_EXCEEDED_MAX_LENGTH

The metadata could not be retrieved because the name of the table or column did not fit in the allocated buffer.

EXIT_FN_RET_FETCH_ERROR

The record could not be fetched. View the error message to see the reason.

EXIT_FN_RET_INCOMPLETE_DDL_REC

An internal error occurred when processing the DDL record. The record is probably incomplete.

EXIT_FN_RET_INVALID_CALLBACK_FNC_CD

An invalid callback function code was passed to the callback routine.

EXIT_FN_RET_INVALID_COLUMN

A non-existent column was referred to in the function call.

EXIT_FN_RET_INVALID_COLUMN_TYPE

The routine is trying to manipulate a data type that is not supported by Oracle GoldenGate for that purpose.

EXIT_FN_RET_INVALID_CONTEXT

The callback function was called at an improper time.

EXIT_FN_RET_INVALID_PARAM

An invalid parameter was passed to the callback function.

EXIT_FN_RET_NO_SRCDB_INSTANCE

The source database instance could not be found.

EXIT_FN_RET_NO_TGTDB_INSTANCE

The target database instance could not be found.

EXIT_FN_RET_NOT_SUPPORTED

This function is not supported for this process.

EXIT_FN_RET_OK

The callback function succeeded.

EXIT_FN_RET_SESSION_CS_CNV_ERR

A ULIB_ERR_INVALID_CHAR_FOUND error was returned to the character-set conversion routine. The conversion failed.

EXIT_FN_RET_TABLE_NOT_FOUND

An invalid table name was specified.

EXIT_FN_RET_TOKEN_NOT_FOUND

The specified user token could not be found in the record.

You can use ERCALLBACK to perform many different function calls. For example, if you want to get the name of a table, you can use the following command:

ERCALLBACK (GET_TABLE_NAME, &var, &result_code)

These functions are used inside the c code for the user exit to perform any of the calls for functions provided in the section Function Codes. With the combination of the different function_code calls, you can perform many tasks using ERCALLBACK, such as:
  • Recreate DML statements
  • Perform transformations
  • Pull specific columns out of a record
  • Write information to a report file

For example, if you need a message written to the report file each time the lag in the heartbeat table exceeds a certain threshold, you could use the CUSEREXIT function. The CUSEREXIT function would then make numerous calls to ERCALLBACK to get the lag column data, perform calculations and the comparison, and if the lag is over the specified threshold then write a message to the report file.