FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Spreadsheets and databases: working with multiple data tables and arrays

Description
A database table (or a spreadsheet range) may contain in its different fields (columns) the data for several Mosel arrays and inversely, a Mosel array may correspond to several data tables (ranges). We have here examples of various different cases:

  1. using the odbc driver,
  2. formulated with SQL statements,
  3. using the excel driver,
  4. using the oci driver,
  5. using the xls driver, and
  6. using the csv driver.
for three sets of examples:
  • Reading several arrays from a single database table/spreadsheet range (multicol.mos)
  • Outputting several arrays into a single database table/spreadsheet range (multiout.mos)
  • Reading an array from several tables/ranges (multitab.mos)
Further explanation of this example: Xpress Whitepaper 'Using ODBC and other database interfaces with Mosel', Section 'Examples'.


Source Files

Data Files





multiout4.mos

(!*******************************************************
   Mosel Example Problems 
   ======================

   file multiout4.mos
   ``````````````````
   Output several data arrays into a single table.
   - Using 'initializations' and OCI statements -
       
   (c) 2012 Fair Isaac Corporation
       author: S. Heipcke, Dec. 2012, rev. Aug. 2023
*******************************************************!)

model "Output multiple data columns (OCI)"
 uses "mmoci"
 options keepassert

 parameters
  DB="myname/mypassword@dbname"     ! Login to Oracle database (not provided)
 end-parameters

 declarations
  PRODUCTS: set of string
  MACH: range
  COST: dynamic array(PRODUCTS,MACH) of real
  DUR: dynamic array(PRODUCTS,MACH) of integer
 end-declarations

! Read data
 initializations from "multiout.dat"
  COST DUR
 end-initializations


! **** Using SQL statements ****

 setparam("OCIdebug",true)
 OCIlogon(DB)
 assert(getparam("OCIsuccess"))
 writeln("Connection number: ", getparam("OCIconnection"))

 OCIexecute("create table CombData (Products varchar(10), Mach integer, Cost double, Duration integer)")
 assert(getparam("OCIsuccess"))
 OCIexecute("delete from CombData")
 OCIexecute("insert into CombData(Products, Mach, Cost, Duration) values (:1,:2,:3,:4)", [COST,DUR])
 assert(getparam("OCIsuccess"))

 OCIlogoff


! **** Using 'initializations to' ****
! (this assumes that the table 'CombData' has been created previously)

 initializations to "mmoci.oci:debug;"+DB
  [COST,DUR] as 'CombData'
 end-initializations


end-model

Back to examples browserPrevious exampleNext example