Initializing help system before first use

Oracle

When accessing Oracle databases using initializations blocks we need to use the OCI I/O driver name, "mmoci.oci", followed by the database logon information, resulting in an extended file name such as "mmoci.oci:myname/mypassword@dbname".

The introductory examples in this section are documented in full length. However, given the similarity of the ODBC and OCI interfaces, most of the examples in the 'Examples' section of this whitepaper are presented only in their ODBC version without repeating every time the modifications to the driver name/database connection string that are required to obtain their OCI version. Nevertheless, many examples are available with an Oracle version in the Examples Database on the Xpress website.

Data input using oci

Let us assume we are working with a database dbname that contains a table `MyDataTable' with three fields, the first two (for the indices) of type integer, and the third of type float, filled with the data displayed in Section Data input using odbc.

We may then use the following model duooci.mos to read in the array A4 from the database and print it out. Only the module name in the uses statement and the extended filename for the database connection differ from what we have seen previously for an ODBC connection.

model "Duo input OCI (1)"
 uses "mmoci"

 declarations
  A4: dynamic array(range,range) of real
 end-declarations

! Use an initializations block with the odbc driver to read data
 initializations from "mmoci.oci:myname/mypassword@dbname"
  A4 as 'MyDataTable'
 end-initializations

! Print out the data we have read
 writeln('A4 is: ', A4)

end-model 

Data output using oci

Outputting data from a Mosel model through the oci I/O driver again only requires few changes to the model version for ODBC. Consider the following example (file duooci_out.mos):

model "Duo output OCI (1)"
 uses "mmoci"

 declarations
  A: array(-1..1,5..7) of real
 end-declarations

 A :: [ 2,  4,  6,
       12, 14, 16,
       22, 24, 26]

! Use an initializations block with the oci driver for writing data
 initializations to "mmoci.oci:myname/mypassword@dbname"
  A as "MyOutTable1"
 end-initializations

end-model 

The array A is written out to a data table named `MyOutTable1' in the database dbname. This table must have been created before executing the Mosel model, with fields that correspond to the data array we want to write. That is, a total of three fields where the first two (index) fields have the type integer and the third field is of type float.

In terms of database functionality, when writing out data with initializations to, Mosel performs an ``insert'', no replacement or update. If the data table already contains some data, for instance from previous model runs, the new output will be appended to the existing data. This means that the insertion will fail if key fields have been defined and you are trying to write the same data entries a second time. The deletion of any existing data in the table(s) used for output must be done manually directly in the database prior to the model run, or by adding the corresponding SQL commands to the Mosel model. For the latter, it is possible to use the oci I/O driver in combination with other mmoci functionality, such as calling specific SQL queries (see Section Oracle).