If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > How to execute a ananomyous pl/sql block using shell script that connects to oracle

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-20-11, 15:49
MIKELALA MIKELALA is offline
Registered User
 
Join Date: Nov 2009
Posts: 45
How to execute a ananomyous pl/sql block using shell script that connects to oracle

THis is the procdure that needs to be execute on DB using .sh file


DECLARE
TYPE tbl_col_type is TABLE of VARCHAR2(50);
L_table_col tbl_col_type := tbl_col_type('X_ACC_REV_MNTH_AGG');


l_sql_stmt VARCHAR2(32000);
BEGIN
FOR rec IN L_table_col.FIRST..L_table_col.LAST


LOOP


l_sql_stmt := 'UPDATE '||'KAW_OWNER.'||L_table_col(rec)||
' SET X_REVENUE_TYPE_CD = REPLACE(X_REVENUE_TYPE_CD, ''-'', ''_'')'||
' WHERE INSTR(X_REVENUE_TYPE_CD, ''-'') > 0' ;
EXECUTE IMMEDIATE l_sql_stmt ;
END LOOP;
END
Reply With Quote
  #2 (permalink)  
Old 01-25-11, 16:07
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Wink

Something like this:

PHP Code:
#!/bin/ksh
#
export ORACLE_SID=orcl
ORACLE_ENV_ASK
=NO
. /usr/local/bin/oraenv

sqlplus 
-{uid}/{pw} <<EOSQL
set 
echo on
DECLARE
TYPE tbl_col_type is TABLE of VARCHAR2(50);
L_table_col tbl_col_type := tbl_col_type('X_ACC_REV_MNTH_AGG');
l_sql_stmt VARCHAR2(32000);
BEGIN
  
FOR rec IN L_table_col.FIRST..L_table_col.LAST
  LOOP
    l_sql_stmt 
:= 'UPDATE '||'KAW_OWNER.'||L_table_col(rec)
       ||
' SET X_REVENUE_TYPE_CD = REPLACE(X_REVENUE_TYPE_CD, ''-'', ''_'')'
       
||' WHERE INSTR(X_REVENUE_TYPE_CD, ''-'') > 0' ;
    
EXECUTE IMMEDIATE l_sql_stmt ;
  
END LOOP;
END;
/
exit
EOSQL 
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #3 (permalink)  
Old 03-24-11, 03:24
keviavuz78 keviavuz78 is offline
Registered User
 
Join Date: Mar 2011
Posts: 1
Awesome post!
I am waiting for your future thoughts. Thanks for sharing.

Thanks for sharing here!



bookkeeping services
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On