Categories
windows

Oracle ODBC hello world with powershell

Demo :

cmd /c "odbcconf.exe /a {configdsn ""Oracle in OraClient11g_home1"" ""DSN=helloworld|SERVER=DB01""}"

Create a helloworld data source connecting to your DB01 tns alias in your OraClient11g_home1 Oracle Home.

It is easy to get the Oracle Home name with

Get-itemproperty HKLM:\SOFTWARE\ORACLE\*| Select-Object ORACLE_HOME,ORACLE_HOME_NAME

ORACLE_HOME ORACLE_HOME_KEY
----------- ---------------
C:\oracle\product\11.1.0\client_1 OraClient11g_home1
C:\oracle\product\11.2.0\client_1 OraClient11g_home2

Then we create the connection (as we did in ADO or ODP) :

$conn = New-Object Data.Odbc.OdbcConnection
$conn.ConnectionString= "dsn=helloworld;uid=scott;pwd=tiger;"
$conn.open()
(new-Object Data.Odbc.OdbcCommand("select 'Hello World' from dual",$conn)).ExecuteScalar()
$conn.close()

Note: odbcconf will be removed in future release, prefer Add-OdbcDsn

By Laurent Schneider

Oracle Certified Master

4 replies on “Oracle ODBC hello world with powershell”

Hi Kaurent,

Kudos !! For ur excellent knowledge in oracle.

I m facing a problem with sql plus.

I have a requirement to create a stored procedure so that whenever a call to storedprocedure is made, the data from the table should be populated into a xlsb file which is having some macros. And even in that it should go into the 1st worksheet.
So I cannot create a new xlsb file instead I hav to use already existing one.

Please post me any ideas how to do this?

Leave a Reply

Your email address will not be published.