SQL Report from UNIX


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers SQL Report from UNIX
# 8  
Old 10-10-2014
So you want to pass the name of the directory to process as a parameter and run all sql-scripts found there?
Code:
#!/usr/bin/sh

# check argument passed to the script
if [ $# -ne 1 ]; then
   echo 'Illegal number of arguments.'
   exit 1
else
   DIR_NAME=$1
fi

#oracle variables
ORACLE_HOME=/path/oracle/client
export ORACLE_HOME
SQLPLUS=$ORACLE_HOME/bin/sqlplus
export SQLPLUS
LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
TNS_ADMIN=/path/tnsnames
export TNS_ADMIN

# put a list of .sql files in the given directory in a temporary file
ls -1 $DIR_NAME/*.sql >/tmp/sql_script_list.$$ 2>/dev/null
if [ $? -ne 0 ]; then
   echo "No .sql files found in $DIR_NAME"
   exit 1
fi

while read SQL_FILE; do
   OUT=/report/path/$SQL_FILE.output
   $SQLPLUS -s "user/pass@database" << END_SQL > /dev/null

      SET ECHO OFF
      SET TERMOUT OFF
      SET PAGESIZE 50000
      SET LINESIZE 32767
      SET TRIMSPOOL ON

      SPOOL $OUT

      @ $DIR_NAME/$SQL_FILE

      SPOOL OFF
END_SQL
done </tmp/sql_script_list.$$
rm /tmp/sql_script_list.$$


Last edited by cero; 10-10-2014 at 08:24 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can i run sql queries from UNIX shell script and retrieve data into text docs of UNIX?

Please share the doc asap as very urgently required. (1 Reply)
Discussion started by: 24ajay
1 Replies

2. UNIX for Dummies Questions & Answers

SQL PLUS report formatting

Hi I am fetcthing the data from the oracle database using SQLPLUS. Here is my script #!/bin/ksh echo `sqlplus -s <<EOF set feedback off set linesize 5000 set pages 0 set space 0 set echo off set trimspool on set colsep '|' SELECT col1 , col2... (4 Replies)
Discussion started by: max_hammer
4 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. 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

5. Shell Programming and Scripting

unix variables from sql / pl/sql

How do I dynamically assign the below output to unix shell variables so I can build a menu in a shell script? Example: var1 = 1 var2= SYSTEM var3 = 2 var4= UNDOTBS1 and so on, then in the shell script I can use the variables to build a menu. set serveroutput on declare... (2 Replies)
Discussion started by: djehres
2 Replies

6. UNIX for Dummies Questions & Answers

SQL in Unix

Hi, I would like to access SQL plus from my unix, and learn to run some SQL scripts in Unix. How do i begin. Is there any known website that offers a quick tutorial or tips? Thanks, unxhopeful (4 Replies)
Discussion started by: unxhopeful
4 Replies

7. Shell Programming and Scripting

sql through unix.

when we are spooling query o/p to certain txt file,in that file how we can get headers in the query.(through unix shell scripting). for exmple q1="slect * from XXXXXX;"; sqlplus XXX/XXXX@XXXXX spool XXXX.txt $q1 spool off in the text file i want the headers of the query..... ... (1 Reply)
Discussion started by: bhagya.puccha
1 Replies

8. Shell Programming and Scripting

Using SQL in Unix

Please tell me how i can use SQL in my unix scripts. Please give examples. I just want to start writing some scripts for my use. Looking for ur cooperation. thanks (2 Replies)
Discussion started by: Mohit623
2 Replies

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

10. Shell Programming and Scripting

sql plus report under unix environment

Hi i am creating a report with file format csv using sql plus commands under unix environment. I am sending this report using mailx command to excel spread sheet. when i opened the report my columns are merged. I need to manually pull each column to see whole column results. Is there any way in... (0 Replies)
Discussion started by: raosurya
0 Replies
Login or Register to Ask a Question
SQL::Translator::Producer::SQLServer(3pm)		User Contributed Perl Documentation		 SQL::Translator::Producer::SQLServer(3pm)

NAME
SQL::Translator::Producer::SQLServer - MS SQLServer producer for SQL::Translator SYNOPSIS
use SQL::Translator; my $t = SQL::Translator->new( parser => '...', producer => 'SQLServer' ); $t->translate; DESCRIPTION
This is currently a thin wrapper around the nextgen SQL::Translator::Generator::DDL::SQLServer DDL maker. Extra Attributes field.list List of values for an enum field. TODO
* !! Write some tests !! * Reserved words list needs updating to SQLServer. * Triggers, Procedures and Views DO NOT WORK # Text of view is already a 'create view' statement so no need to # be fancy foreach ( $schema->get_views ) { my $name = $_->name(); $output .= " "; $output .= "-- -- View: $name -- " unless $no_comments; my $text = $_->sql(); $text =~ s/ //g; $output .= "$text GO "; } # Text of procedure already has the 'create procedure' stuff # so there is no need to do anything fancy. However, we should # think about doing fancy stuff with granting permissions and # so on. foreach ( $schema->get_procedures ) { my $name = $_->name(); $output .= " "; $output .= "-- -- Procedure: $name -- " unless $no_comments; my $text = $_->sql(); $text =~ s/ //g; $output .= "$text GO "; } SEE ALSO
SQL::Translator AUTHORS
See the included AUTHORS file: http://search.cpan.org/dist/SQL-Translator/AUTHORS <http://search.cpan.org/dist/SQL-Translator/AUTHORS> COPYRIGHT
Copyright (c) 2012 the SQL::Translator "AUTHORS" as listed above. LICENSE
This code is free software and may be distributed under the same terms as Perl itself. perl v5.14.2 2012-05-10 SQL::Translator::Producer::SQLServer(3pm)