使用Perl管理Oracle数据库
1、连接数据库
#!/usr/bin/perl use strict; use DBI; my $tnsname = "DB234"; my $username = "SCOTT"; my $password = "TIGER"; my $dbh = DBI->connect("dbi:Oracle:$tnsname",$username,$password) or die "Cannot connect db : $DBI::errstr "; print "I have connect to the Oracle database! "; $dbh->disconnect or warn "DB disconnect failed:$DBI::errstr ";
2、插入数据
#!/usr/bin/perl use strict; use DBI; my $id = 9; my $name = 'jame'; my $dbh = DBI->connect("dbi:Oracle:DB234","u1","u1") or die "Cannot connect db :$DBI::errstr "; my $sql = qq{INSERT INTO T1 VALUES(?,?)}; my $sth = $dbh->prepare($sql); $sth->execute($id,$name); print "I have inserted the record! "; $dbh->disconnect or warn "DB disconnect failed:$DBI::errstr ";