Fix issue 413
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index cc9557e..dea08ff 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -528,8 +528,7 @@
 	 */
 	protected function _error_message()
 	{
-		// If the error was during connection, no conn_id should be passed
-		$error = is_resource($this->conn_id) ? oci_error($this->conn_id) : oci_error();
+		$error = self::_get_error_data();
 		return $error['message'];
 	}
 
@@ -542,13 +541,35 @@
 	 */
 	protected function _error_number()
 	{
-		// Same as _error_message()
-		$error = is_resource($this->conn_id) ? oci_error($this->conn_id) : oci_error();
+		$error = self::_get_error_data();
 		return $error['code'];
 	}
 
 	// --------------------------------------------------------------------
 
+	/* Get error data
+	 *
+	 * Used by _error_message() and _error_number()
+	 *
+	 * @return	array
+	 */
+	private function _get_error_data()
+	{
+		$res = NULL;
+		foreach (array('curs_id', 'stmt_id', 'conn_id') as $key)
+		{
+			if (is_resource($this->$key))
+			{
+				$res = $key;
+				break;
+			}
+		}
+
+		return ( ! is_null($res)) ? oci_error($res) : oci_error();
+	}
+
+	// --------------------------------------------------------------------
+
 	/**
 	 * Escape the SQL Identifiers
 	 *