I have a script where I make a sqlplus connection. In the script I have multiple sql queries within that sqlplus connection. I want the result of the queries to be stored in shell variables declared earlier. I dont want to use procedures. Is there anyway else.
if the database is Oracle, you may use:
Update...
...
SET SERVEROUTPUT ON
DEFINE MYDATE = _DATE
exec dbms_output.put_line('Update completed at ' || TO_CHAR(MYDATE) );
SET SERVEROUTPUT OFF
...
#!/usr/bin/ksh
DB=abcd
USER=ghij
PASS=jjkil
DATA_PATH=./DATA
LOG_PATH=./LOG
SYear=`date +%Y`
SMonth=`date +%m`
SDay=`date +%d`
LOG_FILE=test.log
RPT_FILE=test.txt
sqlplus -s $USER/$PASS@$DB<<EOF1 > $LOG_PATH/$LOG_FILE 2>&1
SET SERVEROUTPUT ON
SET HEADING OFF
SET FEEDBACK OFF
SET WRAP OFF
SET PAGES 0
SET LINESIZE 32700
DEFINE MYDATE = _DATE
!echo " "`date` > home/LOG/test.log
exec dbms_output.put_line('Update completed at ' || TO_CHAR(MYDATE) );
SET SERVEROUTPUT OFF
QUIT
EOF1
When I run it I get this error
ERROR at line 1:
ORA-06550: line 1, column 62:
PLS-00201: identifier 'MYDATE' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Please help. I dont want to use pl/sql . Is there any other way or I can modify this one.
sqlplus -s ${user}@${pass}/@{inst} << EOF
set echo off head off feed off pagesize 0 trimspool on linesize 1000
spool table_update.log
update table1 set value1...
select 'Update completed at ' || to_char(sysdate, 'mm/dd/yyyy hh24:mi:ss') from dual;
update table2 set value2...
select 'Update completed at ' || to_char(sysdate, 'mm/dd/yyyy hh24:mi:ss') from dual;
spool off;
exit;
EOF
You can later read this spool file and fetch the values into a variable if you want. I hope this helps.