·  PERL – DB – Oracle – Connect – DBI

 

- Info:

  - This tutorial shows how to connect to oracle DB from PERL using DBi.

 

- Example:

  - Create "PERL Application" Test.pl.

 

    Test.pl

    print "Content-type:text/plain\n\n";

    

    use DBI;

    

    eval {  #Catch exceptions.

    

      #CONNECT TO DB.-----------------------------------------------------------------------------------

      $db      = 'dbi:Oracle:XE';    

      $user    = 'myUser';

      $password= 'myPassword';

      $conn    = DBI->connect($db,$user,$password,{PrintError=>0});

      

      #DEFINE STATEMENT.--------------------------------------------------------------------------------

      $select  = "SELECT 1 FROM DUAL";

      $select  = $conn->prepare($select);

      

      #EXECUTE STATEMENT.-------------------------------------------------------------------------------

      $select  ->execute;

      

      #GET ROWS.----------------------------------------------------------------------------------------

      while (@row = $select->fetchrow_array) {  #Load next row into array.

        $result = $row[0];                      #Get value of first column listed after SELECT.

        

        print("$result");

      }

      

      #CLOSE DB CONNECTION.-----------------------------------------------------------------------------

      $select ->finish;

    

    };

    if ($@) {

      print($DBI::errstr);

    }

 

    

    tnsnames.ora      (H:\Installed\Programming\Oracle10gXE\app\oracle\product\10.2.0\server\NETWORK\ADMIN)

    XE =

      (DESCRIPTION =

        (ADDRESS = (PROTOCOL = TCP)(HOST = ivordesktop)(PORT = 1521))

        (CONNECT_DATA =

          (SERVER = DEDICATED)

          (SERVICE_NAME = XE)

        )

      )