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.
I am getting following error when trying to create staging table.
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
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
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..
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
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
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
Double quotes is just fine. It should not be a problem.
I suggest you to put the PL/SQL procedure inside the SQL block in your function rather than calling using an .sql file just to understand what is happening:
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
-- put the procedure here