Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, MICHAEL.

Asked: August 25, 2022 - 2:54 pm UTC

Last updated: August 30, 2022 - 2:37 am UTC

Version: ORACLE 19C

Viewed 1000+ times

You Asked

I received error msg
SQL*Plus: Release 19.0.0.0.0 - Production on Thu Aug 25 10:18:09 2022
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle. All rights reserved.

SQL> SQL> SQL> SQL> 2 3 4 5 SP2-0640: Not connected
SQL> SQL> 2 3 4 SP2-0640: Not connected
SQL> SQL> SQL> 2 SP2-0640: Not connected
SQL> SP2-0640: Not connected
SQL> June month close has been completed successfully
APPCTRL: ACCT_PAY_PD_APD has been updated to 13
AAPDC : DOC CODE IPOF, PER 13 have been inserted and PER 12 deleted
DMFXJNCL,2022-08-25 10:18:09,INFO, Script DMFXJNCL Completed.
my code has sqlplus 2 times:
result_fy_per_flags=`sqlplus /nolog <<-EOF>> ${JIC_LOG_PATH}/${PROGRAM_LOG_FILE}
connect ${CWA_DB_USR}/${CWA_DB_PSWD}@${CWA_DB_NM}
set pagesize 0 feedback off verify off heading off echo off termout off heading off linesize 80
spool /tmp/result_with_data.txt
whenever sqlerror exit 12

SELECT FY, PER, CLSD_FL, CLSNG_PROC_RUN_FL
FROM FMS01.R_APD
WHERE FY = (SELECT PARM_VL
FROM ADM01.BS_CATALOG_PARM
WHERE PARM_NM = 'FY_CLOSE')
AND PER = (SELECT PARM_VL
FROM ADM01.BS_CATALOG_PARM
WHERE PARM_NM = 'ACTGPRD_CLOSE');
spool off;
exit;
EOF`
tail -2 /tmp/result_with_data.txt>/tmp/last2lines.txt
head -1 /tmp/last2lines.txt>/tmp/only4var
typeset -i myYEAR=`awk '{print $1}' /tmp/only4var`
period=`awk '{print $2}' /tmp/only4var`
echo "period was $period">/tmp/period

typeset -i clsdFL=`awk '{print $3}' /tmp/only4var`
typeset -i clsRUN=`awk '{print $4}' /tmp/only4var`
echo "\n** YEAR: $myYEAR *****PERIOD: $period ***********" >> $JIC_LOG_PATH/$PROGRAM_LOG_FILE
echo "************************END SQL************************************\n" >> $JIC_LOG_PATH/$PROGRAM_LOG_FILE
runTmpValidation
if [ ${rc} -eq 0 ]
then
echo "$SCRIPT,`date +%Y-%m-%d' '%H:%M:%S`,INFO,SQL ${JOB_NAME} ran successfully. Return code = [$rc]" >> $JIC_LOG_PATH/$PROGRAM_LOG_FILE
rc=0
else
echo "$SCRIPT,`date +%Y-%m-%d' '%H:%M:%S`,INFO,SQL ${JOB_NAME} Failed. Return code = [$rc]" >> $JIC_LOG_PATH/$PROGRAM_LOG_FILE
rc=12
fi
if [[ $period==12 && $clsdFL=1 && $clsRUN==1 ]]; then
echo " if was satisfied $result_fy_per_flags , $period ">/tmp/insidE_if
result_fy_per_flags=`sqlplus /nolog <<-EOF1> ${JIC_LOG_PATH}/${PROGRAM_LOG_FILE}

set pagesize 0 feedback off verify off heading off echo off termout off heading off linesize 80
whenever sqlerror exit 12
UPDATE IN_APP_CTRL
SET PARM_VL='13'
WHERE PARM_NM='ACCT_PAY_PD_APD'
echo " sqlcode for update of IN_APP_CTRL was $? "
commit;

INSERT INTO R_DOC_ALW_APD
SELECT DOC_TYP_SH_NM, DOC_CD, DOC_CD_SH_NM, DOC_CAT_SH_NM, FY, 13, 1,
SYSDATE
FROM R_DOC_ALW_APD WHERE DOC_CD='IPOF' AND FPD=12;
commit;

DELETE FROM R_DOC_ALW_APD
WHERE DOC_CD='IPOF' AND FPD=12;
commit;
exit
EOF1`

The EOF1 part did not work and produced error msg in the beginning, the connect
connect ${CWA_DB_USR}/${CWA_DB_PSWD}@${CWA_DB_NM} copied from before caused script to hanged, should i write
disconnect after select ... which worked and before update ...?


and Connor said...

Looking at your second sqlplus

sqlplus /nolog <<-EOF1> ${JIC_LOG_PATH}/${PROGRAM_LOG_FILE}


there seems to be no connect attempt made? That would explain why you are getting "Not Connected"

My personal preference is not to use the backquote syntax, ie

myvar = `sqlplus etc etc`

I prefer to get detailed logging and then extract what I need from that, eg (assuming ksh)

print "
connect ...
select ...
exit" | sqlplus /nolog 1>expected_output.log 2>error.log


Then I can grep error.log for unexpected things, and grep expected_output.log the data I want.


Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment