Thursday, July 30, 2015

What is the difference between a unique constraint and a primary key?

What is the difference between a unique constraint and a primary key?

Primary Key Unique Constraint
None of the fields that are part of the primary key can contain a null value. Some of the fields that are part of the unique constraint can contain null values as long as the combination of values is unique.

Sunday, July 26, 2015

Oracle Browse files

Declare
    New_Path Varchar2(100);
    file_path Varchar2(100);
Begin
    New_Path := 'C:/';
  file_path := Win_Api_Dialog.Open_File
  ('Find Files',New_Path,
  'MSACCESS Files (*.mdb) |*.mdb|MSACCESS Files (*.accdb) |*.accdb|All Files (*.*) |*.*|'
  ,TRUE,WIN_API.OFN_FLAG_DEFAULT,TRUE);
    :file_name := file_path;
  EXCEPTION
    WHEN NO_DATA_FOUND THEN
      NULL;
END;

Saturday, July 11, 2015

Oracle Number formats

A number format can be used as part a TO_CHAR or TO_DATE function to return a number in the specified format.

FormatDescriptionExample
9Number
(suppress leading/trailing zeros)
Includes a leading - for negative no's or one leading space for pos no's
9999=' 123'
0Number
including leading/trailing zeros
09999=00123
9999D00=123.00
FMSupress all leading /trailing blanksFM9999=123
$Include a leading $$999=$123
BOver-ride the '0' format and replace leading 0's with blank spaces ' 'B9999=' 123'
SInclude poth positive+ and negative - signsS999 =+123
999S =123+
PRIndicate SIGN with <brackets>PR999=<123>
PR999=' 123 '
MIIndicate Minus SIGN999MI=123-
RN or rnRoman numeral
(upper or lower case)
RN99=XI
DPosition of decimal point(.)99D99=12.34
GGroup separator (often a comma) in desired position9G999=1,234
,Return a comma in desired position9,999=1,234
.Return a period in desired position99.99=12.34
CISO currency symbolC99
LLocal currency symbolL99
EEEE
Return a value using in scientific notation
9.9EEEE= 1.2E+02
TMText Minimum
TM9(the default) or TME (Scientific notation)
TM9=12345
TME=1.2E+02
UReturns in the specified position the Euro (or other) dual currency symbol.
(NLS_DUAL_CURRENCY)
U9999 = €1234
VReturn a value multiplied by 10n , where n is the number of 9's after the V.
(value will be rounded up if necessary)
999V99= 123 x 1045
XReturns the hexadecimal value of the specified number of digits.select to_char('64','xx') from dual;
Some of the format elements above can only be used at the start or end of a format string:
MI, PR, S
The default text minimum number format model is TM9, which returns the number in fixed notation unless the output exceeds 64 characters in which case the number will be returned in scientific notation.

Thursday, July 9, 2015

pl/sql Constant

A constant holds a value that once declared, does not change in the program. A constant declaration specifies its name, data type, and value, and allocates storage for it. The declaration can also impose the NOT NULL constraint.

Declaring a Constant

A constant is declared using the CONSTANT keyword. It requires an initial value and does not allow that value to be changed. For example:
PI CONSTANT NUMBER := 3.141592654;
 
DECLARE
   -- constant declaration
   pi constant number := 3.141592654;
   -- other declarations
   radius number(5,2); 
   dia number(5,2); 
   circumference number(7, 2);
   area number (10, 2);
BEGIN 
   -- processing
   radius := 9.5; 
   dia := radius * 2; 
   circumference := 2.0 * pi * radius;
   area := pi * radius * radius;
   -- output
   dbms_output.put_line('Radius: ' || radius);
   dbms_output.put_line('Diameter: ' || dia);
   dbms_output.put_line('Circumference: ' || circumference);
   dbms_output.put_line('Area: ' || area);
END;
/
 
 
When the above code is executed at SQL prompt, it produces the following result:
Radius: 9.5 Diameter: 19 Circumference: 59.69 Area: 283.53 Pl/SQL procedure successfully completed.
  

Wednesday, July 8, 2015

