SQLPLUS calling Via Script

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers SQLPLUS calling Via Script
# 1  
Old 10-30-2017
SQLPLUS calling Via Script

Hello All,

Could you please help me if i am doing anything wrong in below script, especially the sqlplus part performance wise or anything else i could improvise in the script. Thank you.

Code:
#!/bin/ksh
## Batch Obj Id
MP_BCH_OBJ_ID=$1
PASS=$2
partition=$3

## script dir
RUN_DIR=$(dirname $0)

## Set/Source Environment #
cd ${RUN_DIR}


${ORACLE_HOME}/bin/sqlplus -s /nolog <<-EOF > /dev/null
conn el1acpt2/$PASS@AOWH01
spool ${SRC_DIR}/SRVC_CONV/RDW_SRVC_CONV_${MP_BCH_OBJ_ID}_$partition.dat;
set pagesize 0
set trimspool on
set heading off
set feedback off
select ACTVY_RPTNG_PER_DT||'|'||LN_ID||'|'||ARM_IDX_CD||'|'||RCRS_TYP_CD||'|'||LNDR_LN_ID from LN_ACTVY partition($3);
spool off;
EXIT;
EOF


Moderator's Comments:
Mod Comment Please use CODE (not HTML) tags as required by forum rules!

Last edited by RudiC; 10-31-2017 at 06:32 AM.. Reason: Changed HTML to CODE tags.
# 2  
Old 10-31-2017
Anything wrong with that script? Error messages? Undesired results?
# 3  
Old 10-31-2017
I don't see anything wrong with your script.

By the way you can establish a direct database connection instead of having a connection-less session with /NOLOG and then connecting.
Code:
${ORACLE_HOME}/bin/sqlplus -s  el1acpt2/$PASS@AOWH01 <<-EOF > /dev/null

NOLOG is useful for performing some database administration tasks, writing transportable scripts, or to use SQL*Plus editing commands to write or edit scripts.
# 4  
Old 10-31-2017
Quote:
Originally Posted by Yoda
I don't see anything wrong with your script.

By the way you can establish a direct database connection instead of having a connection-less session with /NOLOG and then connecting.
Code:
${ORACLE_HOME}/bin/sqlplus -s  el1acpt2/$PASS@AOWH01 <<-EOF > /dev/null

NOLOG is useful for performing some database administration tasks, writing transportable scripts, or to use SQL*Plus editing commands to write or edit scripts.
I am remember doing that in the past because the database username & passwords are visible, when if anyone else issues ps -ef command.
This User Gave Thanks to Ariean For This Post:
# 5  
Old 10-31-2017
Oh yes, /nolog will definitely help with that. By the way in our Linux environments it appears we used hide utility that will hide sqlplus arguments.
# 6  
Old 11-06-2017
Hello All,
i am trying to extract the data file via sqlplus and i wanted to capture the output of sqlplus into a log file and check for any syntax,Connection, DB errors etc.
But for some reason my logfile is filled up with the data of sqlplus output, and also process is running a long time because of this.
Appreciate your further inputs.


Code:
#${ORACLE_HOME}/bin/sqlplus -s /nolog <<-EOF > ${LOG_DIR}/edw_extract_RDW_Partition.sh.${MP_BCH_OBJ_ID}_${partition}.sql.log
${ORACLE_HOME}/bin/sqlplus -s /nolog <<-EOF > /dev/null
conn ${APPLICATION_ID}/${DB_PASS}@${RDW_DB}
spool ${SRC_DIR}/RDW_SRVC_CONV_${MP_BCH_OBJ_ID}_${partition}.dat;
set pagesize 0
set trimspool on
set heading off
set feedback off
set linesize 500
select to_char(ACTVY_RPTNG_PER_DT,'mm/dd/yyyy hh24:mi:ss')||'|'||LN_ID||'|'||'|'||'|'||'|'||'|'||ARM_IDX_CD||'|'||'|'||'|'||'|'||'|'||'|'||'|'||RCRS_TYP_CD||'|'||'|'||'|'||LNDR_LN_ID||'|'||'|'||'|'||'|'||'${MP_BCH_OBJ_ID}'||'|'||'|'||'${MP_EDW_USR_ID}'||'|'||'${MP_BCH_STRT_DTTM}'||'|'||'|' from $RDW_Schema.LL_LN_ACTVY_3 partition(${partition});
spool off;
EXIT;
EOF

# 7  
Old 11-07-2017
There is an Oracle system variable ERRORLOGGING.

