calling a plsql procedure through shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting calling a plsql procedure through shell script
# 1  
Old 12-08-2011
Tools calling a plsql procedure through shell script

I have a plsql procedure inside a package which is having one IN parameter .I want to call that procedure through a shell script and that IN parameter is a column of a table in the database. So my requirement is that i need to loop all the entries of that IN parameter from the table through shell script. suppose i have 100 rows in that table so i need to take 100 rows(which is IN parameter of a procedure) from the table and then process 5 at a time .so i pick 1st five rest are on wait. once those 5 are done then next five.......its a urgent requirement......any help is appreciated .......thanks in advance
# 2  
Old 12-08-2011
Quote:
Originally Posted by rspnf
I have a plsql procedure inside a package which is having one IN parameter .I want to call that procedure through a shell script and that IN parameter is a column of a table in the database. So my requirement is that i need to loop all the entries of that IN parameter from the table through shell script. suppose i have 100 rows in that table so i need to take 100 rows(which is IN parameter of a procedure) from the table and then process 5 at a time .so i pick 1st five rest are on wait. once those 5 are done then next five...
Please post the "create table" statement to create the table, "insert into" statements to populate the table, and your PL/SQL procedure that you have as of now.

tyler_durden
# 3  
Old 12-09-2011
My procedure which needs to call through shell script

CREATE OR REPLACE package body IRS_TIN.f1099k_data as

procedure create_1099k_data

(errcode out varchar2
errmsg out varchar2,
retcur out refcursor,
p_ptfolio_id in varchar2,
p_startdt in varchar2,
p_enddt in varchar2)

is proc_name varchar2(50) default 'create_1099k_data'||to_char(sysdate, 'YYYYMMDDHH24MISS');
begin

errcode :=0;
errmsg :=null;
for ptcr in ( Select ptfolio_id,ptfolio_name,
source_system,network_id
from portfolio_merchants
where ptfolio_id = p_ptfolio_id
and network_id = '06293870001' )
loop
merge into tr_1099k_data b

using ( Select pmx.source_system,
pmx.network_id,
pe.payee_id,
pct.pse_id, pct.epf_id,
'2011' yyyy,
sum( case when substr (reporting_month, 5,2) = '01' then grs else 0 end ) jan_grs,
sum( case when substr (reporting_month, 5,2) = '02' then grs else 0 end ) feb_grs,
sum( case when substr (reporting_month, 5,2) = '03' then grs else 0 end ) mar_grs,
sum( case when substr (reporting_month, 5,2) = '04' then grs else 0 end ) apr_grs,
sum( case when substr (reporting_month, 5,2) = '05' then grs else 0 end ) may_grs,
sum( case when substr (reporting_month, 5,2) = '06' then grs else 0 end ) jun_grs,
sum( case when substr (reporting_month, 5,2) = '07' then grs else 0 end ) jul_grs,
sum( case when substr (reporting_month, 5,2) = '08' then grs else 0 end ) aug_grs,
sum( case when substr (reporting_month, 5,2) = '09' then grs else 0 end ) sep_grs,
sum( case when substr (reporting_month, 5,2) = '10' then grs else 0 end ) oct_grs,
sum( case when substr (reporting_month, 5,2) = '11' then grs else 0 end ) nov_grs,
sum( case when substr (reporting_month, 5,2) = '12' then grs else 0 end ) dec_grs,
sum( txn_cnt) txn_cnt

from payee pe,
payee_merchant_xref pmx,
portfolio_merchants pm,
ptfolio_card_type_payer_xref pct,
mthly_grs mg

where pe.payee_id = pmx.payee_id
and pmx.source_system = pm.source_system
and pmx.network_id = pm.network_id
and pm.ptfolio_id = pct.ptfolio_id
and pmx.source_system = mg.source_system
and pmx.network_id = mg.network_id
and pct.product_code = mg.product_code

-- Parameters

and pmx.network_id = ptcr.network_id
and pct.ptfolio_id = ptcr.ptfolio_id

group by pe.payee_id,
pmx.source_system,
pmx.network_id,
pct.pse_id,
pct.epf_id ) t

