SQL Translation and Migration Guide
SQL Translation and Migration Guide
Release 21c
F31393-01
December 2020
Oracle Database SQL Translation and Migration Guide, Release 21c
F31393-01
Contributors: Tulika Das, Peter Castro, Christopher Jones, Shoaib Lari, Tom Laszewski, Aman Manglik,
Robert Pang, Rajendra Pingte, Jeff D. Smith, Andrei Souleimanian
This software and related documentation are provided under a license agreement containing restrictions on
use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your
license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license,
transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse
engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is
prohibited.
The information contained herein is subject to change without notice and is not warranted to be error-free. If
you find any errors, please report them to us in writing.
If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on
behalf of the U.S. Government, then the following notice is applicable:
U.S. GOVERNMENT END USERS: Oracle programs (including any operating system, integrated software,
any programs embedded, installed or activated on delivered hardware, and modifications of such programs)
and Oracle computer documentation or other Oracle data delivered to or accessed by U.S. Government
end users are "commercial computer software" or "commercial computer software documentation" pursuant
to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such,
the use, reproduction, duplication, release, display, disclosure, modification, preparation of derivative works,
and/or adaptation of i) Oracle programs (including any operating system, integrated software, any programs
embedded, installed or activated on delivered hardware, and modifications of such programs), ii) Oracle
computer documentation and/or iii) other Oracle data, is subject to the rights and limitations specified in the
license contained in the applicable contract. The terms governing the U.S. Government’s use of Oracle cloud
services are defined by the applicable contract for such services. No other rights are granted to the U.S.
Government.
This software or hardware is developed for general use in a variety of information management applications.
It is not developed or intended for use in any inherently dangerous applications, including applications that
may create a risk of personal injury. If you use this software or hardware in dangerous applications, then you
shall be responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure its
safe use. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of this
software or hardware in dangerous applications.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of
their respective owners.
Intel and Intel Inside are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are
used under license and are trademarks or registered trademarks of SPARC International, Inc. AMD, Epyc,
and the AMD logo are trademarks or registered trademarks of Advanced Micro Devices. UNIX is a registered
trademark of The Open Group.
This software or hardware and documentation may provide access to or information about content, products,
and services from third parties. Oracle Corporation and its affiliates are not responsible for and expressly
disclaim all warranties of any kind with respect to third-party content, products, and services unless otherwise
set forth in an applicable agreement between you and Oracle. Oracle Corporation and its affiliates will not
be responsible for any loss, costs, or damages incurred due to your access to or use of third-party content,
products, or services, except as set forth in an applicable agreement between you and Oracle.
Contents
Preface
Audience xi
Related Documents xi
Documentation Accessibility xi
Conventions xi
iii
2 SQL Translation Framework Overview
2.1 Architecture of SQL Translation Framework 2-2
2.2 How to Use SQL Translation Framework 2-2
2.3 When to Use SQL Translation Framework 2-3
iv
5 Example: Application Migration Using SQL Translation Framework
5.1 Migrating a Sybase JDBC Application 5-1
5.1.1 Application Overview 5-1
5.1.2 Setting Up Migration 5-2
5.1.3 Capturing Migration 5-3
5.1.4 Setting Migration Preferences 5-6
5.1.5 Converting Migration 5-7
5.1.6 Generating a Migration 5-9
5.1.6.1 Creating a Target Oracle User 5-10
5.1.7 Moving the Data 5-10
5.2 Generating Migration Reports 5-11
v
7.1.2.11 MYSQL_TYPE_SHORT 7-5
7.1.2.12 MYSQL_TYPE_STRING 7-5
7.1.2.13 MYSQL_TYPE_TIME 7-6
7.1.2.14 MYSQL_TYPE_TIMESTAMP 7-6
7.1.2.15 MYSQL_TYPE_TINY 7-6
7.1.2.16 MYSQL_TYPE_TINY_BLOB 7-6
7.1.2.17 MYSQL_TYPE_VAR_STRING 7-6
7.1.3 Data Type Conversions for MySQL External Data Types (LOB Data
Type Descriptors) 7-7
7.1.4 Data Type Conversions for Datetime and Interval Data Types 7-7
7.2 Error Handling 7-8
7.3 Available Oracle Support for MySQL APIs 7-8
7.3.1 my_init() 7-10
7.3.2 mysql_affected_rows() 7-10
7.3.3 mysql_autocommit() 7-10
7.3.4 mysql_change_user() 7-11
7.3.5 mysql_character_set_name() 7-11
7.3.6 mysql_close() 7-11
7.3.7 mysql_commit() 7-11
7.3.8 mysql_connect() 7-11
7.3.9 mysql_create_db() 7-12
7.3.10 mysql_data_seek() 7-12
7.3.11 mysql_debug() 7-12
7.3.12 mysql_debug_info() 7-12
7.3.13 mysql_drop_db() 7-12
7.3.14 mysql_dump_debug_info() 7-12
7.3.15 mysql_eof() 7-13
7.3.16 mysql_errno() 7-13
7.3.17 mysql_error() 7-13
7.3.18 mysql_escape_string() 7-13
7.3.19 mysql_fetch_field() 7-13
7.3.20 mysql_fetch_field_direct() 7-14
7.3.21 mysql_fetch_fields() 7-14
7.3.22 mysql_fetch_lengths() 7-14
7.3.23 mysql_fetch_row() 7-14
7.3.24 mysql_field_count() 7-14
7.3.25 mysql_field_seek() 7-15
7.3.26 mysql_field_tell() 7-15
7.3.27 mysql_free_result() 7-15
7.3.28 mysql_get_character_set_info() 7-15
7.3.29 mysql_get_client_info() 7-15
vi
7.3.30 mysql_get_client_version() 7-15
7.3.31 mysql_get_host_info() 7-16
7.3.32 mysql_get_proto_info() 7-16
7.3.33 mysql_get_server_info() 7-16
7.3.34 mysql_get_server_version() 7-16
7.3.35 mysql_get_ssl_cipher() 7-16
7.3.36 mysql_hex_string() 7-17
7.3.37 mysql_info() 7-17
7.3.38 mysql_init() 7-17
7.3.39 mysql_insert_id() 7-17
7.3.40 mysql_kill() 7-17
7.3.41 mysql_library_end() 7-17
7.3.42 mysql_library_init() 7-18
7.3.43 mysql_list_dbs() 7-18
7.3.44 mysql_list_fields() 7-19
7.3.45 mysql_list_processes() 7-19
7.3.46 mysql_list_tables() 7-19
7.3.47 mysql_more_results() 7-19
7.3.48 mysql_next_result() 7-19
7.3.49 mysql_num_fields() 7-19
7.3.50 mysql_num_rows() 7-20
7.3.51 mysql_options() 7-20
7.3.52 mysql_ping() 7-20
7.3.53 mysql_query() 7-20
7.3.54 mysql_read_query_result() 7-20
7.3.55 mysql_real_connect() 7-20
7.3.56 mysql_real_escape_string() 7-21
7.3.57 mysql_real_query() 7-21
7.3.58 mysql_refresh() 7-21
7.3.59 mysql_reload() 7-21
7.3.60 mysql_rollback() 7-21
7.3.61 mysql_row_seek() 7-22
7.3.62 mysql_row_tell() 7-22
7.3.63 mysql_select_db() 7-22
7.3.64 mysql_send_query() 7-22
7.3.65 mysql_server_end() 7-22
7.3.66 mysql_server_init() 7-23
7.3.67 mysql_set_character_set() 7-23
7.3.68 mysql_set_local_infile_default() 7-23
7.3.69 mysql_set_local_infile_handler() 7-23
7.3.70 mysql_set_server_option() 7-23
vii
7.3.71 mysql_shutdown() 7-23
7.3.72 mysql_sqlstate() 7-24
7.3.73 mysql_ssl_set() 7-24
7.3.74 mysql_stat() 7-24
7.3.75 mysql_stmt_affected_rows() 7-24
7.3.76 mysql_stmt_attr_get() 7-24
7.3.77 mysql_stmt_attr_set() 7-25
7.3.78 mysql_stmt_bind_param() 7-25
7.3.79 mysql_stmt_bind_result() 7-25
7.3.80 mysql_stmt_close() 7-25
7.3.81 mysql_stmt_data_seek() 7-25
7.3.82 mysql_stmt_errno() 7-25
7.3.83 mysql_stmt_error() 7-25
7.3.84 mysql_stmt_execute() 7-26
7.3.85 mysql_stmt_fetch() 7-26
7.3.86 mysql_stmt_fetch_column() 7-26
7.3.87 mysql_stmt_field_count() 7-26
7.3.88 mysql_stmt_free_result() 7-26
7.3.89 mysql_stmt_init() 7-26
7.3.90 mysql_stmt_insert_id() 7-27
7.3.91 mysql_stmt_next_result() 7-27
7.3.92 mysql_stmt_num_rows() 7-27
7.3.93 mysql_stmt_param_count() 7-27
7.3.94 mysql_stmt_param_metadata() 7-27
7.3.95 mysql_stmt_prepare() 7-27
7.3.96 mysql_stmt_reset() 7-28
7.3.97 mysql_stmt_result_metadata() 7-28
7.3.98 mysql_stmt_row_seek() 7-28
7.3.99 mysql_stmt_row_tell() 7-28
7.3.100 mysql_stmt_send_long_data() 7-28
7.3.101 mysql_stmt_sqlstate() 7-28
7.3.102 mysql_stmt_store_result() 7-29
7.3.103 mysql_store_result() 7-29
7.3.104 mysql_thread_end() 7-29
7.3.105 mysql_thread_id() 7-29
7.3.106 mysql_thread_init() 7-29
7.3.107 mysql_thread_safe() 7-30
7.3.108 mysql_use_result() 7-30
7.3.109 mysql_warning_count() 7-30
viii
8 API Reference for SQL Translation of JDBC Applications
8.1.1 Translation Properties 8-1
8.1.1.1 sqlTranslationProfile 8-1
8.1.1.2 sqlErrorTranslationFile 8-2
8.1.2 OracleTranslatingConnection Interface 8-2
8.1.2.1 SqlTranslationVersion 8-3
8.1.2.2 createStatement() 8-3
8.1.2.3 prepareCall() 8-7
8.1.2.4 prepareStatement() 8-9
8.1.2.5 getSQLTranslationVersions() 8-13
8.1.3 Error Translation Configuration File 8-13
Glossary
Index
ix
List of Tables
1-1 Supported Applications in Databases 1-10
1-2 Supported Database Versions for Migration Using Oracle SQL Developer 1-10
7-1 Mapping Oracle Data Types to MySQL Data Types 7-1
7-2 Converting MySQL Program Variable Data Types to Oracle Column Data Types 7-2
7-3 Data Type Conversions for LOB Data Type Descriptors 7-7
7-4 Data Conversions for Datetime and Internal Data Type 7-7
8-1 Translation Properties 8-1
8-2 OracleTranslatingConnection Enumeration 8-2
8-3 OracleTranslatingConnection Methods 8-3
x
Preface
This guide describes the installation, configuration, and administration tasks for all
activities related to migrating applications developed for non-Oracle databases, such
as DB2, MySQL, Sybase, and legacy applications, to Oracle Database. This guide
also provides migration scenarios that users may implement in sequence.
Audience
This guide is for database administrators and application developers who are
interested in migrating from databases other than Oracle to an Oracle Database.
Related Documents
For more information, see the following documents in the Oracle Database
documentation set:
• Oracle Database SQL Language Reference
• Oracle Database Administrator's Guide
• Oracle Database Development Guide
• Oracle Database Reference
Documentation Accessibility
For information about Oracle's commitment to accessibility, visit the
Oracle Accessibility Program website at http://www.oracle.com/pls/topic/lookup?
ctx=acc&id=docacc.
Conventions
The following text conventions are used in this document:
Convention Meaning
boldface Boldface type indicates graphical user interface elements associated
with an action, or terms defined in text or the glossary.
xi
Preface
Convention Meaning
italic Italic type indicates book titles, emphasis, or placeholder variables for
which you supply particular values.
monospace Monospace type indicates commands within a paragraph, URLs, code
in examples, text that appears on the screen, or text that you enter.
xii
1
Introduction to Tools and Products that
Support Migration
Before migrating your application to Oracle Database, you must be aware of several
key points that are described in Oracle Database Concepts.
When discussing the migration of a database-centered enterprise, it is useful to keep
in mind that the actual migration of database schema and data is only a part of the
process. The migration of a core business solution often involves several databases
and applications that work together to deliver the product and services that drive the
revenue of an organization. For more information about preparing a migration plan,
see Oracle SQL Developer User's Guide.
1-1
Chapter 1
Oracle Database Features for Migration Support
• It enables the enterprise to reuse the same application to use data stored in both
MySQL Database and Oracle Database
• It reduces the cost and complexity of migrating MySQL applications to Oracle
Database
Oracle Database supports all MySQL functions in the client interface with the same
semantics.
1-2
Chapter 1
Oracle Database Features for Migration Support
For information about the DBMS_SQL package, see Oracle Database PL/SQL Packages
and Types Reference. For information about how to use format output, SQL*Plus
User's Guide and Reference.
1-3
Chapter 1
Oracle Database Features for Migration Support
c2 sys_refcursor;
begin
open c1 for select * from hr.employees;
dbms_sql.return_result(c1); --return to client
-- open 1 more cursor
open c2 for select * from hr.departments;
dbms_sql.return_result (c2); --return to client
end;
The following code demonstrates how to retrieve the implicit results returned by
PL/SQL procedures using the JDBC getMoreResults methods:
String sql = "begin foo; end;";
...
Connection conn = DriverManager.getConnection(jdbcURL, user, password);
try {
Statement stmt = conn.createStatement ();
stmt.executeQuery (sql);
while (stmt.getMoreResults())
{
ResultSet rs = stmt.getResultSet();
System.out.println("ResultSet");
while (rs.next())
{
/* get results */
}
}
}
See Also:
Oracle Call Interface Programmer's Guide
1-4
Chapter 1
Oracle Database Features for Migration Support
1-5
Chapter 1
Oracle Database Features for Migration Support
SQLFreeConnect (hdbc);
SQLFreeEnv (henv);
1-6
Chapter 1
Oracle Database Features for Migration Support
• Boolean
• Record declared in a package specification
• Collection declared in a package specification
The SQL TABLE operator is also enhanced, so that you can query on PL/SQL
collections of locally scoped types as an argument to TABLE operator. Here, the
collections can be of nested table types, VARRAY, or PL/SQL index table that are
indexed by PLS_INTEGER.
This feature extends the flexibility of the TABLE operator, and enables easy migration of
non-Oracle stored procedure code to PL/SQL.
1.1.6 Native SQL Support for Query Row Limits and Row Offsets
Starting with Oracle Database 12c, Oracle provides a row limiting clause that enables
native SQL support for query row limits and row offsets. If your application has queries
that limit the number of rows returned or offset the starting row of the results, this
feature significantly reduces SQL complexity for such queries.
1-7
Chapter 1
Oracle Database Features for Migration Support
See Also:
If you require support for translation of Oracle errors (ORA errors) to your the
native database, once your application starts running against Oracle Database, then
you must enable the SQLTranslateErrors=T entry in the .odbc.ini file. See "SQL
Translation of ODBC Applications" for more information on this topic.
1-8
Chapter 1
Other Oracle Products that Enable Migration
1-9
Chapter 1
Migration Support for Other Database Vendors
Table 1-2 Supported Database Versions for Migration Using Oracle SQL
Developer
1-10
2
SQL Translation Framework Overview
Various client-side applications, designed to work with non-Oracle Databases, cannot
be used with Oracle Database without significant alterations. This is because SQL
dialect varies among vendors of database technologies and different vendors use
different syntaxes to express SQL queries and statements.
Starting with Oracle Database 12c, there is a new mechanism called SQL Translation
Framework. It translates the SQL statements of a client program from a foreign (non-
Oracle) SQL dialect into the SQL dialect used by the Oracle Database SQL compiler.
In addition to translating non-Oracle SQL statements, the SQL Translation Framework
may be used to substitute an Oracle SQL statement with another Oracle statement to
address a semantic or performance issue. In this way, you can address an application
issue without patching the client application.
The SQL translation framework consists of two basic components: SQL Translator,
and SQL Translation Profile.
2-1
Chapter 2
Architecture of SQL Translation Framework
SQL Translation
Framework
Oracle Database
Non-Oracle SQL
SQL Translator
SQL
Results
Application Translation
Profile
2-2
Chapter 2
When to Use SQL Translation Framework
5. Test all functionality of the application against Oracle Database. As the application
runs, the SQL Translation Profile translates SQL statements of the application
from the third-party SQL dialect to semantically-equivalent Oracle syntax and
register them in the profile.
If the translator does not have a translation for a particular SQL statement or error,
then you may register your own translation to fill its place.
6. Verify the custom translations and edit them, if required. Alternatively, register new
ones to ensure that the application performs as intended, until testing is complete.
Oracle recommends establishing a test environment and rigorously testing the
application, ideally through a regression test suite.
7. Set up the server-side application objects and data in the production Oracle
Database for deployment to a production environment.
8. Create a database service with the profile set as a service attribute and change
the connection settings of the application, so that it connects to the database
service in the production database. The application is expected to run as tested.
Oracle recommends that the application be monitored to guard against the possibility
of errors due to unavailability of translation of any SQL statement. You must first
disable the automatic translation of new and unseen SQL statements in the profile;
when any such statement is encountered, it raises an error that is logged. In cases of
alerts for mis-translation, you must make adjustments to the profile.
See Also:
2-3
Chapter 2
When to Use SQL Translation Framework
• If the application uses ODBC, JDBC, OLE DB or .NET driver, or data provider
to connect to the database, then the driver or data provider for Oracle must be
replaced.
• If the application uses MySQL client library to connect to MySQL, then the library
with Mysql Client Library Driver for Oracle must be replaced.
• No direct translator is available for DB2. For more information, refer to "Migration
Support for Other Database Vendors".
If the application uses IBM DRDA network protocol to connect to DB2, then the
database connection settings must be changed to connect to Oracle through
DRDA Application Server for Oracle.
• If the application uses a vendor-proprietary C client API (the case of Sybase), then
the API calls must be replaced with appropriate Oracle OCI APIs.
2-4
3
SQL Translation Framework Configuration
The SQL Translation Framework may be installed and configured using Oracle SQL
Developer, or from the command line interface. In either case, the user must have the
necessary permissions to install SQL Translator.
3-1
Chapter 3
Installing and Configuring SQL Translation Framework with Oracle SQL Developer
3-2
Chapter 3
Installing and Configuring SQL Translation Framework with Oracle SQL Developer
You can use the following command to check the database you are connected to and
the JDBC driver being used:
show jdbc
3-3
Chapter 3
Installing and Configuring SQL Translation Framework with Oracle SQL Developer
3. In the Scratch Editor toolbar, select Sybase T_SQL To PL/SQL option, which is
the Sybase translator.
3-4
Chapter 3
Installing and Configuring SQL Translation Framework with Oracle SQL Developer
4. In the left panel of the Scratch Editor, enter the following query in Sybase SQL
dialect:
select top 10 * from dual
5. Click the Translate icon.
The translated query text is displayed in the right panel of the editor.
3-5
Chapter 3
Installing and Configuring SQL Translation Framework with Oracle SQL Developer
5. In the Select Connection box, select the connection if you want to use an existing
connection. If you want to create a new connection, then add the information for
transluser discussed in step 2.
3-6
Chapter 3
Installing and Configuring SQL Translation Framework with Oracle SQL Developer
6. Click Connect.
7. In the DBA navigator, right-click the connection created in the preceding steps,
and select Install SQL Translator.
3-7
Chapter 3
Installing and Configuring SQL Translation Framework with Oracle SQL Developer
11. To ensure that both the Profile and Translator are properly installed, verify whether
the appropriate package and Java class files are present or not in the Connections
pane.
3-8
Chapter 3
Installing and Configuring SQL Translation Framework with Oracle SQL Developer
4. Click SYBASE_PROFILE and select the SQL Translation tab to inspect the profile and
view the translated statement.
An alternative way to view the profile SQL in a better way when you double-click
on it, the fingerprint and template open in a Translation Scratch Editor as shown in
the following images:
3-9
Chapter 3
Installing and Configuring SQL Translation Framework from Command Line
3-10
Chapter 3
Installing and Configuring SQL Translation Framework from Command Line
3-11
Chapter 3
Granting Necessary Permissions for Installing the SQL Translator
3-12
Chapter 3
Granting Necessary Permissions for Installing the SQL Translator
3-13
4
SQL Translation of JDBC and ODBC
Applications
Oracle provides SQL Translation mechanisms for use with JDBC and ODBC
applications.
When necessary, you can register custom translations of SQL statements and errors
with the SQL Translation Profile on the Server. When a SQL statement or error is
translated, then first, the custom translation is looked up and then, the translator is
invoked only if no match is found.
See "Architecture of SQL Translation Framework" and "Setting up a SQL Translation
Profile".
4-1
Chapter 4
SQL Translation of JDBC Applications
Here, the naming format for the parameter markers is :b<n>, where n is an incremental
number to specify the position of the (?) marker in the JDBC PreparedStatement.
After conversion, the driver sends the following query to the server for translation:
UPDATE employees SET salary = salary * :b1 WHERE employee_id = :b2
Note that any query that contains "?" as a parameter marker fails during the
connection translation phase if you change the value of the processEscapes property
to FALSE. For a successful translation, you must retain the default value of the
processEscapes property.
Converting parameter markers helps the driver to automatically reorder any parameter
changes that occurred at translation. At the time of conversion, any custom translation
that must be registered on the server should be registered from the Oracle style
parameter marker version; the server receives the statements. Note that, the custom
translation must have the same number of parameter markers in the Oracle style as in
the original query.
For more information about supported JDBC APIs, API Reference for SQL Translation
of JDBC Applications .
4-2
Chapter 4
SQL Translation of JDBC Applications
Note that the JDBC driver can support the translation errors (when the query cannot
be translated due to the unavailability of translation) set by either value of the
DBMS_SQL_TRANSLATOR.ATTR_RAISE_TRANSLATION_ERROR attribute. However, the value
must be set on the server before the connection is established. Because a change in
the value of this attribute in the middle of a session may result in inconsistent behavior,
Oracle recommends that you do not flip the value of this attribute during a session.
See Oracle Database PL/SQL Packages and Types Reference for more information
about the TRANSLATE_SQL procedure.
Now, connect to the database as HR and execute the following SQL statements:
drop table sample_tab;
create table sample_tab (c1 number, c2 varchar2(100));
insert into sample_tab values (1, 'A');
insert into sample_tab values (1, 'A');
insert into sample_tab values (1, 'A');
commit;
exec dbms_sql_translator.drop_profile('FOO');
exec dbms_sql_translator.create_profile('FOO');
exec dbms_sql_translator.register_sql_translation('FOO','select row of select
c1, c2 from sample_tab
where c1=:b1 and c2=:b2','select c1, c2 from sample_tab where c1=:b1 and
c2=:b2');
Now, you can run the following program that translates SQL statements that use JDBC
standard parameter markers.
Example 4-1 Translating Non-Oracle SQL Statements to Oracle SQL Dialect
Using JDBC Driver
public class SQLTransPstmt
{
static String url="jdbc:oracle:thin:@localhost:5521:jvx1";
4-3
Chapter 4
SQL Translation of ODBC Applications
try{
// Any statements created using a translating connection are
// automatically translating. If you want to get a non-translating
// statement out of a translating connection please have a look at
// the oracle.jdbc.OracleTranslatingConnection Interface.
// Refer to "OracleTranslatingConnection Interface"
// for more information
PreparedStatement trStmt = conn.prepareStatement(primitiveSql);
trStmt.setInt(1, 1);
trStmt.setString(2, "A");
System.out.println("executeQuery for: "+primitiveSql);
ResultSet trRs = trStmt.executeQuery();
while (trRs.next())
System.out.println("C1:"+trRs.getInt(1)+", C2:"+trRs.getString(2));
trRs.close();
trStmt.close();
}catch (Exception e) {
e.printStackTrace();
}
conn.close();
}
}
4-4
Chapter 4
SQL Translation of ODBC Applications
Note that you must set the ServerName= entry in the .odbc.ini file with the Database
service name created in "How to Use SQL Translation Framework" section. Also,
set the 'SQLTranslateErros=T entry in the .odbc.ini file, if you require translation of
Oracle errors to native database errors.
Example 4-2 Translating Non-Oracle SQL to Oracle SQL Dialect Using ODBC
Driver
int main()
{
HENV m_henv; /* environment handle */
HDBC m_hdbc; /* connection handle */
HSTMT m_hstmt; /* statement handle */
int retCode; /* return code */
char dbdsn[100]; /* Initialize with the DSN name of connection */
const char szUID[10];/*Initialize with appropriate Username of DB */
const char szPWD[10]; /* Initialize with appropriate Password */
4-5
Chapter 4
SQL Translation of ODBC Applications
{
printf ("SQLAllocHandle failed\n");
printSQLError (2, m_hdbc);
}
retCode=SQLExecute(m_hstmt);
if (retCode != SQL_SUCCESS && retCode != SQL_SUCCESS_WITH_INFO)
{
printf ("SQLExecute-failed\n");
printSQLError (3, m_hstmt);
}
printf ("cleanup()\n");
retCode = SQLFreeHandle (SQL_HANDLE_STMT, m_hstmt);
if (retCode != SQL_SUCCESS && retCode != SQL_SUCCESS_WITH_INFO)
{
printf ("SQLFreeHandle failed\n");
printSQLError (3, m_hstmt);
}
4-6
Chapter 4
SQL Translation of ODBC Applications
4-7
5
Example: Application Migration Using SQL
Translation Framework
Consider an example of migrating a Sybase JDBC Application, and the information
contained in the migration reports: how it may be used to tune the migration for optimal
results.
Sybase SQL
Oracle
Translation Profile
Oracle
Sybase Sybase SQL
ODBC/JDBC
App Translation Profile
Driver
Custom Error-Code
Mappings
5-1
Chapter 5
Migrating a Sybase JDBC Application
5-2
Chapter 5
Migrating a Sybase JDBC Application
9. Connect to the database as the migrep user and associate the migration
repository with the user, as shown in Figure 5-3.
5-3
Chapter 5
Migrating a Sybase JDBC Application
5-4
Chapter 5
Migrating a Sybase JDBC Application
3. Enter a project name and specify an output directory to place files, as shown in
Figure 5-8.
Click Next.
4. Select the database connection and the mode, as shown in Figure 5-9.
Click Next.
5-5
Chapter 5
Migrating a Sybase JDBC Application
The capture phase saves a snapshot of the selected database at this point of time.
Only the object definitions are captured, not the actual table data. This captured
snapshot can be viewed in the Migration Projects navigator.
Note that the snapshot is not a connection to the database, and it only enables you to
browse through the information saved in the Migration Repository.
5-6
Chapter 5
Migrating a Sybase JDBC Application
2. From the Tools menu, select Preferences, then Migration, and then Generation
Options. Select the Use all Oracle Database 12c features in Migration option.
5-7
Chapter 5
Migrating a Sybase JDBC Application
The Migration Wizard is opened at the Convert phase, as shown in Figure 5-14.
5-8
Chapter 5
Migrating a Sybase JDBC Application
Note that the converted model is not an actual Oracle database, but a prototype of an
Oracle Database. The information is still stored only in the Migration Repository tables.
5-9
Chapter 5
Migrating a Sybase JDBC Application
The database objects are not created under the connection selected in this step.
However, this connection must have enough privileges to create other users and
objects.
5-10
Chapter 5
Generating Migration Reports
Figure 5-18 Moving the Data from Sybase Database to Oracle Database
2. Select online as the data move mode in the Move Data screen.
You can select offline as the data move mode if the migration process involves
large amount of data.
3. Click Next. The Summary screen appears.
4. Click Finish.
You can browse the database objects to verify the data is moved to Oracle
database.
See Also:
Oracle SQL Developer User's Guide
5-11
Chapter 5
Generating Migration Reports
The Analysis report provides information about the size of the migrated database like
the number of objects, line sizes, and so on, as shown in Figure 5-20.
The Target Status report provides information about the status of the migrated objects
in the Target database. First, select a target connection with enough privileges to view
the status of other schema objects and then select refresh. Objects that are present
in the converted model, but are missing from the target Oracle Database, are listed as
missing. These objects can be either valid or invalid.
5-12
Chapter 5
Generating Migration Reports
The Data Quality tab provides information about the number of rows in the target
Oracle Database compared with the source database. Perform the following steps to
compare the databases:
1. Select a converted model, a source connection, and a target connection.
2. Click Analyse.
3. Click Refresh.
This performs a count(*) function on each table in the source and the target
database. So, it is advisable not to perform this operation on production data.
5-13
6
MySQL Client Library Driver for Oracle
Consider the specifics of MySQL Client Library Driver for Oracle Database, and its use
in migrating applications from MySQL to Oracle.
The MySQL Client Library Driver for Oracle is deprecated in Oracle Database 20c.
See Also:
API Reference for Oracle MySQL Client Library Driver for more information
about MySQL programmatic support
Application Application
using using
MySQL’s C API MySQL’s C API
liboramysql
libmysqlclient
OCI
MySQL DB Oracle DB
The C code snippet in Example 6-1 demonstrates how to connect to MySQL and
how to insert a row into a table. After updating the connection credentials, this code
6-1
Chapter 6
Installation and First Use of MySQL Client Library Driver for Oracle
can run unchanged against Oracle Database when the executable is linked using the
liboramysql library, instead of the libmysqlclient library.
Although the database schema and data must be migrated to Oracle separately, and
although the liboramysql library does not translate SQL statements, considerable
amount of effort is conserved when migrating to Oracle Database because no changes
have to be made to the application code.
Custom C applications can use the liboramysql library to easily migrate to Oracle
Database.
Additionally, you can migrate applications using programming languages that abstract
the use of the libmysqlclient library and provide MySQL extensions or adapters.
These languages include PHP, Perl, Python, and Ruby. Although native Oracle
adapters already exist for many programming languages implemented in C, migrating
an application to a native Oracle adapter often requires extensive application code
changes.
The driver must be installed in the same directory as the Oracle Client Shared Library,
that is, libclntsh.so for Linux and oci.dll for Windows. Typically, you must set
the operating system environment variable (LD_LIBRARY_PATH on Linux or PATH on
Windows) to include this installation directory.
For ORACLE_HOME installations, the driver library is installed in the $ORACLE_HOME/lib
directory for Linux and the %ORACLE_HOME%\bin directory for Windows. For Instant
Client ZIP files, the library is in the instantclient_12_1 directory. For Instant
Client RPM installations, the library is in the /usr/lib/oracle/12.1/client/lib
or /usr/lib/oracle/12.1/client64/lib directory on 32-bit and 64-bit Linux
platforms, respectively.
6-2
Chapter 6
Overview of Migration with MySQL Client Library Driver for Oracle
6-3
Chapter 6
Using MySQL Client Library Driver for Oracle
application, or by using a SQL Translator. The application schema and data must also
be migrated separately. Oracle SQL Developer automates this process.
Whenever cross-version OCI connectivity exists for older versions of Oracle Database,
you can use the liboramysql driver to connect to these older versions.
Depending on the application, you can use one or more of the following ways to relink
the application with the liboramysql library:
6-4
Chapter 6
Using MySQL Client Library Driver for Oracle
6.4.5 Globalization
The date format expected by the application may be set using NLS_DATE_FORMAT
environment variable of Oracle Database, or changed with the equivalent ALTER
SESSION command after connecting. The NLS_DATE_FORMAT environment variable is
only used if NLS_LANG is also set in the environment.
6-5
7
API Reference for Oracle MySQL Client
Library Driver
Consider the APIs that support migration from MySQL, the mapping of data types,
support for specific MySQL APIs within Oracle, and error handling for migrated
applications..
For documentation of MySQL C APIs, refer to MySQL 5.5 documentation.
It is recommended that users use this table when migrating MySQL applications to
Oracle. The MySQL Client Library driver for Oracle will perform Data type conversions
between MySQL and Oracle.
7-1
Chapter 7
Mapping Data Types
Table 7-1 (Cont.) Mapping Oracle Data Types to MySQL Data Types
7.1.2 Data Type Conversions for MySQL Program Variable Data Types
The calls to mysql_stmt_bind_param() and mysql_stmt_bind_result() may be used to
convert between C program variables and database column values. Similarly, OCI
provides rich conversion support from server data types to many client data types.
Input conversions from a C program value to a database column value are handled by
invoking mysql_stmt_bind_param(). Output to a C program value is handled through a
call to mysql_stmt_bind_result().
Table 7-2 summarizes viable conversions between MySQL program variable data
types and Oracle column data types. The possible values in the table are:
• I: input conversion is supported
• O: output conversion is supported
• I/O: both input and output conversion is supported
• -: conversion is not supported.
Be sure to read the corresponding notes for each data type before finalizing
conversion choices.
Table 7-2 Converting MySQL Program Variable Data Types to Oracle Column Data Types
MySQL Program CHAR VARCHAR2 NUMBER LONG ROWID UROWID DATE RAW LONG
Variable Data Types RAW
MYSQL_TYPE_TINY I/O I/O I/O I - - - - -
7-2
Chapter 7
Mapping Data Types
Table 7-2 (Cont.) Converting MySQL Program Variable Data Types to Oracle Column Data Types
MySQL Program CHAR VARCHAR2 NUMBER LONG ROWID UROWID DATE RAW LONG
Variable Data Types RAW
MYSQL_TYPE_SHOR I/O I/O I/O I - - - - -
T
MYSQL_TYPE_LONG I/O I/O I/O I - - - - -
MYSQL_TYPE_LONG I/O I/O I/O I - - - - -
LONG
MYSQL_TYPE_FLOA I/O I/O I/O I - - - - -
T
MYSQL_TYPE_DOUB I/O I/O I/O I - - - - -
LE
MYSQL_TYPE_DATE I/O I/O - I - - I/O - -
MYSQL_TYPE_TIME I/O I/O - I - - I/O - -
MYSQL_TYPE_DATE I/O I/O - I - - I/O - -
TIME
MYSQL_TYPE_TIME I/O I/O - I - - I/O - -
STAMP
MYSQL_TYPE_STRI I/O I/O I/O I/O I/O I/O I/O I/O I/O
NG
MYSQL_TYPE_VAR_ O O O O O O O O O
STRING
MYSQL_TYPE_BLOB I/O I/O - I/O - - - I/O I/O
MYSQL_TYPE_TINY_ O O - O - - - O O
BLOB
MYSQL_TYPE_MEDI O O - O - - - O O
UM_BLOB
MYSQL_TYPE_LONG O O - O - - - O O
_BLOB
MYSQL_TYPE_NEW O O O - - - - - -
DECIMAL
7.1.2.1 MYSQL_TYPE_BLOB
• CHAR and VARCHAR2: Conversion is valid for input or output. On input, column value
is stored in hexadecimal format.
• LONG: Conversion is valid for input or output. On input, column value is stored in
hexadecimal format.
• RAW: Conversion is valid for input or output.
• LONG RAW: Conversion is valid for input or output.
• Conversion is not supported for NUMBER, ROWID, UROWID, and DATE.
7-3
Chapter 7
Mapping Data Types
7.1.2.2 MYSQL_TYPE_DATE
• CHAR and VARCHAR2: Conversion is valid for input or output. For input, host string
must be in Oracle DATE character format. For output, column value is returned in
Oracle DATE format.
• DATE: Conversion is valid for input or output.
• LONG: Conversion valid for input to database column value.
• Conversion not supported for NUMBER, ROWID, UROWID, RAW, and LONG RAW.
7.1.2.3 MYSQL_TYPE_DATETIME
• CHAR and VARCHAR2: Conversion is valid for input or output. For input, host string
must be in Oracle DATE character format. For output, column value is returned in
Oracle DATE format.
• DATE: Conversion is valid for input or output.
• LONG: Conversion valid for input to database column value.
• Conversion not supported for NUMBER, ROWID, UROWID, RAW, and LONG RAW.
7.1.2.4 MYSQL_TYPE_DOUBLE
• CHAR and VARCHAR2: Conversion is valid for input or output. For output, column
value must represent a valid number.
• NUMBER: Conversion is valid for input or output.
• LONG: Conversion valid for input to database column value.
• Conversion not supported for ROWID, UROWID, DATE, RAW, and LONG RAW.
7.1.2.5 MYSQL_TYPE_FLOAT
• CHAR and VARCHAR2: Conversion is valid for input or output. For output, column
value must represent a valid number.
• NUMBER: Conversion is valid for input or output.
• LONG: Conversion valid for input to database column value.
• Conversion not supported for ROWID, UROWID, DATE, RAW, and LONG RAW.
7.1.2.6 MYSQL_TYPE_LONG
• CHAR and VARCHAR2: Conversion is valid for input or output. For output, column
value must represent a valid number.
• NUMBER: Conversion is valid for input or output.
• LONG: Conversion valid for input to database column value.
• Conversion not supported for ROWID, UROWID, DATE, RAW, and LONG RAW.
7-4
Chapter 7
Mapping Data Types
7.1.2.7 MYSQL_TYPE_LONG_BLOB
• CHAR, VARCHAR2, LONG, RAW, and LONG RAW: Conversion is valid for output.
• Conversion is not supported for NUMBER, ROWID, UROWID, and DATE.
7.1.2.8 MYSQL_TYPE_LONGLONG
• CHAR and VARCHAR2: Conversion is valid for input or output. For output, column
value must represent a valid number.
• NUMBER: Conversion is valid for input or output.
• LONG: Conversion valid for input to database column value.
• Conversion not supported for ROWID, UROWID, DATE, RAW, and LONG RAW.
7.1.2.9 MYSQL_TYPE_MEDIUM_BLOB
• CHAR, VARCHAR2, LONG, RAW, and LONG RAW: Conversion is valid for output.
• Conversion is not supported for NUMBER, ROWID, UROWID, and DATE.
7.1.2.10 MYSQL_TYPE_NEWDECIMAL
• CHAR and VARCHAR2: Conversion is valid for output. Column value must represent a
valid number.
• NUMBER: Conversion is valid for output to C program value.
• Conversion is not supported for LONG, ROWID, UROWID, DATE, RAW, and LONG RAW.
7.1.2.11 MYSQL_TYPE_SHORT
• CHAR and VARCHAR2: Conversion is valid for input or output. For output, column
value must represent a valid number.
• NUMBER: Conversion is valid for input or output.
• LONG: Conversion valid for input to database column value.
• Conversion not supported for ROWID, UROWID, DATE, RAW, and LONG RAW.
7.1.2.12 MYSQL_TYPE_STRING
• CHAR and VARCHAR2: Conversion is valid for input or output.
• NUMBER: Conversion is valid for input or output. For input, the host string must
represent a valid number.
• LONG: Conversion valid for input or output.
• ROWID: Conversion is valid for input or output. For input, the host string must be in
Oracle ROWID format. For output, column value is returned in Oracle ROWID format.
• UROWID: Conversion is valid for input or output. For input, the host string must be
in Oracle UROWID format. For output, column value is returned in Oracle UROWID
format.
7-5
Chapter 7
Mapping Data Types
• DATE: Conversion is valid for input or output. For input, host string must be in
Oracle DATE character format. For output, column value is returned in Oracle DATE
format.
• RAW: Conversion is valid for input or output. For input, host string must be in
hexadecimal format.
• LONG RAW: Conversion is valid for input or output. For input, host string must be in
hexadecimal format.
7.1.2.13 MYSQL_TYPE_TIME
• CHAR and VARCHAR2: Conversion is valid for input or output. For input, host string
must be in Oracle DATE character format. For output, column value is returned in
Oracle DATE format.
• DATE: Conversion is valid for input or output.
• LONG: Conversion valid for input to database column value.
• Conversion not supported for NUMBER, ROWID, UROWID, RAW, and LONG RAW.
7.1.2.14 MYSQL_TYPE_TIMESTAMP
• CHAR and VARCHAR2: Conversion is valid for input or output. For input, host string
must be in Oracle DATE character format. For output, column value is returned in
Oracle DATE format.
• DATE: Conversion is valid for input or output.
• LONG: Conversion valid for input to database column value.
• Conversion not supported for NUMBER, ROWID, UROWID, RAW, and LONG RAW.
7.1.2.15 MYSQL_TYPE_TINY
• CHAR and VARCHAR2: Conversion is valid for input or output. For output, column
value must represent a valid number.
• NUMBER: Conversion is valid for input or output.
• LONG: Conversion valid for input to database column value.
• Conversion not supported for ROWID, UROWID, DATE, RAW, and LONG RAW.
7.1.2.16 MYSQL_TYPE_TINY_BLOB
• CHAR, VARCHAR2, LONG, RAW, and LONG RAW: Conversion is valid for output.
• Conversion is not supported for NUMBER, ROWID, UROWID, and DATE.
7.1.2.17 MYSQL_TYPE_VAR_STRING
• CHAR and VARCHAR2: Conversion is valid for output to C program value.
• NUMBER: Conversion is valid for output to C program value.
• LONG: Conversion is valid for output to C program value.
7-6
Chapter 7
Mapping Data Types
• ROWID: Conversion is valid for output to C program value. On output, column value
is returned in Oracle ROWID format.
• UROWID: Conversion is valid for output to C program value. On output, column
value is returned in Oracle UROWID format.
• DATE: Conversion is valid for output to C program value. On output, column value
is returned in Oracle DATE format.
• RAW: Conversion is valid for output to C program value.
• LONG RAW: Conversion is valid for output to C program value.
7.1.3 Data Type Conversions for MySQL External Data Types (LOB
Data Type Descriptors)
The external data types Table 7-3 may be converted to the specified Oracle internal
data types.
Table 7-3 Data Type Conversions for LOB Data Type Descriptors
7.1.4 Data Type Conversions for Datetime and Interval Data Types
When working with a DATETIME or INTERVAL columns, it is possible to use one of the
character data types to define a host variable used in a FETCH or INSERT operation
The driver automatically converts between the character data type and DATETIME or
INTERVAL data type.
Table 7-4 lists external data types that may be converted to the specified internal
Oracle data types.
Table 7-4 Data Conversions for Datetime and Internal Data Type
7-7
Chapter 7
Error Handling
Table 7-4 (Cont.) Data Conversions for Datetime and Internal Data Type
• 00000 success
• HY000 all other errors
However, this also means that client applications that expect more specific SQLSTATE
errors must be partially re-written.
7-8
Chapter 7
Available Oracle Support for MySQL APIs
Connection Management
The following interfaces support connection management:
my_init(), mysql_change_user(), mysql_close(), mysql_connect(),
mysql_get_character_set_info(), mysql_get_ssl_cipher(), mysql_init(), mysql_options(),
mysql_ping(), mysql_real_connect(), mysql_select_db(), mysql_set_character_set(),
andmysql_ssl_set().
Error Reporting
The following interfaces support error reporting: mysql_errno(), mysql_error(),
andmysql_sqlstate()
Prepared Statements
The following interfaces support statement preparation: mysql_stmt_affected_rows(),
mysql_stmt_attr_get(), mysql_stmt_attr_set(), mysql_stmt_bind_param(),
mysql_stmt_bind_result(), mysql_stmt_close(), mysql_stmt_data_seek(),
mysql_stmt_errno(), mysql_stmt_error(), mysql_stmt_execute(), mysql_stmt_fetch(),
mysql_stmt_fetch_column(), mysql_stmt_field_count(), mysql_stmt_free_result(),
mysql_stmt_init(), mysql_stmt_insert_id(), mysql_stmt_next_result(),
mysql_stmt_num_rows(), mysql_stmt_param_count(), mysql_stmt_param_metadata(),
mysql_stmt_prepare(), mysql_stmt_reset(), mysql_stmt_result_metadata(),
mysql_stmt_row_seek(), mysql_stmt_row_tell(), mysql_stmt_send_long_data(),
mysql_stmt_sqlstate(), and mysql_stmt_store_result().
Transaction Control
The following interfaces support transaction control: mysql_autocommit(),
mysql_commit(), and mysql_rollback().
Information Routines
The following interfaces support information routines: mysql_character_set_name(),
mysql_get_client_info(), mysql_get_client_version(), mysql_get_host_info(),
mysql_get_proto_info(), mysql_get_server_info(), mysql_get_server_version(),
mysql_info(), mysql_stat(), mysql_thread_id(), and mysql_warning_count().
7-9
Chapter 7
Available Oracle Support for MySQL APIs
Administrative Routines
The following interfaces support administrative routines:
mysql_refresh(), mysql_set_server_option(), mysql_set_local_infile_default(),
mysql_set_local_infile_handler(), and mysql_shutdown().
Miscellaneous Routines
The following interfaces support all remaining routines:
mysql_create_db(), mysql_debug(), mysql_debug_info(), mysql_drop_db(),
mysql_dump_debug_info(), mysql_read_query_result(), mysql_send_query(),
mysql_thread_end(), mysql_thread_init(), and mysql_thread_safe().
7.3.1 my_init()
This function is a no-op function. It is called by my_init macro in my_sys.h file. All
initializations are done by the mysql_library_init().
Return Value
0
7.3.2 mysql_affected_rows()
Returns the number of rows processed for INSERT, UPDATE, and DELETE statements
executed.
For UPDATE statements, note that the semantics of MySQL do not report rows where
the new value is the same as the old value. In contrast, Oracle reports that rows are
affected, even if the new value is the same as the old value. This function implements
Oracle semantics. Therefore, existing applications that rely on this call may have to
make programmatic changes.
For SELECT statement, the return is (my_ulonglong) -1.
Return Value
A number of rows that were processed by DML statement; >0. 0 indicates no updates
were made by the statement. -1 indicates that the statement was a query (SELECT), or
an error.
7.3.3 mysql_autocommit()
Sets auto commit mode to ON or OFF.
Return Value
0, if the auto commit mode is changed successfully. Non-zero if an error occurred in
the process.
7-10
Chapter 7
Available Oracle Support for MySQL APIs
7.3.4 mysql_change_user()
Changes the user, including user name, password, and database on the same or
different host. In Oracle Database 12c, change of the database is not supported, so
the value entered for the db parameter is ignored.
A call to mysql_change_user() rolls back any active transactions, ends the current
session, and then re-establishes a new connection based on information stored in the
host parameter.
Existing applications must make necessary application logic changes to implement this
behavior in Oracle Database 12c.
Return Value
0 if connection can be reestablished with the original host for the supplied user name
and password. Non-zero if an error occurred.
7.3.5 mysql_character_set_name()
Not supported in Oracle Database 12c. Applications that rely on results of this call
must change their application logic.
Return Value
Empty string.
7.3.6 mysql_close()
Closes the connection and frees all associated data structures.
Return Value
none
7.3.7 mysql_commit()
Commits the transaction currently associated with the service context.
A mysql_commit() call supports the default mode in Oracle Database 12c. It therefore
ignores the completion type system variable.
Existing applications that use this API to perform MySQL-specific completion type
operations must change their application logic.
Return Value
0 if successful, non-zero otherwise.
7.3.8 mysql_connect()
Deprecated; use mysql_real_connect().
7-11
Chapter 7
Available Oracle Support for MySQL APIs
Return Value
Initialized MYSQL structure. NULL if an error occurred.
7.3.9 mysql_create_db()
Not supported in Oracle Database 12c. Applications that rely on results of this call
must change their application logic.
Return Value
0 if successful; non-zero if an invalid MYSQL structure is passed in.
7.3.10 mysql_data_seek()
Seeks to a row in a result set based on the value specified in the offset parameter.
Offset value, being a row number, can range from 0 to mysql_num_rows(result) -1.
Return Value
None
7.3.11 mysql_debug()
Not supported in Oracle Database 12c. Applications that rely on results of this call
must change their application logic.
7.3.12 mysql_debug_info()
Not supported in Oracle Database 12c. Applications that rely on results of this call
must change their application logic.
Return Value
0 if successful; non-zero if invalid MYSQL structure.
7.3.13 mysql_drop_db()
Not supported in Oracle Database 12c. Applications that rely on results of this call
must change their application logic.
Return Value
0 if successful; non-zero if invalid MYSQL structure.
7.3.14 mysql_dump_debug_info()
Not supported in Oracle Database 12c. Applications that rely on results of this call
must change their application logic.
Return Value
0 if successful; non-zero if an invalid MYSQL structure is passed in.
7-12
Chapter 7
Available Oracle Support for MySQL APIs
7.3.15 mysql_eof()
DEPRECATED. Use mysql_errno() or mysql_error() instead.
Determines if the last row of a result set has been read.
Return Value
1 if fetched the last row; otherwise 0.
7.3.16 mysql_errno()
Returns Oracle error number of the last error on the connection or the global context.
If the previous call did not have an established connection, pass in NULL; this returns
the last error number on global context.
Return Value
Last error number on the MYSQL connection, or the last error number on the global
context.
7.3.17 mysql_error()
Returns Oracle error messages for the last error on the connection or the global
context.
If the previous call did not have an established connection, pass in NULL; this returns
the last error message on global context.
Return Value
Last error message on the MYSQL connection, or the last error message on the global
context.
7.3.18 mysql_escape_string()
Encodes the string in the source (from parameter), places it in the destination (to
parameter), and appends a terminating NULL.
Supports encoding of only one character, '\' using the current character set in the
connection.
See mysql_real_escape_string().
Return Value
The length of the value placed into to, excluding the terminating NULL.
7.3.19 mysql_fetch_field()
Returns the definition of one column of a result set as a MYSQL_FIELD structure.
Only the following attributes of the MYSQL_FIELD structure are supported: flag, name,
name_length, org_name, org_name_length, type, and max_length.
7-13
Chapter 7
Available Oracle Support for MySQL APIs
• The flag attribute supports only the following values: NOT_NULL_FLAG, NUM_FLAG,
and BINARY_FLAG.
• The attribute org_name is set to have the same value as name attribute.
• The attribute org_name_length is set to have the same value as name_length
attribute.
Return value
The MYSQL_FIELD structure for the current column. NULL if no columns are left.
7.3.20 mysql_fetch_field_direct()
Retrieves the column's field definition for a specified field number as a MYSQL_FIELD
structure.
Return Value
Field definition for the specific field. NULL if an error occurred, or if field number
fieldnr is not in range.
7.3.21 mysql_fetch_fields()
Returns an array of all MYSQL_FIELD structures for a result set. Each MYSQL_FIELD
structure gives the field definition for one column of the result set.
Return Value
NULL if an error occurred.
7.3.22 mysql_fetch_lengths()
Returns an array of lengths of the column on the current row.
Return Value
An array of unsigned long integers that represent the size of each column. NULL if an
error occurred.
7.3.23 mysql_fetch_row()
Retrieves the next row of a result set.
Return Value
A MYSQL_ROW structure for the next row. NULL if there are no more rows to retrieve
or if an error occurred.
7.3.24 mysql_field_count()
Returns the number of columns in the result set for the recent query on the
connection.
7-14
Chapter 7
Available Oracle Support for MySQL APIs
Return Value
Number of fields in the result set within the MYSQL structure.; 0 if an error occurred.
7.3.25 mysql_field_seek()
Sets the field cursor to the specified offset.
Return Value
The offset to the field set
7.3.26 mysql_field_tell()
Returns the position of the field; used for the current field.
Return Value
Offset of the current field
7.3.27 mysql_free_result()
Frees the memory allocated for the result set.
Return Value
None
7.3.28 mysql_get_character_set_info()
Not supported in Oracle Database 12c. Applications that rely on results of this call
must change their application logic.
Return Value
None
7.3.29 mysql_get_client_info()
Returns MySQL version number defined by MYSQL_SERVER_VERSION macro in
mysql_version.h header file, in string format. The macro definition is used in the
mysql_version.h file that builds oramysql library; it is not the mysql_version.h file
used by the application.
Return Value
A character string that represents MySQL client library version.
7.3.30 mysql_get_client_version()
Returns current MySQL version, as defined by MYSQL_VEERSION_ID macro in the
mysql_version.h header file. The macro definition is used in the mysql_version.h
7-15
Chapter 7
Available Oracle Support for MySQL APIs
file that builds oramysql library; it is not the mysql_version.h file used by the
application.
Return Value
An unsigned long integer for MySQL version stored in the MYSQL_VERSION_ID macro.
The macro definition is used in the mysql_version.h file that builds oramysql library;
it is not the mysql_version.h file used by the application.
7.3.31 mysql_get_host_info()
Returns the host name used to connect to the database.
Return Value
A character string of host name. NULL in case of an error.
7.3.32 mysql_get_proto_info()
This is a no-op under Oracle environment. Applications that rely on results of this call
must change their application logic.
Return Value
0
7.3.33 mysql_get_server_info()
Returns the Oracle server version in text string format, such as "12.1.0.1.0".
Applications that rely on results of this call must change their application logic.
Return Value
A character string that represents Oracle Server Number. NULL if an error occurred.
7.3.34 mysql_get_server_version()
Returns Oracle Database version number, such as 120100. This is in integer XXYYZZ
format, where XX represents the major version, YY represents the minor version, and
ZZ represents the version within the release level.
Return Value
Oracle Database version number. 0 if an error occurred.
7.3.35 mysql_get_ssl_cipher()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
NULL
7-16
Chapter 7
Available Oracle Support for MySQL APIs
7.3.36 mysql_hex_string()
Encodes string specified by from parameter to hexadecimal format. Each character is
encoded as two hexadecimal digits. The result is placed in the to parameter, with a
terminal NULL byte.
Return Value
Length of the value placed into to parameter, excluding the terminating NULL character.
7.3.37 mysql_info()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
NULL
7.3.38 mysql_init()
Allocates a MYSQL structure if NULL is passed. Otherwise, this call initializes the passed
in MYSQL structure.
Return Value
Initialized MYSQL structure. NULL if MYSQL structure cannot be allocated or initialized.
7.3.39 mysql_insert_id()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
0
7.3.40 mysql_kill()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
0, and non-zero if an invalid MYSQL structure is passed in.
7.3.41 mysql_library_end()
Terminates oramysql library.
7-17
Chapter 7
Available Oracle Support for MySQL APIs
Return Value
none
7.3.42 mysql_library_init()
Initializes oramysql library.
Return Value
0 if successful, non-zero in case of a failure to initialize MySQL library.
7.3.43 mysql_list_dbs()
Returns a list of database names that match the wild parameter on the server.
To use this API, the DBA creates the oramysql_dbs_view view, and grants privileges to
PUBLIC.
When connecting to Oracle Database 12c and subsequent versions, use the following
SQL script to create the view oramysql_dbs_view in Oracle Database 12c:
create view oramysql_dbs_view(name) as select left.name from v$pdbs left
union select right.name from v$database right;
create public synonym oramysql_dbs_view for oramysql_dbs_view;
grant select on oramysql_dbs_view to public;
If the view does not exist, the wild parameter is ignored, and the call executes the
following SQL statement:
select SYS_CONTEXT( 'USERENV', 'DB_NAME') from DUAL;
Return Value
NULL if an error occurs, a MYSQL_RES result set if successful.
7-18
Chapter 7
Available Oracle Support for MySQL APIs
7.3.44 mysql_list_fields()
Returns the column names that match the wild parameter for a specified table.
Return Value
NULL if an error occurred, a MySql result set if successful.
7.3.45 mysql_list_processes()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
NULL
7.3.46 mysql_list_tables()
This is a no-op function. Applications that rely on results of this call must change their
application logic.
Return Value
NULL
7.3.47 mysql_more_results()
Verifies if more results are available from the currently executing statement.
Return Value
TRUE if more results exist; FALSE if no more result sets exist.
7.3.48 mysql_next_result()
Gets the next result set.
Returns Value
0 if successful and there are more results; -1 if successful and there are no more
results; >0 if an error occurred.
7.3.49 mysql_num_fields()
Returns the number of columns in a result set.
Return Value
An unsigned integer that represents the number of columns in the result set; returns 0
if not successful.
7-19
Chapter 7
Available Oracle Support for MySQL APIs
7.3.50 mysql_num_rows()
Returns the number of rows in the result set.
Return Value
The number of rows in the result set; otherwise 0.
7.3.51 mysql_options()
This is a no-op function. Applications that rely on results of this call must change their
application logic.
Return Value
0 if successful, non-zero if an invalid MYSQL structure is passed in.
7.3.52 mysql_ping()
If the server cannot be accessed, returns an error with connection failure details.
Return Value
0 if success, non-zero if error occurred.
7.3.53 mysql_query()
Executes the SQL statement pointed to by the null-terminated string.
Return Value
0 if successful, non-zero if an error occurred.
7.3.54 mysql_read_query_result()
This is a no-op function; query results from mysql_send_query() are available when
that call completes.
Return Value
0
7.3.55 mysql_real_connect()
The db parameter is not used in Oracle Database 12c. Existing applications using this
parameter to connect to a db must supply the connection identifier or service name in
the host parameter. The connection string has the following format:
[//]host[:port][/service_name][:server][/instance_name]
7-20
Chapter 7
Available Oracle Support for MySQL APIs
The parameters db, port, unix_socket, and client_flag are not in use. When the
user must specify the port, it has to be in the syntax method used for host parameter.
Return Value
MYSQL structure initialized if successful. NULL in case initialization does not work.
7.3.56 mysql_real_escape_string()
Encodes the string in the source (from parameter) and the result is placed in the
destination (to parameter) and a terminating null byte is appended.
Note that only single-quote characters are escaped. Each single-quote is escaped
using Oracle semantics. The to buffer should have a minimum size of length*2+1
bytes. Each single quote in the original string is replaced by two consecutive single
quotes.
See mysql_escape_string().
Return Value
The length of the value placed into to buffer, excluding the terminating NULL. 0
otherwise.
7.3.57 mysql_real_query()
This function executes the query string.
Return Value
0 if successful, non-zero in case of an error.
7.3.58 mysql_refresh()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
0 if successful. Non-zero if an invalid MySQL structure was passed in.
7.3.59 mysql_reload()
Reloads the grant tables. This function is deprecated, and has not been implemented.
Use mysql_query() instead. Applications that rely on results of this call must change
their application logic.
7.3.60 mysql_rollback()
Rolls back the current transaction defined as the set of statements executed after the
last mysql_commit() or mysql_real_connect() call. If the application is running under
object mode, the modified or updated objects in the object cache for this transaction
are also rolled back.
7-21
Chapter 7
Available Oracle Support for MySQL APIs
Existing applications that use this API to perform MySQL-specific completion type
operations must change their application logic.
Return Value
Error if an attempt is made to roll back a global transaction that is not currently active.
7.3.61 mysql_row_seek()
Sets to a particular row and returns offset of previous row.
Return Value
Offset of previous row in MYSQL_ROW_OFFSET structure.
7.3.62 mysql_row_tell()
Gives the current row position in the result set.
Return Value
Offset of current row in MYSQL_ROW_OFFSET structure. NULL if an error occurred.
7.3.63 mysql_select_db()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
0
7.3.64 mysql_send_query()
Sends a query. This function is not asynchronous in oramysql library. Instead, the call
blocks until the query is executed.
Return Value
0 if successful, non-zero if an error occurred.
7.3.65 mysql_server_end()
Terminates and cleans up oramysql library.
Return Value
none
7-22
Chapter 7
Available Oracle Support for MySQL APIs
7.3.66 mysql_server_init()
Initializes the oramysql client library before any connections are created. The function
mysql_library_init() macro is defined to be mysql_server_init() in mysql.h
header file. This call is not thread-safe. Only one thread is expected to call it.
Return Value
0 if successful, non-zero if an error occurred.
7.3.67 mysql_set_character_set()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
0
7.3.68 mysql_set_local_infile_default()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
0
7.3.69 mysql_set_local_infile_handler()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
0
7.3.70 mysql_set_server_option()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
0
7.3.71 mysql_shutdown()
Helps shutdown an Oracle Database instance. Before using the mysql_shutdown API,
the C program must connect to server with SYSDBA or SYSOPER session.
7-23
Chapter 7
Available Oracle Support for MySQL APIs
Return Value
0 if successful. Non-zero if an error occurred.
7.3.72 mysql_sqlstate()
Returns SQLSTATE string which is not null-terminated. There are many SQLSTATE codes
in MySQL which are not in use.
Return Value
SQLSTATE code: 00000 - Success, or HY000 - All other errors.
7.3.73 mysql_ssl_set()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
0 if successful. Non-zero if an invalid MYSQL structure was passed.
7.3.74 mysql_stat()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
A string of 4 blanks (" ") if successful. NULL if an invalid MYSQL structure was passed.
7.3.75 mysql_stmt_affected_rows()
This function returns the number of rows affected by the execution on the prepared
statement.
Return Value
Number of rows affected by the DML operation if successful. (my_ulonglong)-1 if an
error occurred, or a SELECT statement was executed.
7.3.76 mysql_stmt_attr_get()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
0
7-24
Chapter 7
Available Oracle Support for MySQL APIs
7.3.77 mysql_stmt_attr_set()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
0
7.3.78 mysql_stmt_bind_param()
This function binds all the parameters in the prepared statement.
Return Value
0 if parameters are bound successfully. Non-zero if an error occurred.
7.3.79 mysql_stmt_bind_result()
Binds program variables for all SELECT list columns of a prepared statement.
Return Value
0 if successful. Non-zero if an error occurred.
7.3.80 mysql_stmt_close()
Closes a MYSQL_STMT object.
Return Value
0
7.3.81 mysql_stmt_data_seek()
This function seeks to get data for a particular row.
Return Value
None
7.3.82 mysql_stmt_errno()
Returns error number for the last error that occurred on the MYSQL_STMT object.
Return Value
none
7.3.83 mysql_stmt_error()
This function returns error message for the last error that occurred on the MYSQL_STMT
object.
7-25
Chapter 7
Available Oracle Support for MySQL APIs
Return Value
A const *char error message.
7.3.84 mysql_stmt_execute()
This function executes the prepared statement.
Return Value
0 if the statement executed successfully; non-zero if an error occurred.
7.3.85 mysql_stmt_fetch()
This function fetches one row in program variables bound by the
mysql_stmt_bind_result call.
Return Value
0 if one row is successfully fetched. MYSQL_NO_DATA if no more rows/data exists.
MYSQL_DATA_TRUNCATED if data truncation occurred. 1 if an error occurred.
7.3.86 mysql_stmt_fetch_column()
This function fetches one column from the current result set row.
Return Value
0 if the value was fetched successfully. Non-zero if an error occurred.
7.3.87 mysql_stmt_field_count()
Fetches the number of fields in the MYSQL_STMT object.
Return Value
0 if an error occurred; otherwise, the number of fields in the result set associated with
the MYSQL_STMT object.
7.3.88 mysql_stmt_free_result()
Frees the result set associated with the MYSQL_STMT object.
Return Value
0
7.3.89 mysql_stmt_init()
Creates a new MYSQL_STMT object from the MYSQL connection object.
7-26
Chapter 7
Available Oracle Support for MySQL APIs
Return Value
MYSQL_STMT object if successful. NULL if an error occurred.
7.3.90 mysql_stmt_insert_id()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
0
7.3.91 mysql_stmt_next_result()
This function is not implemented. Applications that rely on results of this call must
change their application logic.
Return Value
0
7.3.92 mysql_stmt_num_rows()
Returns the number of rows in a stored result set. In case of a non-stored (unbuffered
result set), it returns the total number of rows fetched so far.
Return Value
0 if an error occurred in fetching the number of rows.
7.3.93 mysql_stmt_param_count()
Returns the number of bind parameters in the prepared statement.
Return Value
0 if an error occurred in returning the number of bind parameters.
7.3.94 mysql_stmt_param_metadata()
This function is cast to MySql result set (MYSQL_RES *) NULL
Return Value
NULL
7.3.95 mysql_stmt_prepare()
Prepares a statement in the MYSQL_STMT for execution.
Return Value
0 if successful, non-zero if an error occurred.
7-27
Chapter 7
Available Oracle Support for MySQL APIs
7.3.96 mysql_stmt_reset()
Resets the prepared statement in the MYSQL_STMT.
Return Value
0
7.3.97 mysql_stmt_result_metadata()
Returns the metadata for the result of a SELECT statement that is executed through a
MYSQL_STMT object.
Return Value
A result set that describes the metadata of the prepared SELECT statement. NULL if an
error occurred.
7.3.98 mysql_stmt_row_seek()
Seeks to a row position and returns the offset of the previous row.
Return Value
An offset of the previous row in MYSQL_ROW_OFFSET structure.
7.3.99 mysql_stmt_row_tell()
Gives the current row position in the result set.
Return Value
Current row position. NULL if an error occurred.
7.3.100 mysql_stmt_send_long_data()
Sends parameter data to the server in parts.
The function mysql_stmt_bind_param() must be called first, then
mysql_stmt_send_long_data(), followed by mysql_stmt_execute().
The function can be called multiple times to send parts of a character or binary data
value for a column.
Return Value
0 if the data is sent to the server successfully, non-zero if an error occurred.
7.3.101 mysql_stmt_sqlstate()
Returns SQLSTATE string for the recent prepared statement. There are many SQLSTATE
codes in MySQL that are not used.
7-28
Chapter 7
Available Oracle Support for MySQL APIs
Return Value
SQLSTATE codes: "00000" - Success, or "HY0000" - All other errors.
7.3.102 mysql_stmt_store_result()
Stores the result set from the last query.
If the last query was a SELECT, a result set is returned. If the last statement was a
non-SELECT or error, a NULL result set is returned.
Return Value
A valid result set if successful, NULL if an error occurred, or a non-SELECT statement.
7.3.103 mysql_store_result()
Stores the result set from the last query.
If the last query was SELECT, returns a result set.
If the last statement was a non-SELECT or an error, a NULL result set is returned.
Return Value
A valid result set if successful; otherwise, NULL for errors or non-SELECT statements.
7.3.104 mysql_thread_end()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
none
7.3.105 mysql_thread_id()
Returns Oracle session identifier (SID) for the connection. This is obtained internally
by executing the following SQL statement:
select SYS_CONTEXT('USERENV', 'SID') from DUAL;
Applications that rely on results of this call must change their application logic.
Return Value
Oracle session identifier (SID). 0 if an error occurs.
7.3.106 mysql_thread_init()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
7-29
Chapter 7
Available Oracle Support for MySQL APIs
Return Value
0
7.3.107 mysql_thread_safe()
The oramysql library is thread-safe, so this function always returns TRUE.
Return Value
TRUE
7.3.108 mysql_use_result()
Initiates a result set retrieval.
Return Value
NULL if an error occurred, a valid result set if successful.
7.3.109 mysql_warning_count()
This is a no-op API. Applications that rely on results of this call must change their
application logic.
Return Value
0 if successful, non-zero if an error occurred.
7-30
8
API Reference for SQL Translation of
JDBC Applications
Consider the APIs that are part of the oracle.jdbc package, specifically the
elements of oracle.jdbc that assist in SQL translation. To successfully migrate JDBC
applications, it is important to understand the translation properties, interfaces, and the
error translation mechanisms.
See Also:
Property Description
sqlTranslationProfile Specifies the name of the transaction profile
sqlErrorTranslationFile Specifies the path of the SQL error translation file
8.1.1.1 sqlTranslationProfile
The property oracle.jdbc.sqlTranslationProfile specifies the name of the
transaction profile.
Declaration
oracle.jdbc.sqlTranslationProfile
Constant
OracleConnection.CONNECTION_PROPERTY_SQL_TRANSLATON_PROFILE
Property Value
The value is a string. There is no default value.
8-1
Chapter 8
OracleTranslatingConnection Interface
Remarks
The property sqlTranslationProfile can be set as either a system property or a
connection property. The property is required to use SQL translation. If this property is
set then all statements created by the connection have SQL translation enabled unless
otherwise specified.
8.1.1.2 sqlErrorTranslationFile
The property oracle.jdbc.sqlErrorTranslationFile specifies the path of the SQL
error translation file.
Declaration
oracle.jdbc.sqlErrorTranslationFile
Constant
Oracle.connection.CONNECTION_PROPERTY_SQL_ERROR_TRANSLATION_FILE.
Property Value
The value is a path name. It has no default value.
Exceptions
An error in establishing a connection results in a SQLException but without a valid
connection. However the SQL error translation file path is available either as a system
property or connection property and will be used to translate the error.
Remarks
This file is used only for translating errors which occur when connection establishment
fails. Once the connection is established this file is bypassed and is not considered
even if it contains the translation details for any error which occurs after the connection
is established. The property sqlErrorTranslationFile can be either a system
property or a connection property. The content of this file is used to translate Oracle
SQLExceptions into foreign SQLExceptions when there is no valid connection.
Name Description
SqlTranslationVersion Provides the Keys to the map
8-2
Chapter 8
OracleTranslatingConnection Interface
Name Description
createStatement() Creates a Statement object with option to translate or not
translate SQL.
prepareCall() Creates a CallableStatement object with option to translate
or not translate SQL.
prepareStatement() Creates a PreparedStatement object with option to translate
or not translate SQL.
getSQLTranslationVersions() Returns a map of all the translation versions of the query during
SQL Translation.
8.1.2.1 SqlTranslationVersion
The SqlTranslationVersion enumerated values specify the keys to the
getSQLTranslationVersions() method.
Syntax
public enum SqlTranslationVersion {
ORIGINAL_SQL,
JDBC_MARKER_CONVERTED,
TRANSLATED
}
The following table lists all the SqlTranslationVersion enumeration values with a
description of each enumerated value.
8.1.2.2 createStatement()
This group of methods create a Statement object, and specify whether the statement
supports SQL translation. If the value of parameter translating is TRUE, then the
returning statement supports translation and is identical to the corresponding version
in the java.sql.Connection interface without the translating argument. If the value is
FALSE, then the returning statement does not support translation.
8-3
Chapter 8
OracleTranslatingConnection Interface
Syntax Description
Creates a Statement object with option to
public Statement createStatement(
boolean translating) translate or not translate SQL.
throws SQLException;
Parameters
Parameter Description
Specifies the int value representing the result set type.
resultSetType
Return Value
The createStatement() method returns a Statement object.
Exceptions
The createStatement() method throws SQLException.
Example
Import the following packages before running the example:
import java.sql.*;
import java.util.Properties;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.OracleTranslatingConnection;
import oracle.jdbc.pool.OracleDataSource;
8-4
Chapter 8
OracleTranslatingConnection Interface
conn system/manager;
grant create sql translation profile to HR;
conn username/pwd;
drop table sample_tab;
create table sample_tab (c1 number, c2 varchar2(100));
insert into sample_tab values (1, 'A');
insert into sample_tab values (2, 'B');
commit;
exec dbms_sql_translator.drop_profile('FOO');
exec dbms_sql_translator.create_profile('FOO');
exec dbms_sql_translator.register_sql_translation('FOO','select row of (c1, c2)
from sample_tab','select c1, c2 from sample_tab');
try{
OracleTranslatingConnection trConn = (OracleTranslatingConnection) conn;
System.out.println("Call:
oracle.jdbc.OracleTranslatingConnection.createStatement(true)");
Statement trStmt = trConn.createStatement(true);
System.out.println("executeQuery for: "+primitiveSql);
ResultSet trRs = trStmt.executeQuery(primitiveSql);
while (trRs.next())
System.out.println("C1:"+trRs.getInt(1)+", C2:"+trRs.getString(2));
trRs.close();
trStmt.close();
}catch (Exception e) {
e.printStackTrace();
}
try{
OracleTranslatingConnection trConn = (OracleTranslatingConnection) conn;
System.out.println("Call:
oracle.jdbc.OracleTranslatingConnection.createStatement(false)");
Statement trStmt = trConn.createStatement(false);
System.out.println("executeQuery for: "+primitiveSql);
ResultSet trRs = trStmt.executeQuery(primitiveSql);
while (trRs.next())
System.out.println("C1:"+trRs.getInt(1)+", C2:"+trRs.getString(2));
8-5
Chapter 8
OracleTranslatingConnection Interface
trRs.close();
trStmt.close();
}catch (Exception e) {
System.out.println("expected Exception: "+e.getMessage());
}
try{
OracleTranslatingConnection trConn = (OracleTranslatingConnection) conn;
System.out.println("Call: oracle.jdbc.OracleTranslatingConnection.
createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE,
true)");
Statement trStmt = trConn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE, true);
System.out.println("executeQuery for: "+primitiveSql);
ResultSet trRs = trStmt.executeQuery(primitiveSql);
while (trRs.next())
System.out.println("C1:"+trRs.getInt(1)+", C2:"+trRs.getString(2));
System.out.println("move resultset back to 2nd row...");
trRs.absolute(2);
while (trRs.next())
System.out.println("C1:"+trRs.getInt(1)+", C2:"+trRs.getString(2));
trRs.close();
trStmt.close();
}catch (Exception e) {
e.printStackTrace();
}
try{
conn.setAutoCommit(false);
OracleTranslatingConnection trConn = (OracleTranslatingConnection) conn;
System.out.println("Call:
oracle.jdbc.OracleTranslatingConnection.createStatement(ResultSet.TYPE_SCROLL_SEN
SITIVE, ResultSet.CONCUR_UPDATABLE,
ResultSet.HOLD_CURSORS_OVER_COMMIT, true)");
Statement trStmt = trConn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT, true);
System.out.println("executeQuery for: "+primitiveSql);
ResultSet trRs = trStmt.executeQuery(primitiveSql);
trRs.last();
System.out.println("C1:"+trRs.getInt(1)+", C2:"+trRs.getString(2));
trRs.updateString(2, "Hello");
trRs.updateRow();
conn.commit();
System.out.println("accept the update and list all of the rows again...");
trRs.beforeFirst();
while (trRs.next())
System.out.println("C1:"+trRs.getInt(1)+", C2:"+trRs.getString(2));
trRs.close();
trStmt.close();
}catch (Exception e) {
e.printStackTrace();
}
conn.close();
}
}
8-6
Chapter 8
OracleTranslatingConnection Interface
8.1.2.3 prepareCall()
This group of methods create a CallableStatement object, and specify whether the
statement supports SQL translation. If the value of parameter translating is TRUE,
then the returning statement supports translation. If the value is FALSE, then the
returning statement does not support translation.
Syntax Description
Creates a CallableStatement object with
public CallableStatement prepareCall(
String sql, option to translate or not translate SQL
boolean translating)
throws SQLException;
Parameters
Parameter Description
sql Specifies the String SQL statement value to be sent to the
database; may contain one or more parameters
Specifies the int value representing the result set type
resultSetType
Return Value
The prepareCall() method returns a CallableStatement object.
Exceptions
The prepareCall() method throws SQLException.
8-7
Chapter 8
OracleTranslatingConnection Interface
Example
Import the following packages before running the example:
import java.sql.*;
import java.util.Properties;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.OracleTranslatingConnection;
import oracle.jdbc.pool.OracleDataSource;
conn username/pwd;
exec dbms_sql_translator.drop_profile('FOO');
exec dbms_sql_translator.create_profile('FOO');
exec dbms_sql_translator.register_sql_translation('FOO', 'exec
sample_proc(:b1, :b2)', '{call sample_proc(:b1, :b2)}');
try{
OracleTranslatingConnection trConn = (OracleTranslatingConnection) conn;
System.out.println(
"Call: oracle.jdbc.OracleTranslatingConnection.prepareCall(sql, true)");
CallableStatement trStmt = trConn.prepareCall(primitiveSql, true);
trStmt.setInt("b1", 1);
trStmt.setString("b2", "A");
trStmt.registerOutParameter("b2", Types.VARCHAR);
8-8
Chapter 8
OracleTranslatingConnection Interface
trStmt.close();
}catch (Exception e) {
e.printStackTrace();
}
try{
OracleTranslatingConnection trConn = (OracleTranslatingConnection) conn;
System.out.println(
"Call: oracle.jdbc.OracleTranslatingConnection.prepareCall(sql, false)");
CallableStatement trStmt = trConn.prepareCall(primitiveSql, false);
trStmt.setInt(1, 1);
trStmt.setString(2, "A");
System.out.println("execute for: "+primitiveSql);
ResultSet trRs = trStmt.executeQuery();
while (trRs.next())
System.out.println("C1:"+trRs.getInt(1)+", C2:"+trRs.getString(2));
trRs.close();
trStmt.close();
}catch (Exception e) {
System.out.println("expected Exception: "+e.getMessage());
}
conn.close();
}
}
8.1.2.4 prepareStatement()
This group of methods create a PreparedStatement object, and specify whether the
statement supports SQL translation. If the value of parameter translating is TRUE,
then the returning statement supports translation. If the value is FALSE, then the
returning statement does not support translation.
Syntax Description
Creates a PreparedStatement object
public PreparedStatement prepareStatement(
String sql, with option to translate or not translate
boolean translating) SQL
throws SQLException;
8-9
Chapter 8
OracleTranslatingConnection Interface
Syntax Description
Creates a PreparedStatement object
public PreparedStatement prepareStatement(
String sql, with the given type, concurrency, and
int resultSetType, holdability with option to translate or not
int resultSetConcur, translate SQL
int resultSetHold,
boolean translating)
throws SQLException;
Parameter Description
sql Specifies the String SQL statement value to be sent to the
database; may contain one or more parameters
Specifies the int value representing the result set type
resultSetType
Return Value
The prepareStatement() method returns a PreparedStatement object.
Usage Notes
When the "?" placeholder is used with the prepareStatement() method, the driver
internally changes the "?" to Oracle-style parameters because the server side
translator can only work with Oracle-style markers. This is necessary to distinguish
the bind variables. If not, any change in the order of the bind variables will be
indistinguishable. The replaced oracle style markers follow the format :b<n> where
<n> is an incremental number. For example, exec sample_proc(?,?) becomes exec
sample_proc(:b1,:b2).
To further exemplify, consider a scenario of a vendor format where the vendor query
selecting top three rows is SELECT * FROM employees WHERE first_name=? AND
employee_id=? TOP 3. The query has to be converted to oracle dialect. In this case
the following translation is to be registered on the server:
From:
SELECT * FROM employees WHERE first_name=:b1 AND employee_id=:b2 TOP 3
To:
SELECT * FROM employees WHERE first_name=:b1 AND employee_id=:b2 AND ROWNUM <= 3
8-10
Chapter 8
OracleTranslatingConnection Interface
Exceptions
The prepareStatement() method throws SQLException.
Example
Import the following packages before running the example:
import java.sql.*;
import java.util.Properties;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.OracleTranslatingConnection;
import oracle.jdbc.pool.OracleDataSource;
conn username/pwd;
drop table sample_tab;
create table sample_tab (c1 number, c2 varchar2(100));
insert into sample_tab values (1, 'A');
insert into sample_tab values (1, 'A');
insert into sample_tab values (1, 'A');
commit;
exec dbms_sql_translator.drop_profile('FOO');
exec dbms_sql_translator.create_profile('FOO');
exec dbms_sql_translator.register_sql_translation('FOO','select row of select
c1, c2 from sample_tab
where c1=:b1 and c2=:b2','select c1, c2 from sample_tab where c1=:b1 and
c2=:b2');
try{
OracleTranslatingConnection trConn = (OracleTranslatingConnection) conn;
System.out.println("Call:
8-11
Chapter 8
OracleTranslatingConnection Interface
oracle.jdbc.OracleTranslatingConnection.prepareStatement(sql, true)");
PreparedStatement trStmt = trConn.prepareStatement(primitiveSql, true);
trStmt.setInt(1, 1);
trStmt.setString(2, "A");
System.out.println("executeQuery for: "+primitiveSql);
ResultSet trRs = trStmt.executeQuery();
while (trRs.next())
System.out.println("C1:"+trRs.getInt(1)+", C2:"+trRs.getString(2));
trRs.close();
trStmt.close();
}catch (Exception e) {
e.printStackTrace();
}
try{
OracleTranslatingConnection trConn = (OracleTranslatingConnection) conn;
System.out.println("Call:
oracle.jdbc.OracleTranslatingConnection.prepareStatement(sql, false)");
PreparedStatement trStmt = trConn.prepareStatement(primitiveSql, false);
trStmt.setInt(1, 1);
trStmt.setString(2, "A");
System.out.println("executeQuery for: "+primitiveSql);
ResultSet trRs = trStmt.executeQuery();
while (trRs.next())
System.out.println("C1:"+trRs.getInt(1)+", C2:"+trRs.getString(2));
trRs.close();
trStmt.close();
}catch (Exception e) {
System.out.println("expected Exception: "+e.getMessage());
}
try{
OracleTranslatingConnection trConn = (OracleTranslatingConnection) conn;
System.out.println("Call:
oracle.jdbc.OracleTranslatingConnection.prepareStatement(
sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, true)");
PreparedStatement trStmt = trConn.prepareStatement(
primitiveSql, ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY, true);
trStmt.setInt(1, 1);
trStmt.setString(2, "A");
System.out.println("executeQuery for: "+primitiveSql);
ResultSet trRs = trStmt.executeQuery();
while (trRs.next())
System.out.println("C1:"+trRs.getInt(1)+", C2:"+trRs.getString(2));
conn.close();
}
}
8-12
Chapter 8
Error Translation Configuration File
8.1.2.5 getSQLTranslationVersions()
Returns a map of all the translation versions of the query during SQL Translation. In
case of an exception, and if suppressExceptions is true, then the translated version in
the map is NULL.
Syntax
public Map<SqlTranslationVersion, String> getSqlTranslationVersions(
String sql,
boolean suppressExceptions)
throws SQL Exception;
Return Value
Map with all translation versions of a query. See SqlTranslationVersion enum for more
details about returning versions.
Exception
This method throws SQLException if there is a problem in query translation, provided
suppressExceptions is false.
where,
• ORAError is an int value and specifies the error code for the oracle error.
• ErrorCode is an int value and specifies the vendor error code, that is, the
translated code.
• SQLState is a String value and specifies the vendor SQL state.
8-13
Glossary
adapter
A real-time, proprietary tool used to enable access to data stored in one database from
another database. Adapters are commonly used to translate SQL, map data types,
and facilitate the integration of SQL statements, triggers, and stored procedures.
data integration
The exchange of data between different databases, either asynchronously in real-time
transactions or synchronously as batch processes.
error translation
A scenario in which users can register vendor-specific translations of error codes and
messages with the SQL Translation Profile. During SQL execution, client applications
rely on vendor-specific error codes and messages. When errors occur, the translated
Glossary-1
Glossary
error codes and messages are returned instead of the Oracle error codes and
messages.
migration
The process of modifying a non-Oracle application, including all of its components
(such as architecture, data, SQL code, and client) to use the Oracle RDBMS rather
than a proprietary database management system.
migration repository
A data store in Oracle Database that Oracle SQL Developer uses to manage the
metadata for the source and target schema models during a migration. Multiple
migration repositories can be used to migrate from several databases to Oracle
Database at the same time.
Oracle GoldenGate
An Oracle product that supports modular, transaction-level data integration between
diverse data sources that are stored in SQL Server, Sybase, DB2, Oracle, and other
databases.
Oracle SQL*Loader
A fast, flexible, and free Oracle utility that supports loading data from flat files into
Oracle Database. It supports several data formats and many different encodings. It
also supports parallel data loading.
SQL dialect
A variation or extension of SQL implemented by a database vendor. When
migrating client applications from third-party databases to Oracle, all non-Oracle SQL
statements must be translated into Oracle SQL. Because these non-Oracle SQL
statements are embedded within the source code of client applications, locating and
translating them is a time-consuming, manual task. This release enhances the Oracle
Glossary-2
Glossary
database to accept non-Oracle SQL statements from external vendors, and translate
them automatically at run time before execution.
SQL Translator
The SQL Translator is a software component, provided by Oracle or third-party
vendors, which can be installed in Oracle Database. It translates the SQL statements
of a client program before they are processed by the Oracle Database SQL compiler. If
an error results from translated SQL statement execution, then Oracle Database SQL
compiler generates an Oracle error message.
SQLSTATE
A status parameter defined by the ANSI SQL standard. It is a 5-character string that
indicates the status of a SQL operation. Some of these values are:
• 01XXX: Warning
• 02XXX: No Data
Glossary-3
Index
A J
administrative routines APIs, 7-8 JDBC API, 8-1
ATTR_RAISE_TRANSLATION_ERROR, 4-2 configuration file, 8-13
SQLErrorTranslation.xml, 8-13
methods
C createStatement(), 8-3
client library initialization and termination APIs, getSQLTranslationVersions(), 8-13
7-8 prepareCall(), 8-7
connection management APIs, 7-8 prepareStatement(), 8-9
createStatement(), 8-3 OracleTranslatingConnection interface, 8-2
creating identity columns, 1-3 translation properties, 8-1
sqlErrorTranslationFile, 8-2
sqlTranslationProfile, 8-1
D JDBC driver support for application migration, 1-8
data types,mapping, 7-1 JDBC support for implicit results, 1-3
datetime and interval data types, 7-7
L
E liboramysql driver, 6-1
enhanced SQL to PL/SQL bind handling, 1-6 liboramysql library
error handling, 7-8 connecting, 6-2
error reporting APIs, 7-8 connecting to Oracle Database, 6-5
error handling, 6-5
expected differences, 6-5
F globalization, 6-5
migration overview, 6-3
features supporting migration, 1-1
supported platforms, 6-5
usage, 6-3
G
getSQLTranslationVersions(), 8-13 M
mapping data types, 7-1
I Oracle MySQL client library driver, 7-1
mapping Oracle data types to MySQL data types,
identity columns, 1-2 7-1
implicit statement results, 1-3 methods
information routines APIs, 7-8 createStatement(), 8-3
interface getSQLTranslationVersions(), 8-13
OracleTranslatingConnection, 8-2 prepareCall(), 8-7
prepareStatement(), 8-9
Migrating a Sybase JDBC application, 5-1
capturing migration, 5-3
converting migration, 5-6, 5-7
generating migration, 5-9
Index-1
Index
Index-2
Index
Index-3