Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to Oracle from F#

How would I go about connecting to oracle from F#? Is there a drive or can I load up the C# driver? I'm very new to F#.

like image 906
detroitpro Avatar asked Aug 14 '10 01:08

detroitpro


People also ask

Can you connect to an Oracle database from Excel?

You can use Microsoft Excel to access data from a Oracle database using ODBC connector. With ODBC Driver, you can import the data directly into an Excel Spreadsheet and present it as a table.


1 Answers

You can use the same libraries as you use in C# - .NET interoperability is one of the key features of F#. There are some classes in the Base Class Library which you could use (in System.Data.Oracle.dll), but these have been deprecated in favor of Oracle's own .NET drivers (Oracle Data Provider for .NET).

F# code using ODP.NET might look something like:

#if INTERACTIVE
  #r "System.Data"
  #r "Oracle.DataAccess"
#endif

open System.Data
open Oracle.DataAccess.Client

let conn = OracleConnection("User Id=scott;Password=tiger;Data Source=oracle")
conn.Open()

let cmd = conn.CreateCommand()
cmd.CommandText = "select * from emp"

let rdr = reader = cmd.ExecuteReader()

let empIds = 
  [while reader.Read() do
     yield reader.GetInt32(0)]
like image 102
kvb Avatar answered Oct 03 '22 09:10

kvb