on ( b.payee_id = t.payee_id and
b.source_system = t.source_system and
b.network_id = t.network_id and
b.pse_id = t.pse_id and
b.epf_id = t.epf_id and
b.yyyy = t.yyyy )

when matched then

update set b.jan_grs = b.jan_grs + t.jan_grs,
b.feb_grs = b.feb_grs + t.feb_grs,
b.mar_grs = b.mar_grs + t.mar_grs,
b.apr_grs = b.apr_grs + t.apr_grs,
b.may_grs = b.may_grs + t.may_grs,
b.jun_grs = b.jun_grs + t.jun_grs,
b.jul_grs = b.jul_grs + t.jul_grs,
b.aug_grs = b.aug_grs + t.aug_grs,
b.sep_grs = b.sep_grs + t.sep_grs,
b.oct_grs = b.oct_grs + t.oct_grs,
b.nov_grs = b.nov_grs + t.nov_grs,
b.dec_grs = b.dec_grs + t.dec_grs,
b.txn_cnt = b.txn_cnt + t.txn_cnt,
modified_by= 'f1099k_data.pkb',
modified_date= sysdate

when not matched then

insert ( id,
payee_id,
source_system,
network_id,
pse_id,
epf_id,
jan_grs,
feb_grs,
mar_grs,
apr_grs,
may_grs,
jun_grs,
jul_grs,
aug_grs,
sep_grs,
oct_grs,
nov_grs,
dec_grs,
txn_cnt,
yyyy,
form_status,
status,
status_comments,
created_date,
created_by)

values (tr1099kd_seq.nextval,
t.payee_id,
t.source_system,
t.network_id,
t.pse_id, t.epf_id,
t.jan_grs,
t.feb_grs,
t.mar_grs,
t.apr_grs,
t.may_grs,
t.jun_grs,
t.jul_grs,
t.aug_grs,
t.sep_grs,
t.oct_grs,
t.nov_grs,
t.dec_grs,
t.txn_cnt,
t.yyyy,
'OR',
'PENDING', 'INITIAL',
sysdate, 'f1099k_data.pkb');
end loop;
end;


procedure create_1099k_data

(errcode out varchar2,

errmsg out varchar2,

retcur out refcursor,

ptfolio_id in varchar)

is

startdtchar(10) default to_char(last_day(add_months(sysdate,-2))+1,'YYYYMMDD');
enddt char(10) default to_char(last_day(add_months(sysdate,-1)),'YYYYMMDD');
begin
create_1099k_data (errcode, errmsg, retcur, ptfolio_id, startdt, enddt);
dbms_output.put_line('ERRCODE-'||errcode||':'||'ERRORMSG-'||errmsg);
end;

end f1099k_data;

---------- Post updated at 09:52 PM ---------- Previous update was at 09:49 PM ----------

Table name is portfolio

and column name is portfolio_id

which is also the IN parameter of the procedure
# 4  
Old 12-10-2011
I don't quite understand the code fully.

(1) Could you please put your code within code tags? It's difficult to read as it is.

(2) You have two overloaded procedures called "create_1099k_data". One calls the other, you set p_startdt and p_enddt in the wrapper, and pass it to the other. But you don't use it in the second procedure! What's the point of passing it then?

(3) What's the purpose of the "proc_name" local variable in the invoked procedure? It's declared and assigned, but never used.

(4) There's a MERGE statement inside a CURSOR..FOR loop in the invoked procedure. You fetch data from "portfolio_merchants" in the cursor query, but then you also use the same table/view in the SELECT part of the MERGE statement. If that's the case, then you could probably do away with the CURSOR..FOR loop by adding the filter conditions of the cursor query into the SELECT part of the MERGE.

(5) Finally, your first post mentions something about "piecewise" processing, but I don't see how or where it is applicable in the posted code.

tyler_durden
# 5  
Old 12-10-2011
Hi Durden_Tyler

I understand, but i didn't wrote this procedures ,my senior wrote this and he told me to write a script for this.

Yes you are right ,He declared proc_name but never used this in the whole procedure.

and that piecewise is the p_ptfolio_id which is the IN parameter and we are picking this IN parameter from a column of a table named P_ptfolio_id.

He said to me that In script first of all pick the whole rows of that p_ptfolio_id column and then process in the steps of 5 means pick 5 and put those in the background and when those are done pick next 5 and so on.

I appreciate your kind help.

Rspnf

---------- Post updated at 03:13 PM ---------- Previous update was at 03:11 PM ----------

We are calling the 2nd procedure in the package which itself calls the first procedure

and we are just providing one IN parameter that is p_ptfolio_id and other two he makes default p_startdt and p_enddt.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sub script calling procedure

Hi, I have a doubt regarding how sub scripts will be executed and interested to know internal workflow, For example - My main script is A,it calls a script B then B will call some C....and so on. Then B script run parallel to A or it will wait B to execute then A will continue. ... (1 Reply)
Discussion started by: nag_sathi
1 Replies

2. Shell Programming and Scripting

Script to give plsql procedure output

##Execute the EDW_MEM_KEY_UPDATE procedure ext_sta=`sqlplus -s ${Connstr} <<eof set heading off; set pagesize 0; set feedback off; set serveroutput on; execute EDW_MEM_KEY_UPDATE ; quit; here` vara="ORA-" var=`echo $ext_sta | grep -c $vara ` Hi All, above is a part of my unix... (7 Replies)
Discussion started by: iamnoone
7 Replies

3. Shell Programming and Scripting

calling pl/sql procedure from shell and return values

How could I call an Oracle PL/SQL procedure from any shell (bash) and catch returning value from that procedure (out param) or get a returning value if it's a function. also, I got into trouble when I tried to send a number as a param #!/bin/bash -e username=$1 pwd=$2 baza=$3... (0 Replies)
Discussion started by: bongo
0 Replies

4. UNIX for Advanced & Expert Users

Calling unix script from sql or plsql

Hi Can anyone please let me know how to call unix scripts from sql or plsql ASAP. (2 Replies)
Discussion started by: ksailesh
2 Replies

5. Shell Programming and Scripting

Calling procedure through Unix Shell

how to 1) invoke batch profile to run sqlplus on XXXXX server. 2) execute truncate table xtra.xtra_card_email_request using procedure dbadmin.truncate_table . 3) Check the count before and after the job run. (1 Reply)
Discussion started by: jakred
1 Replies

6. Programming

Calling procedure through Unix Shell

Hi can anyone help me in how to 1) invoke batch profile to run sqlplus on XXXXX server. 2) execute truncate table xtra.xtra_card_email_request using procedure dbadmin.truncate_table . 3) Check the count before and after the job run. (1 Reply)
Discussion started by: jakred
1 Replies

7. UNIX for Advanced & Expert Users

calling plsql function in a unix script

Could anyone please help me. I have a function in plsql that returns a number. But i am listing some records through that function using DBMS_OUTPUT.PUT_LINE. I want to catch those records by executing this function through a unix script. The following shows what i did echo "Connected from... (2 Replies)
Discussion started by: cobroraj
2 Replies

8. Shell Programming and Scripting

Calling an Oracle Stored Procedure from Unix shell script

hai, can anybody say how to call or to execute an oracle stored procedure in oracle from unix... thanks in advance.... for ur reply.... by, leo (2 Replies)
Discussion started by: Leojhose
2 Replies

9. Shell Programming and Scripting

Calling stored procedure from shell script

HI, I have a similar problem to thread 18264, only I couldn't get it to work. https://www.unix.com/showthread.php?t=18264 I have a stored procedure which is called by a shell script program. When I run the stored procedure alone or through the shell script, it works fine with output text... (3 Replies)
Discussion started by: dorisw
3 Replies

10. Shell Programming and Scripting

calling stored procedure from shell script.

Hi All, This is a very starnge problem I am having. I have a shell script that calls a stored procedure. Here's my code in shell script: sqlplus "userid/pwd" @file.sql and file.sql has the following statement: exec my_storedProc; Now, when I execute my shell script, nothing... (2 Replies)
Discussion started by: priyamurthy2005
2 Replies
Login or Register to Ask a Question