Hi Team,
Can you please help me to resolve this issue.
Am unable to use this $ symbol in sql query in the shell script.
For Example:
# !/bin/sh
export USER_NAME=XXX
export PASSWORD=YYY
export ORACLE_SID=xamdb
echo $ORACLE_SID
echo " Session Details ..."
DATE_TIME=`date +%Y%m%d_%H%M%S`
echo $DATE_TIME
#`$ORACLE_HOME/bin/
sqlplus $USER_NAME/$PASSWORD@xamdb << EOF
set serveroutput on
set feedback off
SELECT count(1) AS con_count, machine, username , osuser, status
FROM v$session
WHERE type <> 'BACKGROUND'
GROUP BY username, machine ,osuser, status
ORDER BY con_count DESC;
END;
/
EOF
echo "Completed Session details..."
Output:
SQL> SQL> SQL> SQL> SQL> 2 3 4 5 FROM v
*
ERROR at line 2:
ORA-00942: table or view does not exist
SQL> SQL> SP2-0042: unknown command "END" - rest of line ignored.
SQL> FROM v
*
ERROR at line 2:
ORA-00942: table or view does not exist
---------- Post updated at 05:22 PM ---------- Previous update was at 05:11 PM ----------
I got the answer. we should use \symbol.
SELECT count(1) AS con_count, machine, username , osuser, status
FROM v\$session
WHERE type <> 'BACKGROUND'
GROUP BY username, machine ,osuser, status
ORDER BY con_count DESC;