Unix oracle script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix oracle script
# 8  
Old 05-28-2012
give a try like eh below:


Code:
$ cat s.txt
SQL> select sum(salary) from emp;

SUM(SALARY)
-----------
      30807

SQL> spool off


Code:
Jay@Jay-PC ~
$ grep  " *[0-9]" s.txt
      30807

---------- Post updated at 12:45 PM ---------- Previous update was at 12:32 PM ----------

To be precise, your text.txt contains all the lines between two spool commands.
Since you require only the digits from result set, below two lines will be suffice.

Code:
c=`grep "[0-9]" s.txt`
echo "the value is $c"


Last edited by Scrutinizer; 05-28-2012 at 02:46 PM.. Reason: code tags (x2)
# 9  
Old 05-29-2012
Thanks for your reply!!!
:-)
# 10  
Old 05-29-2012
Read a value right into a shell variable. This example can process a line of results at a time.
Code:
$ cat x
#!/bin/ksh

( $ORACLE_HOME/bin/sqlplus -s login/password@database <<EOF
  set heading off;
  set pagesize 0;
  select 'count='||count(*)
  from dual;
  exit;
EOF
)|
while read line     # Read a line at a time.  Could get blank lines.
do
 if [[ -n $line ]]  # If the line read is not blank...
   then eval $line  # eval causes $line to be evaluated twice, thus
                    # setting shell variables with the data returned.

        ## Print out what was read in.  Quotes are needed around the
        ## variables so printf sees nulls.
        printf "%d\n" "$count"
 fi
done

exit 0
$ x
1
$

I would be remiss if I did not point out that if what is being eval'd could be manipulated into containing a valid shell command, it would be executed by eval. So be careful with eval.

Last edited by gary_w; 05-29-2012 at 04:58 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing Oracle script from UNIX Script

Hi, I am new to UNIX and want to execute oracle script from unix script. I have written below script but i am getting below error. #!/bin/bash file="/home/usr/control/control_file1" while read line do #$line=@$line #echo $line sqlplus tiger/scott@DB @$line exit #echo "$line" done... (3 Replies)
Discussion started by: vipin kumar rai
3 Replies

2. Shell Programming and Scripting

How to pass Oracle sql script as argument to UNIX shell script?

Hi all, $ echo $SHELL /bin/bash Requirement - How to pass oracle sql script as argument to unix shell script? $ ./output.sh users.sql Below are the shell scripts and the oracle sql file in the same folder. Shell Script $ cat output.sh #!/bin/bash .... (7 Replies)
Discussion started by: a1_win
7 Replies

3. UNIX for Advanced & Expert Users

Use of Oracle pl/sql in UNIX shell script

Hi, I have basic knowledge on how to write pl/sql code inside shell script. I am looking for more advance thing. Is there any book for that which can just talk about how to write more advance plsql code inside shell script. Please help Thanks!!!!!! (1 Reply)
Discussion started by: diehard
1 Replies

4. Shell Programming and Scripting

PROBLEM WITH ORACLE QUERY IN UNIX SCRIPT

hi Guys, i have a problem with oracle query in my unix script.. I'm getting the following error while executing.. ./logtab.sh: sqlplus -s "pmutv/pmutv1" << EOFSQL^Jset head off^Jinsert into... (2 Replies)
Discussion started by: apple2685
2 Replies

5. Shell Programming and Scripting

Need to access Oracle DB with shell/perl script in Unix

Hi, We need to access Oracle DB with shell/perl script in Unix. Is Oracle client needed in Unix for this. I have seen threads which tell abt using SQL plus to access Oracle tables. Can we access DB without SQL PLus installation using scripts in UNix like we access DB using jar files in Java .... (1 Reply)
Discussion started by: justinacc
1 Replies

6. Shell Programming and Scripting

How to fetch data from oracle in unix shell script

Hi, How to fetch data from oracle database in unix shell scripting. list=`sqlplus -s ds_user/dsuser@EMI <<EOF set feedback off set serveroutput on set heading off set pagesize 0 set tab off select IP_ID from table / exit EOF` The output is not what i expected.I need output in... (4 Replies)
Discussion started by: Anusha_Reddy
4 Replies

7. Shell Programming and Scripting

Delete oracle table from UNIX script

Hi, Is it possible to delete oracle table datas using a UNIX script/Shell script? how can we do this?? I have oracle Database and i have to delete millions of record everyday.. adn it is taking hours togather to execute this. Will the delete query triggered from UNIX be faster can we expect any... (1 Reply)
Discussion started by: Codesearcher
1 Replies

8. HP-UX

return code from oracle to unix script

Hi I'm writing a shell script that connects to oracle database and fires query to check the availability of data in a table. In case of no data found then what will be the return code and how to handle in that in variable. Kindly provide with an example for better understanding... Thanks... (1 Reply)
Discussion started by: ksailesh
1 Replies

9. UNIX for Dummies Questions & Answers

Unix shell script Certification for oracle developer.

hi friends, I would like to do the certification in Korn shell scripts { i am using HP UNIX machine }. is there any certification for UNIX shell script . If yes please tell me the details . i am junior level oracle plsql developer . i interseted in unix shell scripting . i need... (1 Reply)
Discussion started by: rdhaprakasam
1 Replies

10. 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
Login or Register to Ask a Question