Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl in Oracle, how to get output from v$ tables 1

Status
Not open for further replies.

rozecm

Programmer
Joined
May 21, 2007
Messages
7
Location
DE
Hi All,
I have created a script which connects to the oracle database and to do select from any table, but if I want to get info from v$ tables, I have an issue. Any help is appreciated.
 
#!/usr/bin/perl

$s = qx{sqlplus -s "/ as sysdba" <<EOF
set head off
select * from dba_tables where rownum<5;
exit
EOF };

@lines = split /\n/, $s;
for ($i = 0; $i < scalar @lines; $i++)
{ print "This is line $i: $lines[$i].\n";
}

this script is working right, but if I will change the table name to v$controlfile will get error message:

#!/usr/bin/perl
$ctlfiles="select name from v\$controlfile";

$s = qx{sqlplus -s "/ as sysdba" <<EOF
set head off;
$ctlfiles;
exit
EOF };

@lines = split /\n/, $s;
for ($i = 0; $i < scalar @lines; $i++)
{ print "This is line $i: $lines[$i].\n";
}

output:
This is line 0: select name from v.
This is line 1: *.
This is line 2: ERROR at line 1:.
This is line 3: ORA-00942: table or view does not exist.
 
If your shelling out the way you are your going to have to add more slashes in front of that $ I think a total of 3 (1 for perl, one for the system, and another so perl ignores the 2nd one?)

Why don't you just use the DBI module?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
Hi Travis, you are right!!! Big thanks for help.
I am not going to use DBI module because I am developing tool which must use only standard perl installation. I am on multi vendor environment and it is not easy to get permission to install anything on the system.

Best Regards,
Martin.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top