I don't usually visit here. I should change that fact. So I thought I would share a solution that helped me. I apologize if this has publised before as I did not find this here. I am really a MySQL user for many years. Recently I had to deal with Oracle which I had not touched in 9+ years. So I needed a Quick Strategy to Connect to Oracle DB from Perl script. I hope this helps someone else...

"My Thanks to Michael's Blog for this ...

After successful installation of DBD::Oracle it’s time to use it. The connection string is the same as for he rest DB: my $dbi=

DBI->connect("dbi:Oracle:$db_name:$db_host:$db_port", $db_user, $db_pa +ss);

As result of running code above I got following error:

 Couldn't connect to database db_name: ORA-12154: TNS:could not resolve the connect identifier specified (DBD ERROR: OCIServerAttach)

After googling I found that the problem was that. I tried to connect to the remove database but the driver couldn’t do that without special file – tnsnames.ora. It should be placed to the $ORACLE_HOME/network/admin and contain something like that:

db_name = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = db_host)(PORT = db_port)) ) (CONNECT_DATA = (SERVICE_NAME = db_name) ) )

And the connection string should be changed to use service name from the tnsnames.ora instead of host:

 my $dbi = DBI->connect("dbi:Oracle:$service_name", $db_user, $db_pass);

Finally we should export variable ORACLE_SID into our environment. Add this command into .bashrc

export ORACLE_SID="orcl"

or set it using Perl variable $ENV:

$ENV{ORACLE_SID} = 'orcl';

In reply to RFC: Oracle Perl Connection by sqlpython

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.