Call procedure multiple time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Call procedure multiple time
# 1  
Old 04-08-2013
Call procedure multiple time

Hi,

I have following script which calls sql to create staging table.How do I call load_data_to_oracle() multiple times so that it creates 4 staging as follows.

Code:
1.t1_rpt_1day_stg
2.t1_rpt_7day_stg
3.t1_rpt_30day_stg
4.t1_rpt_CTD_stg

--shell script
Code:
load_data_to_oracle()
{
# truncate or create stage table first
${ORACLE_HOME}/bin/sqlplus ${ORACLE_USER}/${ORACLE_PASSWD}@${ORACLE_SID} << EOF > ${TMP_LOG_FILE} 2>&1
set serveroutput on
@${CREATE_STAGE_SQL}
COMMIT;
QUIT;
EOF

## Function Main

# variables
CREATE_STAGE_SQL=${SQL_DIR}/stage_create.sql

##function call
if [[ $type = 'a' || $type = 'A' ]]
then
    load_data_to_oracle
    exit 0
fi

---sql to create staging table
Code:
stage_create.sql
set serveroutput on size 1000000
declare
v_err_code   varchar2(500);
v_err_mesg   varchar2(1000);
v_table_name varchar2(100);
v_sql_string varchar2(4000);
v_table_exists number;
begin
# some code
     execute immediate 'create table t1_rpt_<parameterized>_stg as select * from t1_rpt_tmt';
#some error checking     
end;


Thanks
Sandy
# 2  
Old 04-08-2013
Use a for loop to call the function:
Code:
for param in 1day 7day 30day CTD
do
   load_data_to_oracle
done

Inside the function pass the $param as argument:
Code:
@${CREATE_STAGE_SQL} "$param"

Use first argument &1 for creating table:
Code:
execute immediate 'create table t1_rpt_&1._stg as select * from t1_rpt_tmt';

Note: Don't forget the period . after &1 which defines the boundary.
This User Gave Thanks to Yoda For This Post:
# 3  
Old 04-11-2013
I am getting following error when trying to create staging table.
Code:
SQL*Loader-941: Error during describe of table T1_1DAY_STG
ORA-04043: object T1_1DAY_STG does not exist

This is PL/SQL block(stage_create_sp.sql) being called inside shell script
Code:
begin

  select count(1) into v_table_exists
   from user_tables
  where table_name = 'TXPCY_&1._STG';
  
  dbms_output.put_line ('table name ' || 'TXPCY_&1._STG');

  if v_table_exists != 0 then
      execute immediate 'create table txpcy_&1._stg as select * from txpcy_tmt';
     dbms_output.put_line('stage table not exists and created...' );
  end if;

  execute immediate 'GRANT DELETE, INSERT, SELECT, UPDATE ON MT_RPT01.txpcy_&1._stg TO MT_RPT01_MO';

   commit;
exception
when others then
  v_err_code := sqlcode;
  v_err_mesg := substr(sqlerrm,1,1000);
  dbms_output.put_line('Others Error code <' || sqlcode || '> Error Message: '|| v_err_mesg);
  -
end;
/

Shell Script Call
Code:
load_data_to_oracle()
{
for i in 1DAY 7DAY 15DAY
do
${ORACLE_HOME}/bin/sqlplus ${ORACLE_USER}/${ORACLE_PASSWD}@${ORACLE_SID} << EOF > ${TMP_LOG_FILE} 2>&1
set serveroutput on
@${CREATE_STAGE_SQL} "$i"
COMMIT;
QUIT;
EOF
}
########Main#######
CREATE_STAGE_SQL=stage_create_sp.sql
load_data_to_oracle


Last edited by sandy162; 04-11-2013 at 05:31 PM..
# 4  
Old 04-11-2013
The ORA error: ORA-04043 suggest that the table was not created successfully. So I guess the PL/SQL procedure didn't run successfully.

In PL/SQL, use semi-colon to define the end of line of code and in the end use forward slash / to execute it:
Code:
begin
execute immediate 'create table t1_&1._stg as select * from t1_rpt_tmt';
end;
/

This User Gave Thanks to Yoda For This Post:
# 5  
Old 04-11-2013
Thanks I have made changes but still got the same error.
I have updated the second post as well.

Last edited by sandy162; 04-11-2013 at 05:32 PM..
# 6  
Old 04-11-2013
I didn't pay attention to this error before!
Code:
SQL*Loader-941: Error during describe of table T1_1DAY_STG

Please check and verify if you are running SQL Loader using a DB User who has sufficient privileges on object: T1_1DAY_STG

Or else check and verify if this object: T1_1DAY_STG exist in the DB User's schema.
This User Gave Thanks to Yoda For This Post:
# 7  
Old 04-12-2013
Thanks..
But table does not exist and I am trying to create table, if I hard code the pl/sql block "t1_1day_stg" ( instead of passing parameter &1.) it works


Code:
begin
execute immediate 'create table t1_1day_stg as select * from t1_rpt_tmt';
end;
/

Do you think I should try passing parameter without double quotes like this : -- @${CREATE_STAGE_SQL} $i

Code:
load_data_to_oracle()
{
for i in 1DAY 7DAY 15DAY
do
${ORACLE_HOME}/bin/sqlplus ${ORACLE_USER}/${ORACLE_PASSWD}@${ORACLE_SID} << EOF > ${TMP_LOG_FILE} 2>&1
set serveroutput on
@${CREATE_STAGE_SQL} $i
COMMIT;
QUIT;
EOF
}
########Main#######
CREATE_STAGE_SQL=stage_create_sp.sql
load_data_to_oracle


Thanks
Sandy
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to call a stored procedure inside a loop?

How to call a stored procedure inside a loop export PATH=$ORACLE_HOME/bin:$PATH ORACLE_SID=xxxx; export ORACLE_SID ORAENV_ASK=NO TODAY_DATE=$(date +"%Y%m%d") LOGFILE=/var/opt/gogd/cust/scripts/${TODAY_DATE}_sap_cust_rel.log echo 'Connected' PARCUST=sap_cust_rel.par sqlldr... (1 Reply)
Discussion started by: ashwanth
1 Replies

2. Shell Programming and Scripting

How to use special character in procedure call?

Hi, I have following script which calls sql to create staging table like t1_rpt_1day_stg,t1_rpt_7day_stg The following line has '*' and causing all data in directory to show up in email notification but if I give all column names then it works, Please let me know how to use '*' instead of... (4 Replies)
Discussion started by: sandy162
4 Replies

3. Shell Programming and Scripting

How to call a stored procedure from shell program?

How to call a stored procedure from shell program (1 Reply)
Discussion started by: noorm
1 Replies

4. Shell Programming and Scripting

Shell Script for call a procedure in Oracle DB

Hi everyone! I'm new with Shell Scripting, and I have to do a shell script to call a procedure, which have 2 input parameters, the directory(from server) and the txt file (which have informations to update/insert in DB). I have to create a shell script to execute that procedure for each txt... (5 Replies)
Discussion started by: renatoal
5 Replies

5. Programming

help remote procedure call

am beginig with unix c code for sun remote procedure call You are to write a program using RPC facility to do the following: 1- The clients reads in a variable length array from the command line 2- The client offers a menu for the user to choose what to do with the array: a. Sort the array... (1 Reply)
Discussion started by: auto2000
1 Replies

6. UNIX for Dummies Questions & Answers

help remote procedure call

i am beginig with unix c code for sun remote procedure call to do the following: 1- The clients reads in a variable length array from the command line 2- The client offers a menu for the user to choose what to do with the array: a. Sort the array b. Add the array c. Find max d. Find... (1 Reply)
Discussion started by: auto2000
1 Replies

7. Programming

help remote procedure call

i am beginig with unix c code for sun remote procedure call to do the following: 1- The clients reads in a variable length array from the command line 2- The client offers a menu for the user to choose what to do with the array: a. Sort the array b. Add the array c. Find max d. Find... (1 Reply)
Discussion started by: auto2000
1 Replies

8. UNIX for Advanced & Expert Users

help remote procedure call

i am beginig with unix c code for sun remote procedure call to do the following: 1- The clients reads in a variable length array from the command line 2- The client offers a menu for the user to choose what to do with the array: a. Sort the array b. Add the array c. Find max d. Find... (1 Reply)
Discussion started by: auto2000
1 Replies

9. Shell Programming and Scripting

need to call 3 stored procedure at the same time

Hi GUYS, I need to trigger 3 stored procedure at the same time.. I know how to trigger the stored procedure. If anybody can tell me how to trigger 3 different process at the same time parallelly.. that would be helpful.. Thanks for your help in advance, Magesh (1 Reply)
Discussion started by: mac4rfree
1 Replies

10. UNIX for Advanced & Expert Users

How to call SQL procedure from UNIX Shellscript ?

Hi All I would be thankful to you all if you will guide me the steps to call a stored proc. from unix shell script. that stored proc. could be parameterised or parameterless developed in SQL. Any info. in this topic would help me..... Thanks in advance.... (1 Reply)
Discussion started by: varungupta
1 Replies
Login or Register to Ask a Question