This is useful for capturing errors generated from long running queries and avoids capturing all output using the SPOOL command, or having to remain present during the run.

Oracle writes errors to default table: SPERRORLOG You can run a select to view all the errors later:-
Code:
SELECT timestamp, 
       username, 
       script, 
       statement, 
       message 
FROM   sperrorlog;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Avoid $ symbol while calling sqlplus in shellscript.

Hi All, we have requirement, i am created a shell script , inside i am connecting sqlplus and execute the query. below my code for your reference. get_sqlid () { sqlid=$( sqlplus -s $PBDW_USERID/$PBDW_PW@$PBDW_SID <<EOF DEFINE TBLNAME=$1 set feedback off set serverout on size... (4 Replies)
Discussion started by: KK230689
4 Replies

2. Shell Programming and Scripting

Oracle/SQLPlus help - ksh Script calling .sql file not 'pausing' at ACCEPT, can't figure out why

Hi, I am trying to write a script that calls an Oracle SQL file who in turns call another SQL file. This same SQL file has to be run against the same database but using different username and password at each loop. The first SQL file is basically a connection test and it is supposed to sort... (2 Replies)
Discussion started by: newbie_01
2 Replies

3. Shell Programming and Scripting

Control not returning from Sqlplus to calling UNIX shell script.

Hello All, I have exactly same issue @vikas_trl had in following link: https://www.unix.com/shell-programming-and-scripting/259854-control-not-returning-sqlplus-calling-unix-shell-script.html I wonder if he or somebody else could find the issue's cause or the solution. Any help would... (4 Replies)
Discussion started by: RicardoQ
4 Replies

4. Shell Programming and Scripting

Control not returning from Sqlplus to calling UNIX shell script.

Hello All, I have a UNIX script which will prepare anonymous oracle pl/sql block in a temporary file in run time and passes this file to sqlplus as given below. cat > $v_Input_File 2>>$v_Log << EOF BEGIN EXECUTE IMMEDIATE 'ALTER SESSION FORCE PARALLEL DML PARALLEL 16'; EXECUTE... (1 Reply)
Discussion started by: vikas_trl
1 Replies

5. UNIX for Dummies Questions & Answers

calling a unix shell script from sqlplus

I want to execute a shell script from sqlplus prompt and get its output back to sqlplus. Is this possible? if yes just give me an example for doing that. (2 Replies)
Discussion started by: boopathyvasagam
2 Replies

6. Shell Programming and Scripting

Help supressing spool output from screen when calling sqlplus from script

I'm calling an embedded sql from my shell script file. This sql does simple task of spooling out the contents of the table (see below my sample code) into a spool file that I specify. So far so good, but the problem is that the output is also displayed on screen which I do NOT want. How can I... (3 Replies)
Discussion started by: MxC
3 Replies

7. Shell Programming and Scripting

Error in calling store procedure using SQLPLUS in unix

Hi, I am facing the following error in calling the stored procedure from SQLPLUS in unix environment. SQL> set serveroutput on SQL> var store number; SQL> exec test_proc(:store, 200); BEGIN TEST_PROC(:store, 200); END; * ERROR at line 1: ORA-01858: a non-numeric character was found... (8 Replies)
Discussion started by: pradeep7986
8 Replies

8. Shell Programming and Scripting

calling sqlplus, read table return etc

I have korn shell scripts. I want to pass a variable to a script which will execute a a sql script to read a table that contains env. variables. I want to read and then somehow export at unix level variables example for every row selected from the table build export command line field1... (5 Replies)
Discussion started by: TimHortons
5 Replies

9. Shell Programming and Scripting

calling sqlplus from within a for loop

i'm not new to programming, but i AM new to unix scripting. here's my deal. this works: #!/bin/ksh echo "HELLO" /oracle_home/bin/sqlplus username/password@MYDB<<EOF SELECT COUNT(*) FROM EMPLOYEES; EOF exit echo "GOODBYE" this doesn't: #!/bin/ksh echo "HELLO" for x in 1 2... (4 Replies)
Discussion started by: akosz
4 Replies

10. Shell Programming and Scripting

calling sqlplus from shell

Hi All, I am executing the following code :- sqlplus -s ${DATABASE_USER} |& print -p -- 'set feed off pause off pages 0 head off veri off line 500' print -p -- 'set term off time off serveroutput on size 1000000' print -p -- "set sqlprompt ''" print -p -- "SELECT run_command from... (2 Replies)
Discussion started by: suds19
2 Replies
Login or Register to Ask a Question