Connecting Tech Pros Worldwide Help | Site Map

Perl Database SQL query variable passing

Newbie
 
Join Date: Feb 2007
Posts: 4
#1: Jan 27 '09
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
Expand|Select|Wrap|Line Numbers
  1. $IPAddress = "10.24.30.1";
  2. $Login = "root";
  3. $password = "root";
  4. $Node = "hostname";
  5.  
  6. use Net::Telnet();
  7. $t= new Net::Telnet (Timeout => 3000 , Prompt => '/[%#\$>?:] $/' );
  8. $t->open("$IPAddress");
  9. print "\nConected!";
  10. $t->waitfor('/login: $/i');
  11. $t->print($Login);
  12. print "\nEntered the Username\n";
  13. $t->waitfor('/assword: $/i');
  14. $t->print($Password);
  15. print "\nEntered the Password!\n";
  16. @output=$t->cmd("export ORACLE_SID=$Node\n");
  17. print @output;
  18. print "\n Done with logging into the database\n";
  19. @output= $t->cmd("bash\n");
  20. print FILE @output;
  21. print @output;
  22. @output = $t->cmd("sqlplus username/pass\n");
  23. print @output;
  24. @output = $t->cmd("conn cusername/pass\n");
  25. print @output;
  26. @output = $t->cmd("SELECT * FROM TABLE_NAME WHERE INSTANCE_NAME LIKE '%hostname%' AND PARAM_KEY_NAME LIKE '%host';");
  27. print FILE @output;
  28. @output = $t->cmd("exit\n");
  29. print @output;
  30. @output = $t->cmd("exit\n");
  31. print @output;
  32.  
Reply