====== Perl + Oracle 연동 ====== ===== 사전작업 ===== - apt-get 을 이용하여 패키지 설치 # apt-get install libdbi-test-perl libdbix-abstract-perl make # apt-get install python3 python-dev python3-dev \ build-essential libssl-dev libffi-dev \ libxml2-dev libxslt1-dev zlib1g-dev \ python-pip ===== DBD::Oracle 설치 ===== - http://cpan.org 에서 DBD::Oracle 모듈을 설치한다. - http://search.cpan.org/~pythian/DBD-Oracle-1.74/lib/DBD/Oracle.pm - 컴파일해서 설치한다. $ perl Makefile.PL $ make $ sudo make install ===== Oracle Database Instant Client Installation ===== - [[dbms:oracle:admin:instantclient | Oracle Database Instant Client Installation ]] 을 참고한다. ===== sample code test ===== - #!/usr/bin/perl # use strict; use DBI; #There are many other security measures # - Also, don't forget to use a 'username' and 'password' for the DB # - Do Not use 'sa' and ''. ##################### DBI configuration ######################## my $hostip = "192.168.200.221"; my $username = "adminuser"; my $password = "password"; my $sid = "SOA01"; my $dsn = "DBI:Oracle:host=$hostip;sid=$sid"; my %attr = ( RaiseError => 1, AutoCommit => 0 ); # howto 1 my $dbh = DBI->connect ($dsn, $username, $password, \%attr) || die "Database connection not mode : $DBI::errstr"; # howto 2 #my $dbh = DBI->connect ("DBI:Oracle:host=$hostip;sid=$sid", $username, $password, \%attr); my $que = "select table_name from tabs where rownum < 5"; my $table_name; # my $sth = $dbh->prepare($que); $sth->execute() || die $sth->errstr; while( ($table_name) = $sth->fetchrow() ) { print "$table_name\n"; } $sth->finish(); $dbh->disconnect;