• Perl DBI模块


    一: select 某些字段:
    
    [oracle@jhoa dbi]$ cat 1.pl 
    use DBI; 
    my $dbName = 'orcl';  
    my $dbUser = 'test';  
    my $dbUserPass = 'test';  
    my $dbh = DBI->connect("dbi:Oracle:$dbName", $dbUser, $dbUserPass) or die "can't connect to database " ;
    my $hostSql = qq{select table_name,tablespace_name,status from user_tables};  
     
    
    my ($table_name, $tablespace_name, $status);  
    my $selStmt = $dbh->prepare($hostSql);  
    $selStmt->bind_columns(undef, $table_name, $tablespace_name, $status);  
    $selStmt->execute();  
    while( $selStmt->fetch() ){  
    	print "$table_name		   $tablespace_name		$status
    ";  
    }  
    $selStmt->finish;  
    
    
    
    [oracle@jhoa dbi]$ perl 1.pl 
    T200		   TEST_DATA		VALID
    B		   TEST_DATA		VALID
    A1		   TEST_DATA		VALID
    T2		   TEST_DATA		VALID
    TEST_UNDO1		   TEST_DATA		VALID
    TEST10		   TEST_DATA		VALID
    A2		   TEST_DATA		VALID
    HWM_TEST		   HWM_TEST_TBS		VALID
    T		   TEST_DATA		VALID
    A		   TEST_DATA		VALID
    A10		   TEST_DATA		VALID
    A7		   TEST_DATA		VALID
    DISK_INFO		   TEST_DATA		VALID
    BFW_TEST		   BFW_TBS		VALID
    T1		   TEST_DATA		VALID
    GCIMONITOR_INFO		   TEST_DATA		VALID
    A11		   TEST_DATA		VALID
    A8		   TEST_DATA		VALID
    
    二:select  * 全部列
    [oracle@jhoa dbi]$ cat 2.pl 
    #!/usr/bin/perl   
    use strict;  
    use DBI;  
    my $dbName = 'orcl';  
    my $dbUser = 'test';  
    my $dbUserPass = 'test';  
    my $dbh = DBI->connect("dbi:Oracle:$dbName", $dbUser, $dbUserPass) or die "can't connect to database ";
    my $sql = "select * from T100";  
    my $sth = $dbh->prepare($sql);  
    
    $sth->execute();  
    
    while (my  @arr = $sth->fetchrow_array()){
    print "
    @arr
    ";
    }
      
    $sth->finish; 
    $dbh->disconnect; 
    
    [oracle@oadb perl]$ cat t1.pl 
    use DBI;
    use Encode;
    use Data::Dumper;
    my $dbName = 'oadb';
    my $dbUser = 'system';
    my $dbUserPass = 'a2p13mvh';
    my $dbh = DBI->connect("dbi:Oracle:$dbName", $dbUser, $dbUserPass) or die "can't connect to database ";
    my $hostSql = qq{select trim(id),trim(a1),trim(a2) from T2};
    my $UNLOAD_SRC_DBCONN = DBI->connect("DBI:Oracle:".$dbName,$dbUser,$dbUserPass) or die("DB connect error!n");
    use HTTP::Date qw(time2iso str2time time2iso time2isoz);
    my $selStmt = $dbh->prepare($hostSql);
    $selStmt->execute();
    while(my $Rows = $selStmt->fetchrow_arrayref){
       push (@all, $Rows);
    } ;
    foreach (@all){
      $tmpstr="";
      foreach $a ( @{$_}){
      $tmpstr=$tmpstr.$a."|"; 
    };
    print $tmpstr;
    print "
    ";
    };


    
                                        
    
  • 相关阅读:
    Python 变量回收
    centos服务器内部开启端口
    mysql启动不起来汇总
    torch中DataLoader加载字典
    torch.meshgrid函数
    如何配置好python脚本的命令行参数
    git忽略文件,.gitignore配置
    jupyter如何解析命令行参数argv
    怎么制作虚拟环境的yaml
    如何提高matplotlib在jupyter中作图的分辨率
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351924.html
Copyright © 2020-2023  润新知