Re: Why doesn't output display SQL statement when using sqlplus in bash script?

From: Hans Forbrich <fuzzy.graybeard_at_gmail.com>
Date: Mon, 7 Mar 2016 20:25:15 -0700
Message-ID: <56DE461B.2010902_at_gmail.com>



SQLPlus was originally a report generator. The idea of listing the command would generally distract from the report and so would not be as great a priority as simply executing the command. There are an incredible number of useful reporting capabilities in the tool, and it saddens me greatly that there are so few people who actually know and understand the power of SQL*Plus, SQL*Developer and now SQLcl (which does everything that SQLPlus does and a whole lot more - see http://www.thatjeffsmith.com/archive/tag/sqlcl/.

To answer your question ... bear with me, some concept stuff is included:

When you type a command into SQLPlus, it is entered into a command buffer. There are several ways to 'close' that buffer:

  • A semi-colon, while watching for command block nesting;
  • A blank line, if not in a command block

A semi-colon on a simple SQL statement is interpreted as 'close the command buffer, and execute the command'

A blank line on a simple SQL statement is interpreted as 'close the command buffer but do NOT execute'

Whatever is currently in the command buffer may be re-executed using either

  • / (slash), which means execute without listing
  • 'RUN', which means LIST and then execute.

The LIST command is the inverse of '/' and simply lists the buffer without executing.

There are also a number of crude, but effective, commands useful for editing the buffer, including:

-  # (buffer line number) makes that the current line;
- ap  appends to the end of the current line
- del  deletes the current line
- in  inputs a new line(s) after the current one
- c/old/new/ replaces old string with new string, using / as separator 
(fist char after c is separator)

These things are discussed in the SQL*Plus manual. Refer to http://docs.oracle.com/database/121/SQPUG/ch_four.htm#SQPUG383 and http://docs.oracle.com/database/121/SQPUG/ch_twelve001.htm#SQPUG023

  HTH
/Hans

On 07/03/2016 1:08 AM, Nan Xiao wrote:
> Hi all,
>
> I am writing a Bash script which using sqlplus to connect Oracle
> database:
>
> #!/bin/bash
>
> sqlplus / as sysdba <<EOF
> select group#,members,bytes/1024/1024,status from v\$log;
> exit
> EOF
>
>
> Executing it, the output is:
>
> $ ./test.sh
>
> SQL*Plus: Release 12.1.0.2.0 Production on Mon Mar 7 02:57:57 2016
>
> Copyright (c) 1982, 2014, Oracle. All rights reserved.
>
>
> Connected to:
> Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit
> Production
> With the Partitioning, OLAP, Advanced Analytics and Real
> Application Testing options
>
> SQL>
> GROUP# MEMBERS BYTES/1024/1024 STATUS
> ---------- ---------- --------------- ----------------
> 1 1 102400 CURRENT
> 3 1 102400 UNUSED
> 2 1 102400 INACTIVE
>
> SQL> Disconnected from Oracle Database 12c Enterprise Edition
> Release 12.1.0.2.0 - 64bit Production
> With the Partitioning, OLAP, Advanced Analytics and Real
> Application Testing options
>
>
> The SQL statement runs successfully. But I am curious about why the
> statement doesn't display in output: There
> is empty after `SQL> `.
>
> Best Regards
> Nan Xiao

--
http://www.freelists.org/webpage/oracle-l
Received on Tue Mar 08 2016 - 04:25:15 CET

Original text of this message