PL/SQL - Packages

PL/SQL packages are schema objects that groups logically related PL/SQL types, variables and subprograms.
A package will have two mandatory parts:
  • Package specification
  • Package body or definition

    Package Specification

    The specification is the interface to the package. It just DECLARES the types, variables, constants, exceptions, cursors, and subprograms that can be referenced from outside the package. In other words, it contains all information about the content of the package, but excludes the code for the subprograms.
    All objects placed in the specification are called public objects. Any subprogram not in the package specification but coded in the package body is called a private object.
    The following code snippet shows a package specification having a single procedure. You can have many global variables defined and multiple procedures or functions inside a package.
    CREATE PACKAGE cust_sal AS
       PROCEDURE find_sal(c_id customers.id%type);
    END cust_sal;
    /
    When the above code is executed at SQL prompt, it produces the following result:

    Package Body

    The package body has the codes for various methods declared in the package specification and other private declarations, which are hidden from code outside the package.
    The CREATE PACKAGE BODY Statement is used for creating the package body. The following code snippet shows the package body declaration for the cust_sal package created above. I assumed that we already have CUSTOMERS table created in our database .
    CREATE OR REPLACE PACKAGE BODY cust_sal AS
       PROCEDURE find_sal(c_id customers.id%TYPE) IS
       c_sal customers.salary%TYPE;
       BEGIN
          SELECT salary INTO c_sal
          FROM customers
          WHERE id = c_id;
          dbms_output.put_line('Salary: '|| c_sal);
       END find_sal;
    END cust_sal;
    /
    When the above code is executed at SQL prompt, it produces the following result:


    Using the Package Elements

    The package elements (variables, procedures or functions) are accessed with the following syntax:
    package_name.element_name;
    Consider, we already have created above package in our database schema, the following program uses the find_sal method of the cust_sal package:
    DECLARE
       code customers.id%type := &cc_id;
    BEGIN
       cust_sal.find_sal(code);
    END;
    /
    When the above code is executed at SQL prompt, it prompt to enter customer ID and when you enter an ID, it displays corresponding salary as follows:
    Enter value for cc_id: 1
    Salary: 3000
    
    PL/SQL procedure successfully completed.

    Example:

    The following program provides a more complete package. We will use the CUSTOMERS table stored in our database with the following records:
    Select * from customers;
    
    +----+----------+-----+-----------+----------+
    | ID | NAME     | AGE | ADDRESS   | SALARY   |
    +----+----------+-----+-----------+----------+
    |  1 | Ramesh   |  32 | Ahmedabad |  3000.00 |
    |  2 | Khilan   |  25 | Delhi     |  3000.00 |
    |  3 | kaushik  |  23 | Kota      |  3000.00 |
    |  4 | Chaitali |  25 | Mumbai    |  7500.00 |
    |  5 | Hardik   |  27 | Bhopal    |  9500.00 |
    |  6 | Komal    |  22 | MP        |  5500.00 |
    +----+----------+-----+-----------+----------+

    THE PACKAGE SPECIFICATION:

    CREATE OR REPLACE PACKAGE c_package AS
       -- Adds a customer
       PROCEDURE addCustomer(c_id   customers.id%type,
       c_name  customers.name%type,
       c_age  customers.age%type,
       c_addr customers.address%type, 
       c_sal  customers.salary%type);
      
       -- Removes a customer
       PROCEDURE delCustomer(c_id  customers.id%TYPE);
       --Lists all customers
       PROCEDURE listCustomer;
     
    END c_package;
    /
    When the above code is executed at SQL prompt, it creates the above package and displays the following result:
    Package created.

    CREATING THE PACKAGE BODY:

    CREATE OR REPLACE PACKAGE BODY c_package AS
       PROCEDURE addCustomer(c_id  customers.id%type,
          c_name customers.name%type,
          c_age  customers.age%type,
          c_addr  customers.address%type, 
          c_sal   customers.salary%type)
       IS
       BEGIN
          INSERT INTO customers (id,name,age,address,salary)
             VALUES(c_id, c_name, c_age, c_addr, c_sal);
       END addCustomer;
      
       PROCEDURE delCustomer(c_id   customers.id%type) IS
       BEGIN
           DELETE FROM customers
             WHERE id = c_id;
       END delCustomer;
    
       PROCEDURE listCustomer IS
       CURSOR c_customers is
          SELECT  name FROM customers;
       TYPE c_list is TABLE OF customers.name%type;
       name_list c_list := c_list();
       counter integer :=0;
       BEGIN
          FOR n IN c_customers LOOP
          counter := counter +1;
          name_list.extend;
          name_list(counter)  := n.name;
          dbms_output.put_line('Customer(' ||counter|| ')'||name_list(counter));
          END LOOP;
       END listCustomer;
    END c_package;
    /
    Above example makes use of nested table which we will discuss in the next chapter. When the above code is executed at SQL prompt, it produces the following result:
    Package body created.

    USING THE PACKAGE:

    The following program uses the methods declared and defined in the package c_package.
    DECLARE
       code customers.id%type:= 8;
    BEGIN
          c_package.addcustomer(7, 'Rajnish', 25, 'Chennai', 3500);
          c_package.addcustomer(8, 'Subham', 32, 'Delhi', 7500);
          c_package.listcustomer;
          c_package.delcustomer(code);
          c_package.listcustomer;
    END;
    /
    When the above code is executed at SQL prompt, it produces the following result:
    Customer(1): Ramesh 
    Customer(2): Khilan 
    Customer(3): kaushik    
    Customer(4): Chaitali 
    Customer(5): Hardik 
    Customer(6): Komal
    Customer(7): Rajnish
    Customer(8): Subham
    Customer(1): Ramesh 
    Customer(2): Khilan 
    Customer(3): kaushik    
    Customer(4): Chaitali 
    Customer(5): Hardik 
    Customer(6): Komal
    Customer(7): Rajnish
    
    PL/SQL procedure successfully completed

