If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > Perl Database SQL query variable passing

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-27-09, 12:57
sonu2die4 sonu2die4 is offline
Registered User
 
Join Date: Oct 2008
Posts: 7
Perl Database SQL query variable passing

Hi,
I have the following perl script working for me.I am accesing the database from my perl script using use Net::Telnet(); package.
I am not using DBI package.as I stataed earlier the following program is printing the output in a nice form.However I want to pass
a variable in the $t->cmd("SELECT * FROM TABLE_NAME WHERE INSTANCE_NAME LIKE '%hostname%' ;");
Here I want hostname to be replaced by a variable name like
$t->cmd("SELECT * FROM TABLE_NAME WHERE INSTANCE_NAME LIKE '%VARIABLE_NAME%';");.
I want just pass a variable in the above sql query so that I can change the VARIABLE_NAME.Please help me out with it.
Thank You
Vivek
*************************************************P rogram******************************************** *************
$IPAddress = "10.24.30.1";
$Login = "root";
$password = "root";
$Node = "hostname";

use Net::Telnet();
$t= new Net::Telnet (Timeout => 3000 , Prompt => '/[%#\$>?:] $/' );
$t->open("$IPAddress");
print "\nConected!";
$t->waitfor('/login: $/i');
$t->print($Login);
print "\nEntered the Username\n";
$t->waitfor('/assword: $/i');
$t->print($Password);
print "\nEntered the Password!\n";
@output=$t->cmd("export ORACLE_SID=$Node\n");
print @output;
print "\n Done with logging into the database\n";
@output= $t->cmd("bash\n");
print FILE @output;
print @output;
@output = $t->cmd("sqlplus username/pass\n");
print @output;
@output = $t->cmd("conn cusername/pass\n");
print @output;
@output = $t->cmd("SELECT * FROM TABLE_NAME WHERE INSTANCE_NAME LIKE '%hostname%' AND PARAM_KEY_NAME LIKE '%host';");
print FILE @output;
@output = $t->cmd("exit\n");
print @output;
@output = $t->cmd("exit\n");
print @output;
************************************************** ************************************************** *************************
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On