Sponsored Content
Top Forums Shell Programming and Scripting add the output of a query to a variable to be used in another query Post 302300702 by hazno on Tuesday 24th of March 2009 08:52:49 PM
Old 03-24-2009
add the output of a query to a variable to be used in another query

I would like to use the result of a query in another query. How do I redirect/add the output to another variable?

PHP Code:
$result odbc_exec($connect$query);
while (
$row odbc_fetch_array($result)) {
        echo 
$row["host"],"\n";
}
odbc_close($connect);
?> 
This will output hostnames:

host1 host2 host3

I would like to add the output to the variable $hosts something like this:

$hosts = "host1,host2,host3"

I plan to use $host in another query further down in the script.

thanks & regards
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to store the sql query's output in a variable

Hi, My requirement is : We are calling an sql statement from a UNIX session, and fetching data into some variables from a table .. now we are unable to access these variables from outside the SQL part. Please let me know how can I achieve this. Can you please share a code snippet which... (4 Replies)
Discussion started by: venkatesh_sasi
4 Replies

2. UNIX for Dummies Questions & Answers

Redirect Query o/p to variable

Hi, I wanted to o/p the number of rows in a table to a variable in linux. How can i achieve this. I wrote the query and its settings like feedback, pagesize line size in a file and using this file as a parameter to the sqlplus command. now can i redirect the o/p of that query to a variable.... (2 Replies)
Discussion started by: Swapna173
2 Replies

3. Solaris

awk output query

Hi Everyone, When i issue command like ls -l | awk '/udtts/ {print $9}' =============================== I am getting output as udttsGEHLNAR.6864 udttsGEHLNAR.7921 udttsNARALAX.15415 udttsNARALAX.18016 But I want output after dot i.e like 6864 7921 15415 18016 (3 Replies)
Discussion started by: gehlnar
3 Replies

4. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

5. Shell Programming and Scripting

How to use a variable in insert query?

My script contains as follows, VALUE=`sqlplus un/pwd <<EOF > OB.txt set pagesize 0 feedback off verify off heading off echo off select max(1) from table1; exit; EOF` insert into table2 values(1, 'The max value is $value',...); i need the value of VALUE to be inserted after 'The max... (2 Replies)
Discussion started by: savithavijay
2 Replies

6. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

7. UNIX for Dummies Questions & Answers

UNIX Query About wc -l output

I was performing the wc -l operation in one data file the result is less when i was giving -nu on the view of the file. while giving wc -l the count is 5023 after setting line numbers in view of file is giving 5024. Can anyone help on this.... (5 Replies)
Discussion started by: abhii
5 Replies

8. Shell Programming and Scripting

Getting variable from a query

Hi, I need to get a variable HMAX_TBL_ID and then use it in second select query. The first select statement returns few leading white spaces for ex : 12345 so when I run the script HMAX_TBL_ID does not return the "12345" , it returns blank. Please let me know what I am missing. ... (1 Reply)
Discussion started by: sandy162
1 Replies

9. Shell Programming and Scripting

How to pass variable to a query?

Hi All, How to pass date variable to a query? I have tried the below one , but it's not working. ost.ksh #!/bin/ksh v_date=$1 var=$(sqlplus -s $ORACON <<ENDOFSQL SELECT TO_DATE('$v_date','DD-MON-YYYY'),-1) FROM DUAL; exit; ENDOFSQL ) #End I have executed as below. (7 Replies)
Discussion started by: ROCK_PLSQL
7 Replies

10. Shell Programming and Scripting

How to Assign the Output of an SQL Query to a Variable?

Hi iam new to shell scripting how to declare variables as redshift query and I have to compare two counts by using if condition . ex:count=select count(*) from prd; select count(*) from prd; select count(*) from tag; can any one help me . Please use CODE tags when displaying... (1 Reply)
Discussion started by: sam526
1 Replies
RDF::Redland::QueryResults(3pm) 			User Contributed Perl Documentation			   RDF::Redland::QueryResults(3pm)

NAME
RDF::Redland::QueryResults - Redland RDF Syntax Query Results Class SYNOPSIS
use RDF::Redland; ... my $query=new RDF::Redland::Query("query string", undef, undef, "sparql"); my $results=$model->query_execute($query); # or my $results=$query->execute($model); while(!$results->finished) { for (my $i=0; $i < $results->bindings_count(); $i++) { my $name=$results->binding_name($i); my $value=$results->binding_value($i); # ... do something with the results } $results->next_result; } The $results in the example is an object of class RDF::Redland::QueryResults. DESCRIPTION
This class represents queries of various syntaxes over an RDF::Redland::Model returning a sequence of results that bind variable names to RDF::Redland::Node values. CONSTRUCTOR
There are no public constructors. METHODS
count Return the number of current results from the query. finished Return non-0 if the results have been exhausted. binding_name INDEX Get the name of variable binding INDEX in the array of variable names. binding_names Get the names all of the variable bindings as an array. binding_value INDEX Get the value of the variable binding INDEX in the current query result. binding_values Get the values of all of the variable bindings in the current query result. binding_value_by_name NAME Get the value of the variable binding NAME in the current query result. bindings Get the variable names and values of the current query result as a hash bindings_count Return the number of variable bindings. next_result Move to the next query result. as_stream Return a new RDF::Redland::Stream object representing the query results as an RDF Graph. to_string [FORMAT-URI [BASE-URI]] Serialize to a string syntax in format FORMAT-URI using the optional BASE-URI. The default format when none is given is determined by librdf_query_results_to_string. is_bindings Return non-0 if the query results format is variable bindings is_boolean Return non-0 if the query results format is a boolean is_graph Return non-0 if the query results format is an RDF graph get_boolean Get the boolean query result; non-0 is true. SEE ALSO
RDF::Redland::Query AUTHOR
Dave Beckett - http://www.dajobe.org/ perl v5.14.2 2011-02-04 RDF::Redland::QueryResults(3pm)
All times are GMT -4. The time now is 11:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy