Sponsored Content
Top Forums Shell Programming and Scripting I want to get the Unix variable value in the sql stmt Post 302448940 by felipe.vinturin on Friday 27th of August 2010 01:15:47 PM
Old 08-27-2010
Sorry, but I didn't understand your problem, but I can suggest you to keep SQL queries out of shell scripts, it keeps the code clear.

The other way to do it is to place the queries in files separated from the shell script and use Oracle SQLPlus substitution variables.

Check this link: SQL*Plus FAQ - Oracle FAQ

For example:
Code:
cat myQuery.sql
SET HEAD OFF
SET FEEDBACK OFF
SET VERIFY OFF
SELECT TO_DATE('&&1', 'YYYYMMDD') TEST FROM DUAL;
EXIT

And execute like below:
Code:
echo "START myQuery.sql 20100827" | sqlplus -S -L <user>/<pass>@${ORACLE_SID}

Regards.
 

9 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

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

3. Shell Programming and Scripting

convert file into sql insert stmt

My file is now cleaned, sanitized & prepped: 07/07/2008 21:18:51 Installation 52016 complete *BUT NOTHING CHANGED* 07/21/2008 15:28:15 Removal 52016 complete 07/21/2008 15:34:15 Removal 55856 complete 12/08/2009 19:30:40 Installation 62323 complete 12/08/2009 19:39:06 Installation ... (6 Replies)
Discussion started by: dba_frog
6 Replies

4. Shell Programming and Scripting

Help with Dates and SQl stmt?

hi All Please explain the below statement in RED?What does this mean? perl /HDS/common/operations/Quality_Team/Nirvana/WEEKLY_OOPS/sql_dump.pl --sql "select * from WEEKLY_REPORT order by test_case, type" --username=ddb_qa --password=ddb_qa123 --sid=pldeldb --output... (1 Reply)
Discussion started by: SVS_2017
1 Replies

5. Shell Programming and Scripting

Passing a string variable from Unix to Sql Plus

Hi Guys, I am trying to pass a string variable from Unix shell script to sqlplus as a parameter. I have tried using single quotes with the variable name but it does not work. Please help me with it. I am using BASH. My code: Your help is much appreciated. Thanks, shil (2 Replies)
Discussion started by: infintenumbers
2 Replies

6. Shell Programming and Scripting

How to use GOTO stmt in Unix scripting?

my code does somthing like this: #!bin/ksh sqlplus / | While read id do temp=`echo $id` i = i+1 done j=0 while do --connecting to sql and executing a Stored proc for 1st id --checking for the status status = $? if error --need to... (1 Reply)
Discussion started by: RP09
1 Replies

7. Shell Programming and Scripting

UNIX variable to SQL statement

The following is my script : #!/bin/bash echo "please give app_instance_id" read app_instance_id echo "id is $app_instance_id" export app_id=app_instance_id sqlplus -s nnviewer/lookup@//nasolora008.enterprisenet.org:1521/LOAD3 @test.sql<<EOF SPOOL /home/tibco/MCH/Data/qa/raak/name.xls... (4 Replies)
Discussion started by: raakeshr
4 Replies

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

9. Shell Programming and Scripting

Assign the return value of the SQL to a variable in UNIX

Hi I am new to UNIX. I am trying the below and getting the error. I am trying to assign the variable with the value of the query result. I want this value to use in the next steps. Created UNIX file (Batch.sh) as below #!/bin/ksh sqlplus callidus/callidus4u@attstcal @Batch.sql ... (2 Replies)
Discussion started by: KrishBalu
2 Replies
SQLSRV_FETCH_ARRAY(3)													     SQLSRV_FETCH_ARRAY(3)

sqlsrv_fetch_array - Returns a row as an array

SYNOPSIS
array sqlsrv_fetch_array (resource $stmt, [int $fetchType], [int $row], [int $offset]) DESCRIPTION
Returns the next available row of data as an associative array, a numeric array, or both (the default). PARAMETERS
o $stmt - A statement resource returned by sqlsrv_query or sqlsrv_prepare. o $fetchType - A predefined constant specifying the type of array to return. Possible values are SQLSRV_FETCH_ASSOC, SQLSRV_FETCH_NUMERIC, and SQLSRV_FETCH_BOTH (the default). A fetch type of SQLSRV_FETCH_ASSOC should not be used when consuming a result set with multiple columns of the same name. o $row - Specifies the row to access in a result set that uses a scrollable cursor. Possible values are SQLSRV_SCROLL_NEXT, SQL- SRV_SCROLL_PRIOR, SQLSRV_SCROLL_FIRST, SQLSRV_SCROLL_LAST, SQLSRV_SCROLL_ABSOLUTE and, SQLSRV_SCROLL_RELATIVE (the default). When this parameter is specified, the $fetchType must be explicitly defined. o $offset - Specifies the row to be accessed if the row parameter is set to SQLSRV_SCROLL_ABSOLUTE or SQLSRV_SCROLL_RELATIVE. Note that the first row in a result set has index 0. RETURN VALUES
Returns an array on success, NULL if there are no more rows to return, and FALSE if an error occurs. EXAMPLES
Example #1 Retrieving an associative array. <?php $serverName = "serverNameinstanceName"; $connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password"); $conn = sqlsrv_connect( $serverName, $connectionInfo ); if( $conn === false ) { die( print_r( sqlsrv_errors(), true)); } $sql = "SELECT FirstName, LastName FROM SomeTable"; $stmt = sqlsrv_query( $conn, $sql ); if( $stmt === false) { die( print_r( sqlsrv_errors(), true) ); } while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) { echo $row['LastName'].", ".$row['FirstName']."<br />"; } sqlsrv_free_stmt( $stmt); ?> Example #2 Retrieving a numeric array. <?php $serverName = "serverNameinstanceName"; $connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password"); $conn = sqlsrv_connect( $serverName, $connectionInfo ); if( $conn === false ) { die( print_r( sqlsrv_errors(), true)); } $sql = "SELECT FirstName, LastName FROM SomeTable"; $stmt = sqlsrv_query( $conn, $sql ); if( $stmt === false) { die( print_r( sqlsrv_errors(), true) ); } while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC) ) { echo $row[0].", ".$row[1]."<br />"; } sqlsrv_free_stmt( $stmt); ?> NOTES
Not specifying the $fetchType or explicity using the SQLSRV_FETCH_TYPE constant in the examples above will return an array that has both associative and numeric keys. If more than one column is returned with the same name, the last column will take precedence. To avoid field name collisions, use aliases. If a column with no name is returned, the associative key for the array element will be an empty string (""). SEE ALSO
sqlsrv_connect(3), sqlsrv_query(3), sqlsrv_errors(3), sqlsrv_fetch(3). PHP Documentation Group SQLSRV_FETCH_ARRAY(3)
All times are GMT -4. The time now is 04:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy