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

Source: Internet
Author: User

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)

Related Article

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.