Sponsored Content
Top Forums Shell Programming and Scripting UNIX variable to SQL statement Post 302748149 by Yoda on Monday 24th of December 2012 10:53:41 AM
Old 12-24-2012
Your export is wrong, you are missing a $ sign
Code:
read app_instance_id
echo "id is $app_instance_id"
export app_id=$app_instance_id

BTW you can read value directly into app_id, no need to read it in one variable and later export it to a different variable.

Also put your query inside the SQL block rather than calling it from a file:
Code:
sqlplus -s nnviewer/lookup@//nasolora008.enterprisenet.org:1521/LOAD3 << EOF
SPOOL /home/tibco/MCH/Data/qa/raak/name.xls
select * from NSPL_561.CL1_APP_INSTANCE where APP_INSTANCE_ID=$app_id;
SPOOL OFF
EXIT;
EOF

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sql query variable not exactly unix

I know htis isnt exactly unix.... but hopefully someone can help me or direct me someplace to get help. I can run sql queries in scripts against my informix db using: dbaccess mydb myquery.sql >> sql.output I need to write my script to select based on todays date. Its very... (5 Replies)
Discussion started by: MizzGail
5 Replies

2. Shell Programming and Scripting

Executing a Oracle SQL statement in a UNIX script

Hi All, I need to select one column from a table based upon the passed in parameter. I tried this: sqlplus -silent $MISP_USER << EOF set feedback off; set verify off; set sqlprompt "" SELECT mail_flag FROM dailyjobs WHERE job_name = '$1'; exit 0 EOF exit... (1 Reply)
Discussion started by: ganga.dharan
1 Replies

3. Shell Programming and Scripting

how to pass a variable to an update sql statement inside a loop

hi all, i am experiencing an error which i think an incorrect syntax for the where clause passing a variable was given. under is my code. sqlplus -s ${USERNAME}/${PASSWORD}@${SID} << END1 >> $LOGFILE whenever sqlerror exit set serveroutput on size 1000000 declare l_rc ... (0 Replies)
Discussion started by: ryukishin_17
0 Replies

4. Shell Programming and Scripting

Using Unix Variable in a PL/SQL block

Hi, I have a unix varaible called as account which hold values which i want to use in a PL/SQL block in a shell script. This variable value is being used in multiple places in the PL/SQL block and i get an erroe whenenevr is use this varaible with $prompt. Help Urgently (1 Reply)
Discussion started by: sumi_mn
1 Replies

5. Shell Programming and Scripting

I want to get the Unix variable value in the sql stmt

Hi All I have a requirement where in I am stuck. There is a shell script that is being developed by me. It consist of the sql stmt also. I need to export a variable called HOMEPAGE with a value say www.abc.com. and then use this $HOMEPAGE variable in the sql stmt. My ultimate aim is to fetch all... (1 Reply)
Discussion started by: amitsinha
1 Replies

6. Shell Programming and Scripting

Unix shell command output to a sql statement

Can i do this Say one command sed 's/:*/ /g' $summf is returning C1234 C2345 C3434 some no of rows, now this ouput i have to insert it into a DB table how do i do this?? (2 Replies)
Discussion started by: depakjan
2 Replies

7. UNIX for Dummies Questions & Answers

unix script with SQL statement problem

Hello, I have a script to get the information from database, however, it's look like the loop is not work, can someone help? :confused: echo Input file list to check: read filelist for file in 'cat $filelist.txt' do echo "select FILENAME from FILE_TABLE where filename like '${file}'%;" >>... (9 Replies)
Discussion started by: happyv
9 Replies

8. UNIX for Dummies Questions & Answers

SQL statement is not work on unix script

Hi, I have the following basic script. However, the statement (line 5) is not work. The output data is not able to set my request format a30. Any advise? :mad: echo " Column filename format a30"|sqlplus4 echo Input file list to check: read filelist for file in `cat $filelist.txt` do... (1 Reply)
Discussion started by: happyv
1 Replies