Analytic Function vs Aggregate Count

Aggregate Examples
The following examples use COUNT as an aggregate function:
SELECT COUNT(*) "Total"
  FROM employees;

     Total
----------
       107

SELECT COUNT(*) "Allstars"
  FROM employees
  WHERE commission_pct > 0;

 Allstars
---------
       35

SELECT COUNT(commission_pct) "Count"
  FROM employees;

     Count
----------
        35

SELECT COUNT(DISTINCT manager_id) "Managers"
  FROM employees;

  Managers
----------
        18
Analytic Example
The following example calculates, for each employee in the employees table, the moving count of employees earning salaries in the range 50 less than through 150 greater than the employee's salary.
SELECT last_name, salary,
       COUNT(*) OVER (ORDER BY salary RANGE BETWEEN 50 PRECEDING AND
                      150 FOLLOWING) AS mov_count
  FROM employees
  ORDER BY salary, last_name;

LAST_NAME                     SALARY  MOV_COUNT
------------------------- ---------- ----------
Olson                           2100          3
Markle                          2200          2
Philtanker                      2200          2
Gee                             2400          8
Landry                          2400          8
Colmenares                      2500         10
Marlow                          2500         10
Patel                           2500         10

Aggregate and Analytic Functions

Aggregate Example
The following example calculates the average salary of all employees in the hr.employees table:
SELECT AVG(salary) "Average"
  FROM employees;

       Average
--------------
    6461.83178
