사용자 도구

사이트 도구


develop:perl:oracle

문서의 이전 판입니다!


Perl + Oracle 연동

사전작업

  1. apt-get 을 이용하여 패키지 설치
    # apt-get install libdbi-test-perl

sample code test

  1. #!/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 itemcode from tb_item where rownum < 5";
    my $itemcode;
    #
    my $sth = $dbh->prepare($que);
    $sth->execute() || die $sth->errstr;
    while( ($itemcode) = $sth->fetchrow() ) {
        print "select * from tb_studyunit where itemcode=$itemcode ;\n";
    }
    $sth->finish();
     
    $dbh->disconnect;
develop/perl/oracle.1496037887.txt.gz · 마지막으로 수정됨: 2017/05/29 15:04 저자 starlits