Oracleでユーザが所有するテーブルの一覧を表示する

#!/usr/bin/env perl

use DBI;

$ENV{ORACLE_HOME}='/u01/app/oracle/product/11.2.0/xe';
$ENV{ORACLE_SID}='XE';
$ENV{NLS_LANG}='JAPANESE_JAPAN.AL32UTF8';
$ENV{NLS_DATE_FORMAT}='yyyy/mm/dd hh24:mi:ss';
$user = 'hr';
$password = '******';

if($#ARGV!=0){
  die "usage: show_user_tables.pl <user>";
}

$sql=<<EOS;
select table_name
from all_tables
where owner='$ARGV[0]'
order by table_name
EOS

$dbh = DBI->connect("dbi:Oracle:$ENV{ORACLE_SID}",$user,$password);
$sth = $dbh->prepare($sql);
$sth->execute();
while(@row=$sth->fetchrow_array()){
  print join(',',@row),"\n";
}
$sth->finish();
$dbh->disconnect();


実行例

$ ./show_user_tables.pl
usage: show_user_tables.pl  at ./show_user_tables.pl line 13.
$ ./show_user_tables.pl hr
$ ./show_user_tables.pl HR
COUNTRIES
DEPARTMENTS
EMPLOYEES
JOBS
JOB_HISTORY
LOCATIONS
REGIONS
$