#!/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 ";
if ($#ARGV <0){
print "请输入一个参数\n";
exit(-1);
}
my $var=$ARGV[0];
my $sql = $var;
if ($var =~ /select\s+(.+)\s+from\s+.*/i){ $a = $1};
my @arr = (split /,/,"$a");
foreach (@arr){
print "$_"." ";
}
my $sth = $dbh->prepare($sql);
$sth->execute();
while (my @arr = $sth->fetchrow_array()){
print "\n@arr\n";
}
sh-3.2$ perl a5.pl "SELECT sid,serial# ,module from v\$s
Perl自动格式输出select 结果
最新推荐文章于 2024-07-15 22:13:36 发布
这是一个使用Perl脚本连接Oracle数据库并自动格式化显示`select`查询结果的例子。用户输入SQL查询语句,脚本将提取列名并逐行打印查询结果。在示例中,展示了查询`v$session`表的`sid`, `serial#`, `module`字段的数据。"
111370293,10292863,K-Means与模糊c均值聚类算法解析,"['机器学习', '无监督学习', '聚类算法', '数据挖掘', 'K-Means']
摘要由CSDN通过智能技术生成