Salesforce SOQL from Oracle

The Salesforce ODBC Driver extends the number of applications that you can use Salesforce SOQL from. In this blog, we describe how to run SOQL statements from Oracle by using our ODBC driver with Oracle's Database Gateway for ODBC (DG4ODBC).

DG4ODBC comes as part of Oracle 12c / Oracle 11g, at no additional cost, and supports both these versions of Oracle and OracleŽ 10g.

To get started:

Before you can use the ODBC Driver to connect your application to, you need to configure an ODBC data source. An ODBC data source stores the connection details for the target database (e.g. and the ODBC driver that is required to connect to it (e.g. the ODBC driver).

If you have the 64-bit version of DG4ODBC, you need to run 64-bit version of ODBC Administrator (which you use to create a data source). To do this, open Administrative Tools in Control Panel, and then open Data Sources ODBC. On Windows Server 2003 and earlier, the Control Panel applet that launches ODBC Administrator is labelled Data Sources. On Windows 8 and later, the Control Panel applet is labelled ODBC Data Sources (64-bit).)

If you have the 32-bit version of DG4ODBC, you need to run 32-bit version of ODBC Administrator. To do this, in the Windows Run dialog box, type:


To create a ODBC Driver data source:

  1. In the ODBC Administrator, choose the System DSN tab, and then choose Add.

    To run the 32-bit version of ODBC Administrator, in the Windows Run dialog box, enter:

  2. In the Create New Data Source dialog box, choose Easysoft Salesforce SOQL ODBC Driver, and then choose Finish.
  3. Complete the Easysoft Salesforce SOQL ODBC Driver DSN Setup dialog box:
    Setting Value
    User Name The name of your user. For example,
    Password The password for your user.
    Token The security token for your user, if required.

    To find out whether you need to supply a security token, choose the Test button. If the connection attempt fails with an error which contains LOGIN_MUST_USE_SECURITY_TOKEN, you need to supply one. emails the security token to the email address associated with your user account. If you have not received a security token, you can regenerate it. will then email the new security token to you. To regenerate your security token, log in to and then choose Setup from the user menu. Search for "security token" in the Quick Find box. Click Reset Security Token in the Reset Security Token page. When you receive the token in your email client, copy it and then paste it into the Token field.

  4. Use the Test button to verify that you can successfully connect to

Using Salesforce SOQL from Oracle

Using the Salesforce ODBC driver to access Salesforce data from Oracle Heterogenous Services:

  1. Create a DG4ODBC init file. To do this, change to the %ORACLE_HOME%\hs\admin directory. Create a copy of the file initdg4odbc.ora. Name the new file initsoql.ora.

    Note In these instructions, replace %ORACLE_HOME% with the location of your Oracle HOME directory. For example, C:\oraclexe\app\oracle\product\11.2.0\server.

  2. Ensure these parameters and values are present in your init file:
    HS_FDS_CONNECT_INFO = my_salesforce_odbc_dsn;UID=my_salesforce_user_name;DOMAIN=my_salesforce_user_domain

    Replace my_salesforce_odbc_dsn with the name of a ODBC driver data source that connects to the target server. Replace my_salesforce_user_name with the user portion of your user name. Replace my_salesforce_user_domain with the domain portion of your user name. For example:

    HS_FDS_CONNECT_INFO = "my_salesforce_dsn;UID=myuser;DOMAIN=mydomain"
  3. Add an entry to %ORACLE_HOME%\network\admin\listener.ora that creates a SID_NAME for DG4ODBC. For example:
     (SID_LIST =
  4. Add a DG4ODBC entry to %ORACLE_HOME%\network\admin\tnsnames.ora that specifies the SID_NAME created in the previous step. For example:
    SOQL =
        (ADDRESS = (PROTOCOL = TCP)(HOST = oracle_host)(PORT = 1521))
        (CONNECT_DATA =
          (SID = soql)
        (HS = OK)

    Replace oracle_host with the host name of your Oracle machine.

  5. Start (or restart) the Oracle Listener:
    cd %ORACLE_HOME%\bin
    lsnrctl stop
    lsnrctl start
  6. Connect to your Oracle database in SQL*Plus.
  7. In SQL*Plus, create a database link for the target server. For example:
    "my_salesforce_user" IDENTIFIED by "my_salesforce_password" USING 'soql';

    Replace my_salesforce_user and my_salesforce_password with a valid username and password for the target server.

To use SOQL from Oracle, you need to use DBMS_HS_PASSTHROUGH, which lets you send a pass-through statement to Salesforce. For example:

   val1 nvarchar2(50);
   val2 nvarchar2(50); 
   DBMS_HS_PASSTHROUGH.PARSE@soqllink(c,'SELECT Account.Name, (SELECT Contact.LastName FROM Account.Contacts) FROM Account'); 
     WHILE (true) 
            DBMS_OUTPUT.PUT_LINE('Name '||val1);
            DBMS_OUTPUT.PUT_LINE('LastName '||val2);
        END LOOP; 
        WHEN no_data_found THEN 
              DBMS_OUTPUT.PUT_LINE('No more rows.');