pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bricklen Anderson <BAnderson@PresiNET.com>
To: dpandey@secf.com
Cc: PostgreSQL <pgsql-sql@postgresql.org>
Subject: Re: Create connection with Oracle database from Postgres plpgsql
Date: Tue, 05 Jul 2005 07:26:15 -0700
Message-ID: <42CA9887.7000603@PresiNET.com> (raw)
In-Reply-To: <20050705094703.4EFF85280B@svr1.postgresql.org>
References: <20050705094703.4EFF85280B@svr1.postgresql.org>

Dinesh Pandey wrote:
> How can we create connection with Oracle database from Postgres plpgsql
> function and execute some oracle stored procedure?
> 
> Thanks
> Dinesh
You can use perl DBI to access Oracle, providing you have DBI and the plperlu
language installed.

Sample code that may help you get started (lookout for typos):

create or replace function connect_ora() returns void as $$
use DBI;
&main;
sub main {
  my $query="select 1 from dual";
  my $dbh=openDatabase();
  if ($dbh==0) { return; }
  my $sth = $dbh->prepare( $query, {ora_check_sql => 0} ) || elog NOTICE, "Can't
prepare SQL statement: $DBI::errstr\n";
  $sth->execute() || elog ERROR, "Cant execute SQL statement: $DBI::errstr\n";
  my $array_ref = $sth->fetchall_arrayref();
  $sth->finish();
  $dbh->disconnect() || elog WARNING, "Disconnection from db failed\n";
  RETURN;
}
sub openDatabase {
    $dbh =
DBI->connect_cached("dbi:Oracle:host=<host>;sid=<sid>;port=<port>",<ora_username>,<ora_pwd>)
|| elog ERROR, $DBI::errstr;
    $dbh->{RowCacheSize} = 100;
  return $dbh;
}
$$ language plperlu;


Customize as you see fit. YMMV

-- 
_______________________________

This e-mail may be privileged and/or confidential, and the sender does
not waive any related rights and obligations. Any distribution, use or
copying of this e-mail or the information it contains by other than an
intended recipient is unauthorized. If you received this e-mail in
error, please advise me (by return e-mail or otherwise) immediately.
_______________________________



view thread (3+ messages)

Message-ID: <42CA9887.7000603@PresiNET.com>
Permalink:  ../42CA9887.7000603@PresiNET.com/
Also on:    postgresql.org/message-id/42CA9887.7000603@PresiNET.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: BAnderson@PresiNET.com, dpandey@secf.com
  Subject: Re: Create connection with Oracle database from Postgres plpgsql
  In-Reply-To: <42CA9887.7000603@PresiNET.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox