DBAs often deploy some sh scripts to log on to the ORACLE database to query the v $ dynamic view to get something for the purpose of actual management automation, but when writing ORACLESQL statements in the sh script,
DBAs often deploy some sh scripts to log on to the ORACLE database to query the v $ dynamic view to get something for the purpose of actual management automation, but when writing oracle SQL statements in the sh script,
DBAs often deploy some sh scripts to log on to the Oracle database to query the v $ dynamic view to get something for the purpose of actual management automation, but when writing oracle SQL statements in the sh script ,, if the statement queries the v $ view, writing v $ XXXX directly cannot be successful. shell treats $ as a parameter.
The following is a simple sh Script:/home/oracle/s_parameter.sh
Sqlplus/nolog <
Conn/as sysdba
Col inst_id for 99
Col name for a48
Col value for a64
Set pagesize 1000 line 180
Spool/home/oracle/1111.txt
Select inst_id, name, value from gv $ system_parameter order by 1, 2;
Spool off
Quit
EOF
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 2013
Copyright (c) 1982,201 1, Oracle. All rights reserved.
SQL> Connected.
SQL> select inst_id, name, value from gv order by 1, 2
*
ERROR at line 1:
ORA-00942: table or view does not exist
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 <
Conn/as sysdba
Col inst_id for 99
Col name for a48
Col value for a64
Set pagesize 1000 line 180
Spool/home/oracle/1111.txt
Select inst_id, name, value from gv \ $ system_parameter order by 1, 2;
Spool off
Quit
EOF
Run/home/oracle/s_parameter.sh to get the correct result (note the red "\" number in the table above)