Perl Database SQL query variable passing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sonu2die4
    New Member
    • Feb 2007
    • 4

    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.P lease help me out with it.
    Thank You
    Vivek
    Code:
    $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;
    Last edited by debasisdas; Jan 27 '09, 05:59 PM. Reason: added code tags
Working...