Dear readers of our blog, we'd like to recommend you to visit the main page of our website, where you can learn about our product SQLS*Plus and its advantages.
 
SQLS*Plus - best SQL Server command line reporting and automation tool! SQLS*Plus is several orders of magnitude better than SQL Server sqlcmd and osql command line tools.
 

REQUEST COMPLIMENTARY SQLS*PLUS LICENCE

Enteros UpBeat offers a patented database performance management SaaS platform. It proactively identifies root causes of complex revenue-impacting database performance issues across a growing number of RDBMS, NoSQL, and deep/machine learning database platforms. We support Oracle, SQL Server, IBM DB2, MongoDB, Casandra, MySQL, Amazon Aurora, and other database systems.

Using SQLS*Plus

28 May 2020

USING SQLS*PLUS

SQLS*Plus is a client terminal software allowing users to interact with SQL Server to manipulate data and data structures. Users type in SQL statements in SQLS*Plus that send statements to SQL server. SQL Server then validates and executes the statements on its databases. The query results are returned to SQLS*Plus and displayed to the user.  Besides sending SQL statements to the server,  SQL*Plus also saves them into a local buffer and allow users to view and change the statements. The following figure illustrates the process, very similar to the Oracle SQL*Plus process

After you login into SQLS*Plus, at the SQL prompt, you can begin typing any SQL command. Upon hitting return (i.e., enter key) the SQL prompt will change to line number prompts. When you are finished typing a command, type / or RUN to execute the SQL command. Also, a semicolon at the end of the SQL command will execute the command immediately after hitting return. In addition to SQL commands, /, and RUN, you can also executes SQL*Plus file commands.

SQLS*Plus file commands

SQLS*Plus file command allow you to execute commands (or programs) stored in an external file, input or output data from/to a file, and save SQL commands typed during current session.

Some SQLS*Plus file commands are:

  • SAVE filename. This allows you to save buffer contents into a file.
  • START filename. This allows you to execute a batch of SQL statements stored in a file.
  • SPOOL filename. This allows you save SQL statements together with their outputs to a file.
  • GET filename. This retrieve a file and places it into the buffer.
  • @ filename. This allows you to execute a PL/SQL procedure(s) stored in a file.

SQLS*Plus edit commands

