Calling Pl/sql function in shell script to modify csv


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calling Pl/sql function in shell script to modify csv
# 1  
Old 09-24-2012
Calling Pl/sql function in shell script to modify csv

I need to
1.Open a csv
2.Process the csv i.e. Modify 2 column in the csv.
To modify the column the value needs to be passed to a pl/sql function and the return value should be updated
For eg:
If column 2 E,then E will be passed in database function
which will return Employee.
3. Write a temprray file with the changed value b.csv

I am trying to use the awk command but its not working
Code:
RET_VALUE=`sqlplus -s ${FCP_LOGIN} <<EOF 
SET TERM ON 
SET ECHO ON 
SET SERVEROUT ON SIZE 10000 
SET LINESIZE 250
Begin 
foo(A);
end; 
exit; 
EOF`
awk -F "," '$2=$RET_VALUE'  a.csv > b.csv
exit


Last edited by Franklin52; 09-24-2012 at 09:43 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 09-24-2012
Try the awk command with variables:
Code:
awk -F "," -v value="$RET_VALUE" '$2=value'  a.csv > b.csv

# 3  
Old 09-25-2012
Error

Hi

But in my function foo,
I need to pass the value of 2nd column of csv
and after modification it need to be saved in the same field that us 2nd column.
Also foo is a function not a procedure

---------- Post updated 09-25-12 at 12:52 AM ---------- Previous update was 09-24-12 at 09:10 PM ----------

In th below code,
I ab able to call a procedure test_x which inturn calls the function and returns the desried value.
The portion which is left is,I need to pass the second column of my csv file
and return the value in OUTPUT cased on that which I can save in my csv

Code:
OUTPUT=`sqlplus -s apps/apps@APPS <<EOF
set pages 0 lines 120 trimout on trimspool on tab off echo off verify off feed off serverout on
var mavar varchar2(100);
exec test_x(:mavar);
print mavar;
exit;
EOF`
 
echo "OUT = ${OUTPUT}"
awk -F "," -v value="${OUTPUT}" '$2=value'  a.csv > c.csv
exit

# 4  
Old 09-25-2012
Hello,

This is what I did.

Code:
create or replace procedure test_proc (  i in varchar , j out varchar )
is
begin
j:='Outcome';
end;
/

and the shell script is

Code:
#!/bin/sh
inp='Sample';
OUTPUT=`sqlplus -s saidata/saidata <<EOF
set pages 0 lines 120 trimout on trimspool on tab off echo off verify off feed off serverout on
var mavar varchar2(100);
exec test_proc ( '${inp}'  , :mavar);
print mavar;
exit;
EOF`

[sai@sai26 ~]$ ./junk.sh
OUT = Outcome

Check the one in Bold. The above is just a template and do the changes in your code accordingly.

Regards
Ravi
# 5  
Old 09-25-2012
It's unclear to me what the problem is, can you elaborate your question?
# 6  
Old 09-25-2012
I wanted to write a code

1. which reads a.csv having 7 column seperated by delimeter

2. Modify the column 2,3,5 in the csv
To modify I need to call a pl/sql function which takes in the value of the column
and modifies it as per business logic and returns the value.
The value returned needs to be saved in the column 2

3. This needs to be updated in the new csv b.csv


If

a.csv

A,Chinky,chinky@yahoo.com,E,F
B,Frank,frank@yahoo.com,M,M

New vaue in b.csv

A,User,chinky@yahoo.com,Employee,Female
B,Moderator,frank@yahoo.com,Manager,Male

the logic of transforming Chinky -> User is in PL/sql procedure

I tried using cat function and loop but still no result
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help to Modify File Name in each function before calling another function.

I have a script which does gunzip, zip and untar. Input to the script is file name and file directory (where file is located) I am reading the input parameters as follows: FILENAME=$1 FILEDIR=$2 I have created 3 functions that are as follows: 1) gunzip file 2) unzip file... (2 Replies)
Discussion started by: pinnacle
2 Replies

2. Shell Programming and Scripting

calling a sql file in my shell script

Hi, I want to call a sql file in my shell script. see the below code:- if ] then ( isql -U${S_USER} -S${S_SERV} -w100 -b -h0 <<ENDSQL | sed -e "s/Password://" ${S_PWD} set nocount on go use ${S_DB} go // need to call a file name... (16 Replies)
Discussion started by: dazdseg
16 Replies

3. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

4. UNIX for Advanced & Expert Users

Calling sql file from shell script

Hi I have a shell script that call a sql file. The sql file will create a spool file. My requirement is, when ever i get an OS error like file not found. I have to log it in a log file. Could some who worked in a like scenario help me by giving the code sample. Many Thanks.. (1 Reply)
Discussion started by: chintapalli001
1 Replies

5. Shell Programming and Scripting

Calling sql in shell script with parameters

Dear All, I want to call an sql script within a unix shell script. I want to pass a parameter into the shell script which should be used as a parameter in teh sql script. e.g $ ./shell1.sh 5000129 here 5000129 is a prameter inside shell script i am calling one sql script e.g. ... (2 Replies)
Discussion started by: Radhe
2 Replies

6. UNIX for Dummies Questions & Answers

calling one function from another shell script

i have a function defined in one ksh (ksh 1) i want to use that function in another ksh (ksh 2) i am using . $<directoryname>/<ksh name> i am calling the function defined in ksh 1 in ksh 2 i want the returnstatus from the above operation but it is not executing the function what i... (1 Reply)
Discussion started by: trichyselva
1 Replies

7. Shell Programming and Scripting

Calling SQL LDR and SQL plus scripts in a shell script

Hi- I am trying to achieve the following in a script so I can schedule it on a cron job. I am fairly new to the unix environment... I have written a shell script that reads a flat file and loads the data into an Oracle table (Table1) via SQLLDR. This Works fine. Then, I run a nested insert... (5 Replies)
Discussion started by: rajagavini
5 Replies

8. Shell Programming and Scripting

calling sql file from shell script

Hello everybody I need help calling sql file from shell script. Can anyone help me creating a small shell script which calls an sql file . The .sql file should contain some select statements like select emp_no from emp_table; select emp_id from emp_table; And the results should be... (6 Replies)
Discussion started by: dummy_needhelp
6 Replies

9. UNIX for Advanced & Expert Users

Calling PL/SQL Script in Shell Programming

Hi all, In a shell script I need to pass two parameters to a pl/sql script and get the ouput of the pl/sql script and use it in shell script. For example Shell script : test.sh PL/SQL script : get_id.sql parameter1 parameter2 Actually get_id.sql has a select statement something... (1 Reply)
Discussion started by: lijju.mathew
1 Replies

10. Shell Programming and Scripting

Calling SQL scripts through Shell Script

Oracle and Scripting gurus, I need some help with this script... I am trying to add the query SELECT * FROM ALL_SYNONYMS WHERE SYNONYM_NAME = 'METADATA' in the current script.... Read the result set and look for the TABLE_NAME field. If the field is pointing to one table eg.... (18 Replies)
Discussion started by: madhunk
18 Replies
Login or Register to Ask a Question