SQL*Plus Flashcards
What is SQL*Plus?
An interface that allows users to communicate with the database.
What can you do within SQL*Plus?
- Run SQL queries and PL/SQL code
- Issues DBA commands
- Startup/Shutdown databases
What MUST you do BEFORE starting a SQL*Plus session?
Set the Environment Variables:
- ORACLE_SID=orcl
- ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
- LD_LIBRARY_PATH
Export the Environment Variables:
- $ export ORACLE_SID
- $ export ORACLE_HOME
What are the ways you can start a SQL*Plus session from the Command Line?
-
Connect w/ the SYSDBA Account:
- $ sqlplus jbwilli1/password AS SYSDBA
-
OS Authenticated User Account:
- $ sqlplus /
-
Connect through OS Authentication using SYSDBA
- $ sqlplus / AS SYSDBA
-
Connect to a non-default databases (i.e. A database not specified by ORACLE_SID):
- $ sqlplus jbwilli1/password@d0dv
- Note: The database name you’re trying to connect to MUST be listed in the tnsnames.ora file
What is the CONNECT command & What does it do?
The CONNECT command allows you to connect to the database as a different user OR connect to a different database from within SQL*Plus.
-
Connect as a different user:
- SQL> CONNECT username/password
-
Connect to a different database: (Only databases listed in tnsnames.ora)
- SQL> CONNECT jbwilli1/password@d0dv1
-
Connect as SYSDBA:
- SQL> CONNECT / AS SYSDBA
-
Connect to a different database as SYSDBA:
- SQL> CONNECT jbwilli1/password@d0dv1 AS SYSDBA
What is a SQL*Plus session with /NOLOG?
A SQL*Plus session with /NOLOG is a SQL*Plus session that is not connected to any database; which is used mostly for writing or editing scripts using SQL*Plus or PL/SQL commands.
- Syntax: $ sqlplus /NOLOG
- Note: If you decide you want to connect to a database you issue the CONNECT command to do so.
What is the product_user_profile table?
A table that limits access to SQL*Plus and PL/SQL commands. When a user logs into a SQL*Plus session, SQL*Plus checks this table to see what restrictions are supposed to be applied to the user.
Note: After creating a database, you should execute the pupbld.sql script, which is used to build the product_user_profile table. The script is located in $ORACLE_HOME/sql/admin
Note: By default, there are no rows in the table. The SYSDBA must insert rows manually if some users need to be restricted. You can restrict a user from executing the following commands:
- ALTER
- BEGIN
- CONNECT
- DECLARE
- EXEC
- EXECUTE
- GRANT
- HOST
- INSERT
- SELECT
- UPDATE
What is the RESTRICT command?
The RESTRICT command prevents users from using certain operating system (OS) commands. The RESTRICT command can be used at three levels:
Level 1: Restricts commands EDIT, HOST
Level 2: Restricts Level 1 + SAVE, SPOOL, STORE
Level 3: Restricts Levels 1 and 2 + GET, START
Syntax: $ sqplus RESTRICT -3
What is the SET command?
The SET command allows you to set the environment variables for your SQL*Plus sessions
Ex: SQL> SET PAGES 2000
Note: To get a complete list of all the variables that can be configured with the SET command type “help set” at the command line.
What is the SET SERVEROUTPUT command?
SET SERVEROUTPUT determines whether the output of a PL/SQL code or stored procedure is displayed on the screen.
Ex: SQL> SET SERVEROUTPUT ON
Note: You can format the output of text displayed on screen by using the FORMAT clause with the SET SERVEROUTPUT command. The FORMAT clause can take the values WRAPPED, WORD_WRAPPED, or TRUNCATED.
- WRAPPED = The output is wrapped within the length specified by the LINES command and new lines are started when output doesn’t fit the specification.
- WORD_WRAPPED = Wraps each lines to the length specified by the value of LINES and if a word won’t fit at the end of a line, the line ends before the word.
- TRUNCATED = Each line of output is cut off exactly at the length of the LINES value.
Ex: SQL> SET SERVEROUTPUT ON FORMAT WORD_WRAPPED
SQL> SET LINES 200
How can I customize my environment variables for every SQL*Plus login?
You specify your preferences in the login.sql file which is usually located in your home directory, BUT, you may have to create and configure it manually.
What is the STORE command?
The STORE command allows you to save the values of your environment variables in a script so you may use them at a later date.
Ex: SQL> STORE SET my_sqlplus.sql (This will store your current environment variables in the sqlplus.sql file)
Ex: SQL> @my_sqlplus.sql (OR add the my_sqlplus script to the login.sql file so it will configure your environment every time you log into SQL*Plus)
What is the SHOW command?
The SHOW command displays specified variable values
Ex: SQL> SHOW variable_name
What is the SHOW ALL command?
The SHOW ALL command displays all the variables in your current environment
What is the SHOW RECYCLEBIN command?
Displays all the tables in the Recycle Bin that can be recovered using the FLASHBACK TO BEFORE DROP command.
Ex: SQL> SHOW RECYCLEBIN