Oracle® Database 2 Day DBA 11g Release 1 (11.1) Part Number B28301-03 |
|
|
View PDF |
To perform many of its operations, Oracle Enterprise Manager Database Control (Database Control) submits structured query language (SQL) statements to the database. SQL (pronounced like sequel) is an industry-standard English-like computer programming language for querying and updating databases.
The following is an example of a SQL query that lists information about countries in a countries table, which is owned by user hr
:
SELECT COUNTRY_ID, COUNTRY_NAME FROM HR.COUNTRIES;
SQL is a powerful language that can also be used to perform a variety of database administration tasks. The following SQL statement creates the database user nick
and assigns him a password of your choosing, represented by password:
CREATE USER nick IDENTIFIED BY password;
When performing an administrative task in Database Control, you can click Show SQL to see the SQL statements that Database Control generates and submits.
In addition to using the graphical management pages presented in Database Control, you can use other Oracle tools such as SQL Developer and SQL*Plus to issue SQL statements. These tools enable you to perform database management operations, and to query, insert, update, or delete data directly in the database. The following sections provide details:
SQL*Plus is a command-line program that you use to submit SQL and PL/SQL statements to an Oracle database. You can submit statements interactively or as SQL*Plus scripts. SQL*Plus is installed with the database and is located in your Oracle_home
/bin
directory.
You can start SQL*Plus from the command line, or on Microsoft Windows, from the Start menu.
When SQL*Plus loads, it issues the SQL prompt, which looks like this:
SQL>
At the SQL prompt, you can enter statements that perform administrative tasks such as shutting down the database or creating a new user, or you can query, insert, update, and delete data.
You can enter a single SQL statement on multiple lines. You must end each statement with a semicolon (;). For most statements, you can rerun a statement by entering a forward slash (/) on a line by itself.
See Also:
The section describes how to start SQL*Plus and connect to the database from both the command line and the Windows start menu.
To start SQL*Plus and connect to the database from the command line:
Open a command window.
(Linux and UNIX systems only) Set the required environment variables (ORACLE_HOME
and ORACLE_SID
) by running the script oraenv
(for the Bourne, Korn, or Bash shell) or coraenv
(for the C shell).
These scripts are typically located in the /usr/local/bin
directory. They may prompt you for the desired value of the ORACLE_SID
environment variable. If so, supply the system ID (SID) that you chose when you installed Oracle Database. The default SID that the installer typically suggests is orcl
.
(Linux and UNIX systems only) Either ensure that the Oracle_home
/bin
directory is in your PATH
environment variable, or change to the Oracle_home
/bin
directory.
Enter the following command:
sqlplus {username | /} [as sysdba] Enter password: password
SQL*Plus connects you to the default database instance (Microsoft Windows) or the database instance specified by the environment variables (Linux and UNIX).
For username
, you can use the SYS
or SYSTEM
administrative users. At the prompt, enter the password that you set up during installation. If you use the SYS
user, you must include as sysdba
after the username.
When you enter SYS
or a slash (/
) as the user name and provide the as
sysdba
clause, you are authenticating using operating system authentication. Operating system authentication uses your Windows, UNIX, or Linux host user account to authenticate you to Oracle Database. You must have logged in to the host computer with a user account that is a member of a special host user group. On UNIX and Linux, this user group is typically dba
. This type of authentication enables you to connect to an Oracle database that is not yet started, so that you can start it up. See Oracle Database Administrator's Guide for more information.
To start SQL*Plus and connect to the database from the Windows Start menu:
Click Start, select Programs (or All Programs), then Oracle - HOME_NAME, then Application Development, and then SQL*Plus.
When prompted, enter the user name and password for the account that you want to use to connect to the database.
For the user name, you can use the SYS
or SYSTEM
administrative accounts, and you can use the password that you set up during installation.
If you use SYS
or /
as the user name, follow them with a space and then the clause as
sysdba
, as shown in the following examples:
Enter user-name: sys as sysdba
Enter password: password
or
Enter user-name: / as sysdba
When you enter SYS
or a slash (/
) as the user name and provide the as
sysdba
clause, you are authenticating using operating system authentication. Operating system authentication uses your Windows, UNIX, or Linux host user account to authenticate you to Oracle Database. You must have logged in to the host computer with a user account that is a member of a special host user group. On UNIX and Linux, this user group is typically dba
for the sysdba privilege. This type of authentication enables you to connect to an Oracle database that is not yet started, so that you can start it up. See Oracle Database Administrator's Guide for more information.
SQL Developer provides another graphical user interface for accessing your Oracle database. SQL Developer supports development in both the SQL and PL/SQL languages. It is available in the default installation of Oracle Database.
With SQL Developer, you can browse database objects, run SQL statements and SQL scripts, and edit and debug PL/SQL statements. You can also run any number of provided reports, as well as create and save your own.
See Also:
Oracle Database 2 Day Developer's Guide for instructions for starting SQL Developer