Analytic Example
The following example calculates, for each employee in the employees table, the average salary of the employees reporting to the same manager who were hired in the range just before through just after the employee:
SELECT manager_id, last_name, hire_date, salary,
       AVG(salary) OVER (PARTITION BY manager_id ORDER BY hire_date 
  ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS c_mavg
  FROM employees
  ORDER BY manager_id, hire_date, salary;

MANAGER_ID LAST_NAME                 HIRE_DATE     SALARY     C_MAVG
---------- ------------------------- --------- ---------- ----------
       100 De Haan                   13-JAN-01      17000      14000
       100 Raphaely                  07-DEC-02      11000 11966.6667
       100 Kaufling                  01-MAY-03       7900 10633.3333
       100 Hartstein                 17-FEB-04      13000 9633.33333
       100 Weiss                     18-JUL-04       8000 11666.6667
       100 Russell                   01-OCT-04      14000 11833.3333
       100 Partners                  05-JAN-05      13500 13166.6667
       100 Errazuriz                 10-MAR-05      12000 11233.3333
. . .

Oracle developer course

Oracle developer course:
SQL       = 100$
PL/SQL = 150$
FORMS = 150$
REPORT = 100$

Course Include :
Material
project at the end of every course
Prepare for Oracle Exams in these subjects.

Best regards
Yasser
email: yasser.hassan@yandex.com

Tuesday, July 7, 2015

Configuring Oracle Database Gateway for ODBC



After installing the gateway and the ODBC driver for the non-Oracle system, perform the following tasks to configure Oracle Database Gateway for ODBC:
11.1 Configure the Gateway Initialization Parameter File
Perform the following tasks to configure the gateway initialization file:
11.1.1 Create the Initialization Parameter File
You must create an initialization file for your Oracle Database Gateway for ODBC. Oracle supplies a sample initialization file, initdg4odbc.ora. The sample file is stored in the ORACLE_HOME\hs\admin directory.
To create an initialization file for the ODBC gateway, copy the sample initialization file and rename it to initsid.ora, where sid is the system identifier(SID) you want to use for the instance of the non-Oracle system to which the gateway connects.
The gateway system identifier (SID) is an alphanumeric character string that identifies a gateway instance. You need one gateway instance, and therefore one gateway SID, for each ODBC source you are accessing.
If you want to access two ODBC sources, you need two gateway SIDs, one for each instance of the gateway. If you have only one ODBC source but want to access it sometimes with one set of gateway parameter settings, and other times with different gateway parameter settings, then you will need multiple gateway SIDs for the single ODBC source. The SID is used as part of the file name for the initialization parameter file.
11.1.2 Set the Initialization Parameter Values
After the initialization file has been created, you must set the initialization parameter values. A number of initialization parameters can be used to modify the gateway behavior. You must set the HS_FDS_CONNECT_INFO initialization parameter. Other initialization parameters have defaults or are optional. You can use the default values and omit the optional parameters, or you can specify the parameters with values tailored for your installation. Changes made to the initialization parameters only take effect in the next gateway session.
The HS_FDS_CONNECT_INFO initialization parameter specifies the information required for connecting to the non-Oracle system. Set the HS_FDS_CONNECT_INFO as follows:
HS_FDS_CONNECT_INFO=dsn_value

where dsn_value is the name of the system DSN defined in the Microsoft Windows ODBC Data Source Administrator.
Note:
Before deciding whether to accept the default values or to change them.
11.1.2.1 Example: Setting Initialization Parameter Values
Assume that a system DSN has been defined in the Microsoft Windows ODBC Data Source Administrator. In order to connect to this SQL Server database through the gateway, the following line is required in the initsid.ora file:
HS_FDS_CONNECT_INFO=sqlserver7
sqlserver7 is the name of the system DSN defined in the Microsoft Windows ODBC Data Source Administrator.
The following procedure enables you to define a system DSN in the Microsoft Windows ODBC Data Source Administrator, version 3.5:
  1. From the Start menu, choose Settings > Control Panel and select ODBC.
  2. Select the System DSN tab page to display the system data sources.
  3. Click Add.
  4. From the list of installed ODBC drivers, select the name of the driver that the data source will use. For example, select SQL Server.
  5. Click Finish.
  6. Enter a name for the DSN and an optional description. Enter other information depending on the ODBC driver. For example, for SQL Server enter the SQL Server machine name.
Note:
The name entered for the DSN must match the value of the initialization parameter HS_FDS_CONNECT_INFO that is specified in initsid.ora.
  1. Refer to your ODBC driver documentation and follow the prompts to complete configuration of the DSN.
  2. After creating the system DSN, click OK to exit the ODBC Data Source Administrator.
Note:
If the ODBC driver supports Quoted Identifiers or Delimited Identifiers it should be turned on.
11.2 Configure Oracle Net for the Gateway
The gateway requires Oracle Net to communicate with the Oracle database. After configuring the gateway, perform the following tasks to configure Oracle Net to work with the gateway:
11.2.1 Configure Oracle Net Listener for the Gateway
The Oracle Net Listener listens for incoming requests from the Oracle database. For the Oracle Net Listener to listen for the gateway, information about the gateway must be added to the Oracle Net Listener configuration file, listener.ora. This file by default is located in ORACLE_HOME\network\admin, where ORACLE_HOME is the directory under which the gateway is installed.
The following entries must be added to the listener.ora file:
  • A list of Oracle Net addresses on which the Oracle Net Listener listens
  • The executable name of the gateway that the Oracle Net Listener starts in response to incoming connection requests
A sample of the listener.ora entry (listener.ora.sample) is available in the ORACLE_HOME\dg4odbc\admin directory where ORACLE_HOME is the directory under which the gateway is installed.
11.2.1.1 Syntax of listener.ora File Entries
The Oracle database communicates with the gateway using Oracle Net and any supported protocol adapters. The following is the syntax of the address on which the Oracle Net Listener listens using the TCP/IP protocol adapter:
LISTENER=
        (ADDRESS=
          (PROTOCOL=TCP)
          (HOST=host_name)
          (PORT=port_number))
Where:
Variable
Description
host_name
is the name of the machine on which the gateway is installed.
port_number
specifies the port number used by the Oracle Net Listener. If you have other listeners running on the same machine, then the value of port_number must be different from the other listeners' port numbers.

To direct the Oracle Net Listener to start the gateway in response to incoming connection requests, add an entry to the listener.ora file.
Note:
You must use the same SID value in the listener.ora file and the tnsnames.ora file that will be configured in the next step.
SID_LIST_LISTENER=
   (SID_LIST=
      (SID_DESC=
         (SID_NAME=gateway_sid)
         (ORACLE_HOME=oracle_home_directory)
         (PROGRAM=dg4odbc)
      )
   )
Where:
Variable
Description
gateway_sid
specifies the SID of the gateway and matches the gateway SID specified in the connect descriptor entry in the tnsnames.ora file.
oracle_home_directory
specifies the Oracle home directory where the gateway resides.
dg4odbc
specifies the executable name of the Oracle Database Gateway for ODBC.

If you already have an existing Oracle Net Listener, then add the following syntax to SID_LIST in the existing listener.ora file:
SID_LIST_LISTENER=
(SID_LIST=
   (SID_DESC=.
     .
   )
   (SID_DESC=.
     .
   )
   (SID_DESC=
      (SID_NAME=gateway_sid)
      (ORACLE_HOME=oracle_home_directory)
      (PROGRAM=dg4odbc)
   )
)
11.2.2 Stop and Start the Oracle Net Listener for the Gateway
You must stop and restart the Oracle Net Listener to initiate the new settings, as follows:
  1. From the Start menu, select Settings, Control Panel and then select Services.
  2. Select the Oracle Net Listener service for the gateway.
  3. If the service is already running, click Stop to stop it.
  4. Click Start to start or restart the service.
11.3 Configure the Oracle Database for Gateway Access
Before you use the gateway to access an ODBC data source you must configure the Oracle database to enable communication with the gateway over Oracle Net.
To configure the Oracle database you must add connect descriptors to the tnsnames.ora file. By default, this file is in ORACLE_HOME\network\admin, where ORACLE_HOME is the directory in which the Oracle database is installed. You cannot use the Oracle Net Assistant or the Oracle Net Easy Config tools to configure the tnsnames.ora file. You must edit the file manually.
A sample of the tnsnames.ora entry (tnsnames.ora.sample) is available in the ORACLE_HOME\dg4odbc\admin directory where ORACLE_HOME is the directory under which the gateway is installed.
11.3.1 Configuring tnsnames.ora
Edit the tnsnames.ora file to add a connect descriptor for the gateway. The following is a syntax of the Oracle Net entry using the TCP/IP protocol:
connect_descriptor=
   (DESCRIPTION=
      (ADDRESS=
         (PROTOCOL=TCP)
         (HOST=host_name)
         (PORT=port_number)
      )
      (CONNECT_DATA=
         (SID=gateway_sid))
      (HS=OK))
Where:
Table 11-1 Gateway Parameters for tnsnames.ora File
Variable
Description
connect_descriptor
is the description of the object to connect to as specified when creating the database link, such as dg4odbc.
Check the sqlnet.ora file for the following parameter setting:
names.directory_path = (TNSNAMES)
Note: The sqlnet.ora file is typically stored in ORACLE_HOME\network\admin.
TCP
is the TCP protocol used for TCP/IP connections.
host_name
specifies the machine where the gateway is running.
port_number
matches the port number used by the Oracle Net Listener that is listening for the gateway. The Oracle Net Listener's port number can be found in the listener.ora file used by the Oracle Net Listener..
gateway_sid
specifies the SID of the gateway and matches the SID specified in the listener.ora file of the Oracle Net Listener that is listening for the gateway. See
(HS=OK)
specifies that this connect descriptor connects to a non-Oracle system.

11.4 Create Database Links
Any Oracle client connected to the Oracle database can access an ODBC data source through the gateway. The Oracle client and the Oracle database can reside on different machines. The gateway accepts connections only from the Oracle database.
A connection to the gateway is established through a database link when it is first used in an Oracle session. In this context, a connection refers to the connection between the Oracle database and the gateway. The connection remains established until the Oracle session ends. Another session or user can access the same database link and get a distinct connection to the gateway and ODBC data source.
Database links are active for the duration of a gateway session. If you want to close a database link during a session, you can do so with the ALTER SESSION statement.
To access the ODBC data source, you must create a database link. A public database link is the most common of database links.
SQL> CREATE PUBLIC DATABASE LINK dblink CONNECT TO
2  "user" IDENTIFIED BY "password" USING 'tns_name_entry';
Where:
Variable
Description
dblink
is the complete database link name.
tns_name_entry
specifies the Oracle Net connect descriptor specified in the tnsnames.ora file that identifies the gateway

After the database link is created you can verify the connection to the ODBC data source, as follows:
SQL> SELECT * FROM DUAL@dblink;
11.5 Encrypt Gateway Initialization Parameter Values
The gateway uses user IDs and passwords to access the information in the remote database. Some user IDs and passwords must be defined in the gateway initialization file to handle functions such as resource recovery. In the current security conscious environment, having plain-text passwords that are accessible in the initialization file is deemed insecure. The dg4pwd encryption utility has been added as part of Heterogeneous Services to help make this more secure. This utility is accessible by this gateway. The initialization parameters that contain sensitive values can be stored in an encrypted form.
11.6 Configure the Gateway to Access Multiple ODBC Data Sources
The tasks for configuring the gateway to access multiple ODBC data sources are similar to the tasks for configuring the gateway for a single data source. The configuration example assumes the following:
  • The gateway is installed and configured with the SID of dg4odbc.
  • The gateway is configured to access one ODBC data source named dsn1.
  • Two ODBC data sources named dsn2 and dsn3 where dsn2 and dsn3 are the names of the system DSN defined in the Microsoft Windows ODBC Data Source Administrator, are being added.
11.6.1 Multiple ODBC Data Sources Example: Configuring the Gateway
Choose One System ID for Each ODBC Data Source
A separate instance of the gateway is needed for each ODBC data source. Each instance needs its own gateway System ID (SID). For this example, the gateway SIDs are chosen for the instances that access the ODBC data source:
  • dg4odbc2 for the gateway accessing data source dsn2.
  • dg4odbc3 for the gateway accessing data source dsn3.
Create Two Initialization Parameter Files
Create an initialization parameter file for each instance of the gateway by copying the original initialization parameter file: ORACLE_HOME\hs\admin\initdg4odbc.ora, twice, naming one with the gateway SID for dsn2 and the other with the gateway SID for dsn3:
> cd ORACLE_HOME\hs\admin
> copy initdg4odbc.ora initdg4odbc2.ora
> copy initdg4odbc.ora initdg4odbc3.ora
Change the value of the HS_FDS_CONNECT_INFO parameter in the new files as follows:
For initdg4odbc2.ora, enter the following:
HS_FDS_CONNECT_INFO=dsn2
For initdg4odbc3.ora, enter the following:
HS_FDS_CONNECT_INFO=dsn3
Note:
If you have multiple gateway SIDs for the same ODBC data source because you want to use different gateway parameter settings at different times, follow the same procedure. You create several initialization parameter files, each with different SIDs and different parameter settings.
11.6.2 Multiple ODBC Data Sources Example: Configuring Oracle Net Listener
Add Entries to listener.ora
Add two new entries to the Oracle Net Listener configuration file, listener.ora. You must have an entry for each gateway instance, even when multiple gateway instances access the same database.
The following example shows the entry for the original installed gateway first, followed by the new entries:
SID_LIST_LISTENER=
(SID_LIST=
   (SID_DESC=
      (SID_NAME=dg4odbc)
      (ORACLE_HOME=oracle_home_directory)
      (PROGRAM=dg4odbc)
   )
   (SID_DESC=
      (SID_NAME=dg4odbc2)
      (ORACLE_HOME=oracle_home_directory)
      (PROGRAM=dg4odbc)
   )
   (SID_DESC=
      (SID_NAME=dg4odbc3)
      (ORACLE_HOME=oracle_home_directory)
      (PROGRAM=dg4odbc)
   )
)
where, oracle_home_directory is the directory where the gateway resides.
11.6.3 Multiple ODBC Data Sources Example: Stopping and Starting the Oracle Net Listener
Perform the following steps:
  1. From the Start menu, select Settings, Control Panel and then select Services.
  2. Select the Oracle Net Listener service for the gateway.
  3. Click Stop.
  4. Click Start.
11.6.4 Multiple ODBC Data Sources Example: Configuring Oracle Database for Gateway Access
Add two connect descriptor entries to the tnsnames.ora file. You must have an entry for each gateway instance, even if the gateway instances access the same database.
The following example shows the entry for the original installed gateway first, followed by the two entries for the new gateway instances:
old_dsn_using=(DESCRIPTION=
              (ADDRESS=
                (PROTOCOL=TCP)
                (PORT=port_number)
                (HOST=host_name))
                (CONNECT_DATA=
                    (SID=dg4odbc))
               (HS=OK))
new_dsn2_using=(DESCRIPTION=
              (ADDRESS=
                (PROTOCOL=TCP)
                (PORT=port_number)
                (HOST=host_name))
                (CONNECT_DATA=
                    (SID=dg4odbc2))
                (HS=OK))
new_dsn3_using=(DESCRIPTION=
              (ADDRESS=
                (PROTOCOL=TCP)
                (PORT=port_number)
                (HOST=host_name))
                (CONNECT_DATA=
                    (SID=dg4odbc3))
                (HS=OK))
The value for PORT is the TCP/IP port number of the Oracle Net Listener that is listening for the gateway. The number can be found in the listener.ora file used by the Oracle Net Listener. The value for HOST is the name of the machine on which the gateway is running. The name also can be found in the listener.ora file used by the Oracle Net Listener.
11.6.5 Multiple ODBC Data Sources Example: Accessing ODBC Data
Enter the following to create a database link for the dg4odbc2 gateway:
SQL> CREATE PUBLIC DATABASE LINK ODBC2 CONNECT TO
  2  "user2" IDENTIFIED BY "password2" USING 'new_dsn2_using';
Enter the following to create a database link for the dg4odbc3 gateway:
SQL> CREATE PUBLIC DATABASE LINK ODBC3 CONNECT TO
  2  "user3" IDENTIFIED BY "password3" USING 'new_dsn3_using';
After the database links are created, you can verify the connection to the new ODBC data sources, as in the following:
SQL> SELECT * FROM ALL_USERS@ODBC2;
SQL> SELECT * FROM ALL_USERS@ODBC3;