Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2008
    Posts
    7

    Unanswered: 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;
    ************************************************** ************************************************** *************************

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    This problem really has NOTHING to do with Oracle directly
    & is simply a PERL coding issue.

    The solution is to create/construct/build a text string which contains the desired SELECT statement; such as $SQL_statement = ......
    @output = $t->cmd($SQL_statement);
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Oct 2008
    Posts
    7
    Hi anacedent,
    Thank You so much for your reply . However I am still facing the same problem.The command is taking variable name as an exact value.

    Thank You so much for you concern and time.
    Regards
    Vivek

  4. #4
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >The command is taking variable name as an exact value.
    Then you are not coding the solution correctly.
    The variable substitution needs to occur when $SQL_statement is "built".
    Research the qq() function of Perl.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  5. #5
    Join Date
    Oct 2008
    Posts
    7
    Thank You anacedent.I got the stsement to work but the thing is that when I pass a string as an variable it gives me wrong value. However when I pass variable as an integer it get the correct output.

    I also want to pass the sql query stsement which spans two lines i.e , How can I use the qq() function on it?
    Thank You
    Vivek

  6. #6
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    You can see the code involved & can't understand what is or is not happening.
    Why do you expect others to be able to debug code that they have never seen?

    >How can I use the qq() function on it?
    Too bad GOOGLE is broken for you.
    Please wait for repairs on GOOGLE to be completed.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •