When querying the Oraclev $ view in the Sh script, you must add the Escape Character "" before "$".

Source: Internet
Author: User
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.