Category: Database
Author/Contact Info Mike Sullivan mps@discomsys.com
Description: Just a simple script to dump the source for an Oracle view.

The script reads the TEXT field from DBA_VIEWS, but first has to determine how long the field is since Oracle defines this column as a LONG.

Pretty simple quick hack, but people I work with have found it helpful.

Note: I'm using O/S authentication with a user who has DBA privs when I run this. If you're familiar with the DBI, you should be able to make appropriate changes to work for you.

#!/usr/bin/perl
#
# Written by: Mike Sullivan  (mps@discomsys.com)
#
# Distributed Computing Systems, LLC
#
# Feel free to hack on this and if you think of anything interesting
# to add to it, let me know and I'll try to add it into the master
# copy I have and post the mods for all to use.
#
# Enjoy.

use DBI;

$lda = DBI->connect("dbi:Oracle:$ENV{ORACLE_SID}", '/', '');

$lda->{LongTruncOk} = 1;

print "Enter viewname: ";
while(<STDIN>) {
   chomp($viewname = $_);
   $viewname = uc($viewname);
   $csr = $lda->prepare("select text_length
                              from dba_views
                              where view_name = \'$viewname\'");
   $csr->execute;
   ($text_length) = $csr->fetchrow_array;
   $lda->{LongReadLen} = $text_length;
   $csr = $lda->prepare("select text
                              from dba_views
                              where view_name = \'$viewname\'");
   $csr->execute;
   ($text) = $csr->fetchrow_array;

   print "Long text filed length: $text_length\n\n";
   print "$text\n";
   print "Enter viewname: ";
}

print "\n";
exit;