9. Shell Programming and Scripting

SQL output to UNIX variable

I have a sql statement , i need to assign to a variable in Unix sel count(*) AS num_files from TABLE_A; i need to use "num_files" in unix statements. let me know how to assign unix variable to above num_files (1 Reply)
Discussion started by: nani1984
1 Replies

10. Shell Programming and Scripting

UNIX Sqlplus - Capture the sql statement about to run and execution status

Greetings Experts, I am on AIX using ksh. Created a unix script which generates the CREATE OR REPLACE VIEW ... and GRANT .. statements, which are placed in a single .txt file. Now I need to execute the contents in the file (there are around 300 view creation and grant statements) in Oracle and... (4 Replies)
Discussion started by: chill3chee
4 Replies
PDO.PREPARE(3)								 1							    PDO.PREPARE(3)

PDO
::prepare - Prepares a statement for execution and returns a statement object SYNOPSIS
public PDOStatement PDO::prepare (string $statement, [array $driver_options = array()]) DESCRIPTION
Prepares an SQL statement to be executed by the PDOStatement.execute(3) method. The SQL statement can contain zero or more named (:name) or question mark (?) parameter markers for which real values will be substituted when the statement is executed. You cannot use both named and question mark parameter markers within the same SQL statement; pick one or the other parameter style. Use these parameters to bind any user-input, do not include the user-input directly in the query. You must include a unique parameter marker for each value you wish to pass in to the statement when you call PDOStatement.execute(3). You cannot use a named parameter marker of the same name more than once in a prepared statement, unless emulation mode is on. Note Parameter markers can represent a complete data literal only. Neither part of literal, nor keyword, nor identifier, nor whatever arbitrary query part can be bound using parameters. For example, you cannot bind multiple values to a single parameter in the IN() clause of an SQL statement. Calling PDO.prepare(3) and PDOStatement.execute(3) for statements that will be issued multiple times with different parameter values opti- mizes the performance of your application by allowing the driver to negotiate client and/or server side caching of the query plan and meta information, and helps to prevent SQL injection attacks by eliminating the need to manually quote the parameters. PDO will emulate prepared statements/bound parameters for drivers that do not natively support them, and can also rewrite named or ques- tion mark style parameter markers to something more appropriate, if the driver supports one style but not the other. PARAMETERS
o $statement - This must be a valid SQL statement for the target database server. o $driver_options - This array holds one or more key=>value pairs to set attribute values for the PDOStatement object that this method returns. You would most commonly use this to set the PDO::ATTR_CURSOR value to PDO::CURSOR_SCROLL to request a scrollable cursor. Some drivers have driver specific options that may be set at prepare-time. RETURN VALUES
If the database server successfully prepares the statement, PDO.prepare(3) returns a PDOStatement object. If the database server cannot successfully prepare the statement, PDO.prepare(3) returns FALSE or emits PDOException (depending on error handling). Note Emulated prepared statements does not communicate with the database server so PDO.prepare(3) does not check the statement. EXAMPLES
Example #1 Prepare an SQL statement with named parameters <?php /* Execute a prepared statement by passing an array of values */ $sql = 'SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'; $sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); $sth->execute(array(':calories' => 150, ':colour' => 'red')); $red = $sth->fetchAll(); $sth->execute(array(':calories' => 175, ':colour' => 'yellow')); $yellow = $sth->fetchAll(); ?> Example #2 Prepare an SQL statement with question mark parameters <?php /* Execute a prepared statement by passing an array of values */ $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < ? AND colour = ?'); $sth->execute(array(150, 'red')); $red = $sth->fetchAll(); $sth->execute(array(175, 'yellow')); $yellow = $sth->fetchAll(); ?> SEE ALSO
PDO.exec(3), PDO.query(3), PDOStatement.execute(3). PHP Documentation Group PDO.PREPARE(3)
All times are GMT -4. The time now is 05:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy