Values from Oracle to Unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Values from Oracle to Unix
# 1  
Old 03-25-2008
Values from Oracle to Unix

Hello Experts
how do I get a output value from Oracle to Unix . Please give me sample Unix codings

Scenario (Filne name : test.sh <argument > )
---------

1. Passing argument from unix to sql
2. connecting to Oracle & from oracle get output
3. Pass the output to unix

Thanks
Krishna
# 2  
Old 03-26-2008
You could spool the output from Oracle to a file, then interogate the file.

In Unix script ....
sqlplus $USER @$BATCH/somesql.sql $GMT_OFFSET >> $BATCHLOG

In somesql.sql ..... (in part) ...
Code:
SET SERVEROUTPUT ON SIZE 1000000 FORMAT WRAPPED
SET LINESIZE 250
SET PAGESIZE 50000
SET NEWPAGE  0
SET HEADING  OFF
SET RECSEP   OFF
SET FEEDBACK OFF
SET TERMOUT  OFF
SET VERIFY   OFF
SET DEFINE ~

SPOOL $SQLREPORT/somesql_report.txt;

--PL/SQL block
DECLARE
........
        AND F.FINALISED_DATE + (~1 / 24) > RUN_DATE1
        AND F.FINALISED_DATE + (~1 / 24) <= RUN_DATE2)
        AND F.ADD_TIMESTAMP + (~1 / 24) > RUN_DATE1
        AND F.ADD_TIMESTAMP + (~1 / 24) <= RUN_DATE2)
......

From my simple understanding of sql, the ~1 substitutes for the value of $GMT_OFFSET.

Hope the above is of some help to you.

Last edited by Cameron; 03-26-2008 at 03:07 AM.. Reason: Addition: ~1 explaination.
# 3  
Old 03-29-2008
check this out.

returnedvalue=`sqlplus -s id/pwd <<EOF
set serveroutput on;
Declare

message VARCHAR2(200);

Begin

select tname into message from all_tables;

dbms_output.put_line ('tablenames '||nvl(message,''));
End;
/
set serveroutput off;
EXIT;
EOF`

X=`echo $returnedvalue | grep tablenames | awk '{print $2}'`

echo "The Query output is: "

echo "Query message 1= $X "

If you have more outputs from query, print those results in $2, $3,......
# 4  
Old 03-30-2008
Please have a try......

let i/p be
rmpid=$1

echo " started passing argrument to SQL Block"

return_value=`sqlplus -s id/pwd <<EOF
select * from emp where empid=$empid;
EXIT;
EOF`

echo " fetched value from SQL is $return_value"
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract Oracle home from Oratab and compare values

Friends, I'm trying to do below in ksh script, while requesting user to provide src_db and dest_db values 1. Extract src_db and dest_db Oracle home from oratab file 2. Don't find db if it starts with comment (#) 3. Compare both values 4. Message success or exit with error if they don't... (0 Replies)
Discussion started by: homer4all
0 Replies

2. Shell Programming and Scripting

Processing values from Oracle procedure

Hi all, My oracle procedure returns more than one value. i need to get one value at a time upto ending value ina shell script. Please help me..... (9 Replies)
Discussion started by: pmreddy
9 Replies

3. Shell Programming and Scripting

Retrieving values from the oracle table

Hi, How to retrieve two different date values(min & max) from the oracle table and assign to two different variables in the shell script to process further. With Regards (8 Replies)
Discussion started by: milink
8 Replies

4. Shell Programming and Scripting

How to display fields and values in sql+ for Oracle DB

Hello, I'm trying to do a select for an Oracle table but the output gives me only filelds values without fields name as in Informix. Is there anyway to display both in output ? For instance, the output will be : Name Rico Age 30 Position Engineer Thx, (5 Replies)
Discussion started by: rany1
5 Replies

5. Shell Programming and Scripting

Select multiple values from an Oracle database and assign it to two dimensional array

hi I have two tables in oracle DB and am using a joining query which will result in the output as follows. i need to assign it to a two dimensional array and use it for my further calculations. the way i tried is as follows. #!/bin/ksh export... (1 Reply)
Discussion started by: aemunathan
1 Replies

6. Shell Programming and Scripting

how to capture oracle function returning 2 values in unix

i have an oracle function which returns two values, one is the error message if the function encounters anything and another one which returns a number i need to capture both and pass it on to unix shell script how to do it (2 Replies)
Discussion started by: trichyselva
2 Replies

7. Shell Programming and Scripting

how to pass the values to unix shell from the oracle stored procedure.

Hi i am calling a stored procedure from unix shell like this call test_proc('0002','20100218'); the stored procedure was giving output like this dbms_output.put_line(' processed earlier'); i want to see the output in the unix shell where i called. Thanks barani (6 Replies)
Discussion started by: barani75
6 Replies

8. UNIX for Dummies Questions & Answers

how to pass values from oracle sql plus to unix shell script

how to pass values from oracle sql plus to unix shell script (2 Replies)
Discussion started by: trichyselva
2 Replies

9. UNIX for Dummies Questions & Answers

How to load comma seperated values file (*.csv) into Oracle table

Hi all I need to input values in a .csv file into my Oracle table running in Unix, I wonder what would be the command to do so... The values are recorded in an excel file and I tried using a formatted text file to do so but failed because one of the field is simply too large to fit in the... (5 Replies)
Discussion started by: handynas
5 Replies
Login or Register to Ask a Question