| Oracle Transparent Gateway Rdb on Alpha OpenVms Administrator's Guide Release 8.1.7 Part Number A82918-01 |
|
After the gateway is installed and configured, you can use the gateway to access Rdb data, pass Rdb commands from applications to the Rdb database, perform distributed queries, and copy data.
This chapter contains the following sections:
To access Rdb data through the gateway, complete the following steps on the Oracle database server:
SQL> CREATE DATABASE LINK TG4RDB 2 USING 'tg4rdb'
SQL> SELECT * FROM EMP@TG4RDB
SQL> SELECT * FROM EMP@TG4RDB
SQL> UPDATE EMP@TG4RDB SET SAL=SAL*1.10
The gateway rewrites SQL statements when the statements need to be translated or post-processed.
For example, consider a program that requests the following from the Rdb database:
SELECT COL_A FROM TEST@TG4RDB WHERE COL_A = INITCAP('jones');
The Rdb database does not recognize INITCAP, so the Oracle database server does a table scan of test and filters the results locally. The gateway rewrites the SELECT statement as follows:
SELECT COL_A FROM TEST@TG4RDB
The results of the query are sent to the gateway and are filtered by the Oracle database server.
Consider the following UPDATE request:
UPDATE TEST@TG4RDB SET COL_A = 'SMITH' WHERE COL_A = INITCAP('jones');
In this case, the Oracle database server and the gateway cannot compensate for the lack of support at the Rdb side, so an error is issued.
If you are performing operations on large amounts of data stored in the Rdb database, keep in mind that some functions require data to be moved to the integrating Oracle database server before processing can occur.
The gateway converts Rdb data types to Oracle data types as follows:
You can provide complete data location transparency and network transparency by using the synonym feature of the Oracle database server. When a synonym is defined, you do not have to know the underlying table or network protocol. A synonym can be public, which means that all Oracle users can refer to the synonym. A synonym can also be defined as private, which means every Oracle user must have a synonym defined to access the Rdb table.
The following statement creates a system wide synonym for the EMP table in the schema of user ORACLE:
SQL> CREATE PUBLIC SYNONYM EMP FOR EMP@TG4RDB
The gateway can pass Rdb commands or statements from the application to the Rdb database using the DBMS_HS_PASSTHROUGH package.
Use the DBMS_HS_PASSTHROUGH package in a PL/SQL block to specify the statement to be passed to the Rdb database, as follows:
DECLARE num_rows INTEGER; BEGIN num_rows := DBMS_HS_PASSTHROUGH.EXECUTE_IMMEDIATE@TG4RDB('command'); END; /
Where command cannot be one of the following:
The DBMS_HS_PASSTHROUGH package does support passing bind values and executing SELECT statements.
Oracle Transparent Gateway technology enables the execution of distributed queries that join the Oracle database server and the Rdb database, and any other data store for which Oracle Corporation provides a gateway. These complex operations can be invisible to the users requesting the data.
The following example joins data between the Oracle database server, an IBM DB2 database, and the Rdb database:
SQL> SELECT O.CUSTNAME, P.PROJNO, E.ENAME, SUM(E.RATE*P.HOURS)
FROM ORDERS@DB2 O, EMP@ORACLE8 E, PROJECTS@TG4RDB P
WHERE O.PROJNO = P.PROJNO
AND P.EMPNO = E.EMPNO
GROUP BY O.CUSTNAME, P.PROJNO, E.ENAME
Through a combination of views and synonyms, using the following SQL statements, the process of distributed queries is transparent to the user:
SQL> CREATE SYNONYM ORDERS FOR ORDERS@DB2
SQL> CREATE SYNONYM PROJECTS FOR PROJECTS@TG4RDB
SQL> CREATE VIEW DETAILS (CUSTNAME,PROJNO,ENAME,SPEND)
AS
SELECT O.CUSTNAME, P.PROJNO, E.ENAME, SUM(E.RATE*P.HOURS)
SPEND
FROM ORDERS O, EMP E, PROJECTS P
WHERE O.PROJNO = P.PROJNO
AND P.EMPNO = E.EMPNO
GROUP BY O.CUSTNAME, P.PROJNO, E.ENAME
Use the following SQL statement to retrieve information from the data stores in one command:
SQL> SELECT * FROM DETAILS;
The command retrieves the following table:
CUSTNAME PROJNO ENAME SPEND
-------- ------ ----- -----
ABC Co. 1 Jones 400
ABC Co. 1 Smith 180
XYZ Inc. 2 Jones 400
XYZ Inc. 2 Smith 180
When the gateway is configured as COMMIT_CONFIRM, it is always the commit point site when the Rdb database is updated by the transaction, regardless of the HS_COMMIT_POINT_STRENGTH setting. The Oracle database server commits the unit of work in the Rdb database after verifying that all Oracle databases in the transaction have successfully prepared the transaction.
Only one gateway can participate in an Oracle two-phase commit transaction. Two-phase commit transactions are recorded in the HS_TRANSACTION_LOG table that is created when configuring the gateway.
Because the HS_TRANSACTION_LOG table is used to record the status of a gateway transaction, the table must reside in the database where the Rdb update takes place.
Updates to the HS_TRANSACTION_LOG table cannot be part of an Oracle distributed transaction.
Use the SQL*Plus COPY command to copy data from the local database to the Rdb database. The syntax is as follows:
COPY FROM username/password@db_name
INSERT destination_table USING query
The following example selects all rows from the local Oracle EMP table, inserts them into the EMP table on the Rdb database, and commits the transaction:
SQL> COPY FROM SCOTT/TIGER@ORACLE8 -
> INSERT EMP@TG4RDB -
> USING SELECT * FROM EMP
The COPY command supports APPEND, CREATE, INSERT, and REPLACE options. However, INSERT is the only option supported when copying to Rdb. The SQL*Plus COPY command does not support copying to tables with lowercase table names. Use the following PL/SQL syntax with lowercase table names:
DECLARE v1 oracle_table.column1%TYPE; v2 oracle_table.column2%TYPE; v3 oracle_table.column3%TYPE; . . . CURSOR cursor_name IS SELECT * FROM oracle_table; BEGIN OPEN cursor_name; LOOP FETCH cursor_name INTO v1, v2, v3, ... ; EXIT WHEN cursor_name%NOTFOUND; INSERT INTO destination_table VALUES (v1, v2, v3, ...); END LOOP; CLOSE cursor_name; END;
/
The following Oracle SQL INSERT statement is not supported for copying data from the Oracle database server to Rdb:
INSERT INTO table_name SELECT column_list FROM table_name
For example, consider the following statement:
SQL> INSERT INTO TG4RDB_TABLE SELECT * FROM MY_LOCAL_TABLE
The statement returns the following error message:
ORA-2025: All tables in the SQL statement must be at the remote database
The CREATE TABLE command lets you copy data from the Rdb database to the Oracle database server. To create a table on the local database and insert rows from the Rdb table, use the following syntax:
CREATE TABLE table_name AS query
The following example creates the table EMP in the local Oracle database and inserts the rows from the EMP table of the Rdb database:
SQL> CREATE TABLE EMP AS SELECT * FROM EMP@TG4RDB
Alternatively, you can use the SQL*Plus COPY command to copy data from the Rdb database to the Oracle database server.
|
|
![]() Copyright © 2001 Oracle Corporation. All Rights Reserved. |
|