Sponsored Content
Top Forums Shell Programming and Scripting How to pass string into sql query? Post 302868813 by balajesuri on Tuesday 29th of October 2013 12:47:19 AM
Old 10-29-2013
Using positional parameters:

Code:
a=$1
b=$2
c=$3

sqlplus -s user/password@instance << EOF >>output.txt
set echo off head off feed off pagesize 0 trimspool on linesize 1000 colsep ,
select emp_no, emp_name from emp
where emp_no in ($a, $b, $c);
exit;
EOF


Last edited by balajesuri; 10-29-2013 at 01:53 AM..
This User Gave Thanks to balajesuri For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

pass result from one query to another

Can any one help me how to pass the value of result of one query to another query. I to pass the value of result of 'select max(id) from a' into another query like update table set col =<value from last query> where ....; updatestaging() { xx=`$ORACLE_HOME/bin/sqlplus -s... (1 Reply)
Discussion started by: u263066
1 Replies

2. Shell Programming and Scripting

Pass variable to sql

Please help. I got these error. I'm try to pass variable extract from data-file.txt to sql file(select.sql). cat: cannot open select cat: cannot open * cat: cannot open from cat: cannot open user cat: cannot open where cat: cannot open name=$list; #!/bin/bash list=`sed q... (3 Replies)
Discussion started by: killboy
3 Replies

3. Shell Programming and Scripting

How to use sql data file in unix csv file as input to an sql query from shell

Hi , I used the below script to get the sql data into csv file using unix scripting. I m getting the output into an output file but the output file is not displayed in a separe columns . #!/bin/ksh export FILE_PATH=/maav/home/xyz/abc/ rm $FILE_PATH/sample.csv sqlplus -s... (2 Replies)
Discussion started by: Nareshp
2 Replies

4. Shell Programming and Scripting

Pass a variable to SQL script

Hi Guys, I like to pass a variable to a sql file in a unix script.. I tried a below code.. var=200903 db2 -vf test.sql 200903 test.sql is as below. select * from db2.users where quarter = $1; Please tell me where i go wrong.. Thanks in advance, Magesh (2 Replies)
Discussion started by: mac4rfree
2 Replies

5. Programming

JDBC code to pass the SQL query as parameter and execute?

Below i have the sample code. i need to pass the entire query from file or as parameter and read the results and write into a output file. here the number of columns are unknown. some times it may be 2,3 or entire columns from the table. read all the column results and write into a comma... (0 Replies)
Discussion started by: laknar
0 Replies

6. Shell Programming and Scripting

Run SQL thru shell script: how to get a new line when run sql query?

Hi, this's Pom. I'm quite a new one for shell script but I have to do sql on shell script to query some information from database. I found a concern to get a new line...When I run my script, it retrieves all data as wondering but it's shown in one line :( What should I do? I'm not sure that... (2 Replies)
Discussion started by: Kapom
2 Replies

7. UNIX for Dummies Questions & Answers

To pass multiple arguments from file in to an sql query

Hi all , I want to pass contents from a file say f1 as arguments to a sql query which has In statement using a script example select * from table_1 where login in ( `cat f1`) ; will this work or is there any other way to do it. (1 Reply)
Discussion started by: zozoo
1 Replies

8. 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

9. Shell Programming and Scripting

Need script to pass all sql file names in a directory to DB query

Hi All, In this path /home/all_files we have follwing files and direcotries proc_edf_sot.sql proc_ssc_sot.sql func_dfg_sot.sql sot unic cmr sdc under sot directory we have other directories sql pas ref under sql directory we have sql_sot sql_mat (6 Replies)
Discussion started by: ROCK_PLSQL
6 Replies

10. Programming

Need sql query to string split and normalize data

Hello gurus, I have data in one of the oracle tables as as below: Column 1 Column 2 1 NY,NJ,CA 2 US,UK, 3 AS,EU,NA fyi, Column 2 above has data delimited with a comma as shown. I need a sql query the produce the below output in two columns... (5 Replies)
Discussion started by: calredd
5 Replies
PDO.QUERY(3)								 1							      PDO.QUERY(3)

PDO
::query - Executes an SQL statement, returning a result set as a PDOStatement object SYNOPSIS
public PDOStatement PDO::query (string $statement) DESCRIPTION
PDOStatement PDO::query (string $statement, int $PDO::FETCH_COLUMN, int $colno) PDOStatement PDO::query (string $statement, int $PDO::FETCH_CLASS, string $classname, array $ctorargs) PDOStatement PDO::query (string $statement, int $PDO::FETCH_INTO, object $object) PDO.query(3) executes an SQL statement in a single function call, returning the result set (if any) returned by the statement as a PDOStatement object. For a query that you need to issue multiple times, you will realize better performance if you prepare a PDOStatement object using PDO.pre- pare(3) and issue the statement with multiple calls to PDOStatement.execute(3). If you do not fetch all of the data in a result set before issuing your next call to PDO.query(3), your call may fail. Call PDOState- ment.closeCursor(3) to release the database resources associated with the PDOStatement object before issuing your next call to PDO.query(3). Note Although this function is only documented as having a single parameter, you may pass additional arguments to this function. They will be treated as though you called PDOStatement.setFetchMode(3) on the resultant statement object. PARAMETERS
o $statement - The SQL statement to prepare and execute. Data inside the query should be properly escaped. RETURN VALUES
PDO.query(3) returns a PDOStatement object, or FALSE on failure. EXAMPLES
Example #1 Demonstrate PDO::query A nice feature of PDO.query(3) is that it enables you to iterate over the rowset returned by a successfully executed SELECT state- ment. <?php function getFruit($conn) { $sql = 'SELECT name, color, calories FROM fruit ORDER BY name'; foreach ($conn->query($sql) as $row) { print $row['name'] . " "; print $row['color'] . " "; print $row['calories'] . " "; } } ?> The above example will output: apple red 150 banana yellow 250 kiwi brown 75 lemon yellow 25 orange orange 300 pear green 150 watermelon pink 90 SEE ALSO
PDO.exec(3), PDO.prepare(3), PDOStatement.execute(3). PHP Documentation Group PDO.QUERY(3)
All times are GMT -4. The time now is 03:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy