Help needed in script and sql file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed in script and sql file
# 1  
Old 03-20-2008
Help needed in script and sql file

Hi all,
I have a script which takes in sqlfile as argument and executes the sql

execSqlFile()
{
sqlFile=$1
sqlplus -S $DBLOG/$DBPWD@$DBSVR < $sqlFile
}

This works fine if the sql file is plain, simple and pre-defined statment. But i want to have a sql file which itself will take an argument

What do i need to modify in my script?

Please help!
jak
# 2  
Old 03-20-2008
First you have to embed argument stubs into your script...

mysql.sql might be

select x, z from t where x = $1 and z = $2;

Obviously very simple example...

then just pass arguments to script on command line...

execSqlFile()
{
sqlFile=$1
arg1 = "abc"
arg2 = "def"
sqlplus -S $DBLOG/$DBPWD@$DBSVR < $sqlFile $arg1 $arg2
}

It's that simple...
# 3  
Old 03-22-2008
Thanks for the help
jak
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Code needed to get sql queries

Hi i need code to get sql queries through a shell script for a text file input which contain the service ids iputfile I-H-2048-10GB-M I-H-4096-12GB-M I-H-2048-p1000-M the code should contain below queries among which service_id is replacable with value from input file. ... (4 Replies)
Discussion started by: surender reddy
4 Replies

2. Programming

sql guide needed

SQL> select 2 distinct qc_m|| ',' || 3 to_char(logon_dt, 'YYYY-MM-DD HH24:MI:SS')|| ',' || 4 CASE WHEN logon_dt IS NOT NULL THEN 'LOGON' ELSE 'LOGOFF' END 5 from qc_ct2 qc left join v_tls_equipment_logon tls on qc.qc_m=tls.equipment_id where 6 qc.terminal_c='T'and... (1 Reply)
Discussion started by: ment0smintz
1 Replies

3. Shell Programming and Scripting

Guidance needed for a typical shell script with sql query

Hi , I have a txt file with contents like: 1234 2345 3456 7891 I need to write a script which takes input file as txt file..run a sql query for that number and place the output of query in another file.. select * from bus_event where acct_nbr='1234'( from input txt file) the query... (20 Replies)
Discussion started by: Rajesh Putnala
20 Replies

4. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

5. Shell Programming and Scripting

Help needed with KSH and SQL

Hi All I have a problem with one of my scripts which checks for he status of an Oracle database. Here's the script: #!/bin/ksh sqlplus -s '/nolog' <<EOF connect / as sysdba set heading off spool db_status.txt select OPEN_MODE from v\$database / exit EOF db_status=$(more... (4 Replies)
Discussion started by: huskie69
4 Replies

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

7. UNIX for Dummies Questions & Answers

Execute PL/SQL function from Unix script (.sql file)

Hi guys, I am new on here, I have a function in oracle that returns a specific value: create or replace PACKAGE BODY "CTC_ASDGET_SCHED" AS FUNCTION FN_ASDSCHEDULE_GET RETURN VARCHAR2 AS BEGIN DECLARE ASDSchedule varchar2(6); ASDComplete... (1 Reply)
Discussion started by: reptile
1 Replies

8. Shell Programming and Scripting

(Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script

Hi, I need help urgently for following issue. Pls help me to resolve this issue. I am calling sql script file(file1.sql) from UNIX Shell Script(script1.ksh) using sql plus and trying to create flat file that contains all records returned from SQL query in SQL script(file1.sql) I given... (6 Replies)
Discussion started by: praka
6 Replies

9. Shell Programming and Scripting

Confirmation needed while running the sql's

Hi, I need confirmation whether the same functionality exists when running the sql's. For ex. let us consider there exists a sql file with name june.When running in sql mode does: @june.sql and start june.sql does the same functionality. Someone help me. Thanks Ashok. (1 Reply)
Discussion started by: Ashok_oct22
1 Replies

10. Shell Programming and Scripting

Script needed to FTP a file from sql report to unix server

Hi All, I have a Sqlplus report which will create a file. I need a FTP Script that will be executed inside the Sqlplus Report to FTP the report output file to unix server. Thanks, Previn (0 Replies)
Discussion started by: vprevin
0 Replies
Login or Register to Ask a Question