OcilibCApiInitialization
OCILIB provides two mechanisms for error handling:
- Global error handling through callbacks.
- Contextual thread error handling
Exceptions are raised:
- On Oracle OCI API call error
- On Oracle SQL statement error
- On Internal OCILIB error (type checking, memory allocations …)
- On Oracle warnings (OCI API or SQL)
If an error handler was provided to OCI_Initialize(), when an error occurs, the library generates an OCI_Error handle and pass it to the error handler.
In order to use the thread contextual error handling, you must call OCI_Initialize() with the flag OCI_ENV_CONTEXT for the mode parameter. When activated, error handles are stored per thread and the last error within a thread can be retrieved with OCI_GetLastError()
Exception properties are accessible through a set of functions
- Note
- The two ways to handle errors are not exclusive and can be mixed.
- Thread contextual error is also available for single thread based applications
- Oracle Warnings
Oracle warnings are raised through OCI_Error API. Such error handles have their error type property (OCI_ErrorGetType()) set to OCI_ERR_WARNING. Warning handing is disabled by default. To activate/deactivate it, use OCI_EnableWarnings()
- Example with callbacks
-
#include «ocilib.h»
{
printf
(
«code : ORA-%05in»
«msg : %sn»
«sql : %sn»,
);
}
int main(void)
{
{
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
OCI_SYM_PUBLIC OCI_Connection *OCI_API OCI_ConnectionCreate(const otext *db, const otext *user, const otext *pwd, unsigned int mode)
Create a physical connection to an Oracle database server.
struct OCI_Connection OCI_Connection
Oracle physical connection.
struct OCI_Error OCI_Error
Encapsulates an Oracle or OCILIB exception.
OCI_SYM_PUBLIC OCI_Statement *OCI_API OCI_ErrorGetStatement(OCI_Error *err)
Retrieve statement handle within the error occurred.
OCI_SYM_PUBLIC const otext *OCI_API OCI_ErrorGetString(OCI_Error *err)
Retrieve error message from error handle.
OCI_SYM_PUBLIC int OCI_API OCI_ErrorGetOCICode(OCI_Error *err)
Retrieve Oracle Error code from error handle.
OCI_SYM_PUBLIC boolean OCI_API OCI_Cleanup(void)
Clean up all resources allocated by the library.
OCI_SYM_PUBLIC boolean OCI_API OCI_Initialize(POCI_ERROR err_handler, const otext *lib_path, unsigned int mode)
Initialize the library.
OCI_SYM_PUBLIC const otext *OCI_API OCI_GetSql(OCI_Statement *stmt)
Return the last SQL or PL/SQL statement prepared or executed by the statement.
- Example with thread context
-
#include «ocilib.h»
int main(void)
{
if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT | OCI_ENV_CONTEXT))
{
return EXIT_FAILURE;
}
if (cn == NULL)
{
}
return EXIT_SUCCESS;
}
OCI_SYM_PUBLIC OCI_Error *OCI_API OCI_GetLastError(void)
Retrieve the last error or warning occurred within the last OCILIB call.
- Example of warning handling
-
#include «ocilib.h»
{
printf(«%s — %sn», err_type == OCI_ERR_WARNING ? «warning» : «error», err_msg);
}
int main(void)
{
{
return EXIT_FAILURE;
}
cn = OCI_ConnectionCreate(«db», «usr», «expired_pwd_in_grace_period», OCI_SESSION_DEFAULT);
return EXIT_SUCCESS;
}
OCI_SYM_PUBLIC unsigned int OCI_API OCI_ErrorGetType(OCI_Error *err)
Retrieve the type of error from error handle.
OCI_SYM_PUBLIC boolean OCI_API OCI_EnableWarnings(boolean value)
Enable or disable Oracle warning notifications.
Functions |
|
OCI_SYM_PUBLIC boolean OCI_API | OCI_SetErrorHandler (POCI_ERROR handler) |
Set the global error user handler. | |
OCI_SYM_PUBLIC OCI_Error *OCI_API | OCI_GetLastError (void) |
Retrieve the last error or warning occurred within the last OCILIB call. | |
OCI_SYM_PUBLIC const otext *OCI_API | OCI_ErrorGetString (OCI_Error *err) |
Retrieve error message from error handle. | |
OCI_SYM_PUBLIC unsigned int OCI_API | OCI_ErrorGetType (OCI_Error *err) |
Retrieve the type of error from error handle. | |
OCI_SYM_PUBLIC int OCI_API | OCI_ErrorGetOCICode (OCI_Error *err) |
Retrieve Oracle Error code from error handle. | |
OCI_SYM_PUBLIC int OCI_API | OCI_ErrorGetInternalCode (OCI_Error *err) |
Retrieve Internal Error code from error handle. | |
OCI_SYM_PUBLIC OCI_Connection *OCI_API | OCI_ErrorGetConnection (OCI_Error *err) |
Retrieve connection handle within the error occurred. | |
OCI_SYM_PUBLIC OCI_Statement *OCI_API | OCI_ErrorGetStatement (OCI_Error *err) |
Retrieve statement handle within the error occurred. | |
OCI_SYM_PUBLIC unsigned int OCI_API | OCI_ErrorGetRow (OCI_Error *err) |
Return the row index which caused an error during statement execution. | |
OCI_SYM_PUBLIC const otext *OCI_API | OCI_ErrorGetLocation (OCI_Error *err) |
Return the location where the error occured. | |
◆ OCI_SetErrorHandler()
OCI_SYM_PUBLIC boolean OCI_API OCI_SetErrorHandler | ( | POCI_ERROR | handler | ) |
#include <api.h>
Set the global error user handler.
- Parameters
-
handler — Pointer to error handler procedure
- Note
- Use this call to change or remove the user callback error handler installed by OCI_Initialize()
◆ OCI_GetLastError()
OCI_SYM_PUBLIC OCI_Error *OCI_API OCI_GetLastError | ( | void | ) |
#include <api.h>
Retrieve the last error or warning occurred within the last OCILIB call.
- Note
- OCI_GetLastError() is based on thread context and thus OCILIB must be initialized with the flag OCI_ENV_CONTEXT
- Warning
- OCILIB functions that returns a boolean value to indicate their success :
- return TRUE if no error occurred OR if a warning occurred
- return FALSE if an error occurred
Referenced by ocilib::core::Check().
◆ OCI_ErrorGetString()
OCI_SYM_PUBLIC const otext *OCI_API OCI_ErrorGetString | ( | OCI_Error * | err | ) |
#include <api.h>
Retrieve error message from error handle.
- Parameters
◆ OCI_ErrorGetType()
OCI_SYM_PUBLIC unsigned int OCI_API OCI_ErrorGetType | ( | OCI_Error * | err | ) |
#include <api.h>
Retrieve the type of error from error handle.
- Parameters
- Note
- Returns one of the following values:
- OCI_ERR_ORACLE
- OCI_ERR_OCILIB
- OCI_ERR_WARNING
- Returns
- Object type or OCI_UNKNOWN the input handle is NULL
◆ OCI_ErrorGetOCICode()
OCI_SYM_PUBLIC int OCI_API OCI_ErrorGetOCICode | ( | OCI_Error * | err | ) |
#include <api.h>
Retrieve Oracle Error code from error handle.
- Parameters
◆ OCI_ErrorGetInternalCode()
OCI_SYM_PUBLIC int OCI_API OCI_ErrorGetInternalCode | ( | OCI_Error * | err | ) |
#include <api.h>
Retrieve Internal Error code from error handle.
- Parameters
◆ OCI_ErrorGetConnection()
#include <api.h>
Retrieve connection handle within the error occurred.
- Parameters
◆ OCI_ErrorGetStatement()
#include <api.h>
Retrieve statement handle within the error occurred.
- Parameters
- Note
- If the error occurred outside of a statement context, it returns NULL
◆ OCI_ErrorGetRow()
OCI_SYM_PUBLIC unsigned int OCI_API OCI_ErrorGetRow | ( | OCI_Error * | err | ) |
#include <api.h>
Return the row index which caused an error during statement execution.
- Parameters
- Warning
- Row index start at 1.
- Returns
- 0 is the error is not related to array DML otherwise the index of the given row which caused the error
◆ OCI_ErrorGetLocation()
OCI_SYM_PUBLIC const otext *OCI_API OCI_ErrorGetLocation | ( | OCI_Error * | err | ) |
#include <api.h>
Return the location where the error occured.
- Parameters
- Returns
- The method name that has generated the error
- Информация о материале
- Категория: Функции для работы с Oracle
-
Опубликовано: 01 января 2011
-
Просмотров: 376
(PHP 5, PECL oci8:1.1-1.2.4)
oci_error — Возвращает последнюю ошибку
Описание
array oci_error ( [resource $source] )
Для большинства ошибок параметром source является соответствующий идентификатор соединения или выражения. Для ошибок во время выполнения функций oci_connect(), oci_new_connect() и oci_pconnect() этот параметр указывать не следует. oci_error() возвращает последнюю ошибку, которая была обнаружена в указанном ресурсе. В случае, если ошибок не было найдено, oci_error() возвращает FALSE.
oci_error() возвращает ошибку в виде ассоциативного массива из четырех элементов. Элемент code содержит код ошибки Oracle; элемент message — строку с текстом ошибки; sqltext — строка, содержащая выражение SQL, которое вызвало ошибку, а элемент offset — указатель на место в выражении, которое вызвало ошибку.
Замечание: Элементы массива offset и sqltext были добавлены начиная с версии PHP 4.3.
Вывод сообщения при ошибке соединения
$conn = @oci_connect("scott", "tiger", "mydb");
if (!$conn) {
$e = oci_error(); // For oci_connect errors pass no handle
echo htmlentities($e['message']);
}
Вывод сообщения при ошибке парсинга выражения
$stmt = @oci_parse($conn, "select ' from dual"); // note mismatched quote
if (!$stmt) {
$e = oci_parse($conn); // For oci_parse errors pass the connection handle
echo htmlentities($e['message']);
}
Вывод сообщения об ошибке и SQL-выражения, в котором она возникла
$r = oci_execute($stmt);
if (!$r) {
$e = oci_error($stmt); // For oci_execute errors pass the statementhandle
echo htmlentities($e['message']);
echo "<pre>";
echo htmlentities($e['sqltext']);
printf("n%".($e['offset']+1)."s", "^");
echo "</pre>";
}
Замечание: В версиях PHP ниже 5.0.0 эта функция называлась ocierror(). В PHP 5.0.0 и выше ocierror() является алиасом oci_error(), поэтому вы можете продолжать использовать это имя, однако это не рекомендуется.
May 9, 2020
Hi,
You can get ” OCI Error ORA (status = 1034-ORA-01034: ORACLE not available and ORA-27101: shared memory realm does not exist ” error during Dblogin in Goldengate.
Details of error are as follows.
[[email protected] 19.1.0.0.4]$ ./ggsci Oracle GoldenGate Command Interpreter for Oracle Version 19.1.0.0.4 OGGCORE_19.1.0.0.0_PLATFORMS_191017.1054_FBO Linux, x64, 64bit (optimized), Oracle 11g on Oct 17 2019 23:13:12 Operating system character set identified as UTF-8. Copyright (C) 1995, 2019, Oracle and/or its affiliates. All rights reserved. GGSCI (msdbadm01) 1> dblogin userid [email protected], password GoldenGate135246* ERROR: OCI Error ORA (status = 1034-ORA-01034: ORACLE not available ORA-27101: shared memory realm does not exist Linux-x86_64 Error: 2: No such file or directory Process ID: 0 Session ID: 0 Serial number: 0 ). GGSCI (msdbadm01) 2>
This error is related with the missing Oracle SID and Oracle Home, To solve this error add the following lines into parameter file.
SETENV (ORACLE_SID=MSDB) SETENV (ORACLE_HOME=/u01/app/oracle/product/12.2.0/db_home)
Or Check your TNS Alias if it contains correct values for SID and IP.
I have created a static listener for the Goldengate as follows, then use it. Add following statis listener description into listener.ora under $ORACLE_HOME/network/admin. Then start listener.
LISTENER_GG =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.63.35)(PORT = 1521))
)
)
SID_LIST_LISTENER_GG =
(SID_LIST =
(SID_DESC =
(SID_NAME = MSDB1)
(ORACLE_HOME = /u01/app/oracle/product/12.2.0/db_home)
(SERVICE_NAME = MSDB)
)
)
lsnrctl start LISTENER_GG
Now When I try to run dblogin command, it is successful. The problem is related with the registered listener in my case.
So I have created a new static listener, then it works fine as follows.
[[email protected] 19.1.0.0.4]$ ./ggsci Oracle GoldenGate Command Interpreter for Oracle Version 19.1.0.0.4 OGGCORE_19.1.0.0.0_PLATFORMS_191017.1054_FBO Linux, x64, 64bit (optimized), Oracle 11g on Oct 17 2019 23:13:12 Operating system character set identified as UTF-8. Copyright (C) 1995, 2019, Oracle and/or its affiliates. All rights reserved. GGSCI (msdbadm01) 1> dblogin userid [email protected], password GoldenGate135246* Successfully logged into database. GGSCI (msdbadm01 as [email protected]) 2>
Do you want to learn Oracle Goldengate from scratch, then read the following Goldengate Tutorial articles.
Oracle Goldengate Tutorials for Beginners
1,708 views last month, 1 views today
About Mehmet Salih Deveci
I am Founder of SysDBASoft IT and IT Tutorial and Certified Expert about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 10+years experience.I have OCA, OCP, OCE RAC Expert Certificates I have worked 100+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.If you need Oracle DBA, SQL Server DBA, APPS DBA, Exadata, Goldengate, EBS Consultancy and Training you can send my email adress [email protected].- -Oracle DBA, SQL Server DBA, APPS DBA, Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için [email protected] a mail atabilirsiniz.