Recall that the previously executed commands (in current SQL*Plus session) are stored in the local buffer. One way to change an SQL statement in the buffer is by using the line editor. The following are a list of line edit commands.

  • LIST or L–Lists the contents of the buffer
  • LIST n or L n–Lists the contents of line number n in the buffer and makes the line current
  • LIST * or L *–Lists the current line
  • LIST m n–Lists the range from m to n line
  • Append text or A text–Adds to the end of the current line (e.g., “A ,” adds a comma to the end of line
  • INPUT or I–Adds one or more lines after the current line so you can begin adding the text.
  • CHANGE /text–Deletes text from the current line
  • CHANGE /oldtext/newtext–Replaces oldtext with newtext in the current line
  • DEL — Deletes the current line

Besides line editor,  you can also use the vi editor if you are a fan of Unix editor!.

To invoke the vi editor, type Edit at the SQL Prompt.   Multiple SQL commands can be typed in vi editor. End each SQL command (except the last one) with a semicolon. After exiting notepad, type Start to run all of the commands.

Run SQL statements in a batch

To run SQL commands in a batch, you can put all your SQL commands into a text file and execute these commands in this file in SQL*PLUS.

  • Use your favorite editor to type in your SQL queries into a text file.For example,

xxx@sf3:~/[513]$ more table.sql
DROP TABLE employee
/
commit
/
CREATE TABLE employee (
empno INTEGER NOT NULL,
name VARCHAR2(50) NOT NULL,
sal REAL NOT NULL,
primary key (empno));
/
INSERT INTO employee VALUES (1, ‘Jack’, 6000);
INSERT INTO employee VALUES (2, ‘Tom’,  6000);
INSERT INTO employee VALUES (3, ‘John’, 6000);
INSERT INTO employee VALUES (4, ‘Jane’, 6000);
/
UPDATE employee SET sal=500 WHERE name=’Jack’
/
CREATE INDEX test_index on employee(sal)
/
wanghao@sf3:~/cs6203[514]$

  • Connect into SQL*Plus, and run the batch of commands. For example, assume that you name the SQL file as table.sql.SQL> START table.sql;

Output results to a file

    • You can record your SQL command outputs to a file for output or editing purpose.SQLSPOOL <your file name> ;For example,SQL> SPOOL myoutput.out ;All SQL commands and their outputs after this command are written into the file myoutput.out that by default is stored in the current working directory where you invoked SQL*Plus.
    • To end recording, use the following command:

    SQL> SPOOL OFF;

DUAL and select the current time

The built-in function SYSDATE returns a DATE value containing the current date and time on your system. (Note SQL Server is a client-server architecture and SQLS*Plus is the client. SYSDATE gives you the time of the Unix system which you telnet in. It may NOT be the time of Oracle server unless you telnet into the machine running Oracle server.)

For example,

	SQL> SELECT GETDATE() as "Current Time";

returns

Current Time
---------------------------------------------------------------------------
2007-04-30 13:10:02.047
  • Simple formatting query results
  • To format a number attribute to a dollar format, use the column <attribute> format <format>:
      	SQL> COLUMN salary FORMAT $999,999
    
  • To indicate the displayed width of a character string attribute, use the column <attribute> format <A’format>. For example, set the width of the name attribute to 8 characters.
     	SQL> COLUMN name FORMAT A8
    

    If a name is longer than 8 characters, the remaining is displayed at the second line (or several lines)

  • The set command can be used to change the default number of lines per page (14) and the number of characters per line (80).For example, to set the number of lines per page to 60, use the following command:
    	SQL> SET PAGESIZE 60
    
  • All formatting remain active until they are cleared or reset or after you exit from SQL*Plus.
     	SQL> CLEAR COLUMN

Getting Help

  • If you forget a specific SQL command you could enter SQL> HELP <the SQL command>;
  • You could also find out all commands by entering:    SQL> HELP 
 
Tags: ,

MORE NEWS

 

Preamble​​NoSql is not a replacement for SQL databases but is a valid alternative for many situations where standard SQL is not the best approach for...

Preamble​​MongoDB Conditional operators specify a condition to which the value of the document field shall correspond.Comparison Query Operators $eq...

5 Database management trends impacting database administrationIn the realm of database management systems, moreover half (52%) of your competitors feel...

The data type is defined as the type of data that any column or variable can store in MS SQL Server. What is the data type? When you create any table or...

Preamble​​MS SQL Server is a client-server architecture. MS SQL Server process starts with the client application sending a query.SQL Server accepts,...

First the basics: what is the master/slave?One database server (“master”) responds and can do anything. A lot of other database servers store copies of all...

Preamble​​Atom Hopper (based on Apache Abdera) for those who may not know is an open-source project sponsored by Rackspace. Today we will figure out how to...

Preamble​​MongoDB recently introduced its new aggregation structure. This structure provides a simpler solution for calculating aggregated values rather...

FlexibilityOne of the most advertised features of MongoDB is its flexibility.  Flexibility, however, is a double-edged sword. More flexibility means more...

Preamble​​SQLShell is a cross-platform command-line tool for SQL, similar to psql for PostgreSQL or MySQL command-line tool for MySQL.Why use it?If you...

Preamble​​Writing an application on top of the framework on top of the driver on top of the database is a bit like a game on the phone: you say “insert...

Preamble​​Oracle Coherence is a distributed cache that is functionally comparable with Memcached. In addition to the basic function of the API cache, it...

Preamble​​IBM pureXML, a proprietary XML database built on a relational mechanism (designed for puns) that offers both relational ( SQL / XML ) and...

  What is PostgreSQL array? In PostgreSQL we can define a column as an array of valid data types. The data type can be built-in, custom or enumerated....

Preamble​​If you are a Linux sysadmin or developer, there comes a time when you need to manage an Oracle database that can work in your environment.In this...

Preamble​​Starting with Microsoft SQL Server 2008, by default, the group of local administrators is no longer added to SQL Server administrators during the...