When querying the ORACLE v $ view in the Sh script, you need to add the Escape Character "\" before $ DBA. Some sh scripts are often deployed to log on to the ORACLE database to query the v $ dynamic view to get something practical. automated Management, however, when writing an oracle SQL statement in the sh script, if the statement queries the v $ view, writing v $ XXXX directly cannot be successful, and the shell regards $ as a parameter for processing. The following is a simple sh script:
/home/oracle/s_parameter.shsqlplus /nolog<<EOFconn / as sysdbacol inst_id for 99col name for a48col value for a64set pagesize 1000 line 180spool /home/oracle/1111.txtselect inst_id,name,value from gv$system_parameter order by 1,2;spool offquitEOF
When sh/home/oracle/s_parameter.sh is executed, the following table or view does not exist error is reported:
SQL*Plus: Release 11.2.0.3.0 Production on Sun Aug 18 11:28:17 2013Copyright (c) 1982, 2011, Oracle. All rights reserved.SQL> Connected.SQL> SQL> SQL> SQL> SQL> SQL> select inst_id,name,value from gv order by 1,2 *ERROR at line 1:ORA-00942: table or view does not existSQL> SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
Originally, gv $ system_parameter was written in the sh script file. However, only gv can be identified during execution. view names later than $ are not recognized. To solve this problem, you only need to add a "\" Escape Character before $. For example:
sqlplus /nolog<<EOFconn / as sysdbacol inst_id for 99col name for a48col value for a64set pagesize 1000 line 180spool /home/oracle/1111.txtselect inst_id,name,value from gv\$system_parameter order by 1,2;spool offquitEOF
Run/home/oracle/s_parameter.sh to get the correct result (note the red "\" number in the table above)