查看文章 |
Submitting Commands and SQL to the DatabaseThe primary means of communicating with Oracle Database is by submitting SQL statements. Oracle Database also supports a superset of SQL, which includes commands for starting up and shutting down the database, modifying database configuration, and so on. There are three ways to submit these SQL statements and commands to Oracle Database:
This section focuses on using SQL*Plus to submit SQL statements and commands to the database. It includes the following topics: About SQL*PlusSQL*Plus is the primary command-line interface to your Oracle database. You use SQL*Plus to start up and shut down the database, set database initialization parameters, create and manage users, create and alter database objects (such as tables and indexes), insert and update data, run SQL queries, and more. Before you can submit SQL statements and commands, you must connect to the database. With SQL*Plus, you can connect locally or remotely. Connecting locally means connecting to an Oracle database running on the same computer on which you are running SQL*Plus. Connecting remotely means connecting over a network to an Oracle database that is running on a remote computer. Such a database is referred to as a remote database. The SQL*Plus executable on the local computer is provided by a full Oracle Database installation, an Oracle Client installation, or an Instant Client installation. See Also: SQL*Plus User's Guide and ReferenceConnecting to the Database with SQL*PlusOracle Database includes the following components:
When you connect with SQL*Plus, you are connecting to the Oracle instance. Each instance has an instance ID, also known as a system ID (SID). Because there can be more than one Oracle instance on a host computer, each with its own set of data files, you must identify the instance to which you want to connect. For a local connection, you identify the instance by setting operating system environment variables. For a remote connection, you identify the instance by specifying a network address and a database service name. For both local and remote connections, you must set environment variables to help the operating system find the SQL*Plus executable and to provide the executable with a path to its support files and scripts. To connect to an Oracle instance with SQL*Plus, therefore, you must complete the following steps: Step 1: Open a Command Window Step 2: Set Operating System Environment Variables Step 3: Start SQL*Plus Step 4: Submit the SQL*Plus CONNECT Statement See Also: Oracle Database Concepts for background information about the Oracle instanceStep 1: Open a Command WindowTake the necessary action on your platform to open a window into which you can enter operating system commands.
Step 2: Set Operating System Environment VariablesDepending on your platform, you may have to set environment variables before starting SQL*Plus, or at least verify that they are set properly. For example, on most platforms, UNIX and Linux installations come with two scripts, For all platforms, when switching between instances with different Oracle homes, you must change the Refer to the Oracle Database Installation Guide or administration guide for your operating system for details on environment variables and for information on switching instances. Example 1-1 Setting Environment Variables in UNIX (C Shell) setenv ORACLE_SID orcl Example 1-2 assumes that On Windows, environment variable values that you set in a command prompt window override the values in the registry. Step 3: Start SQL*PlusTo start SQL*Plus:
Step 4: Submit the SQL*Plus CONNECT StatementYou submit the SQL*Plus CONN[ECT] [logon] [AS {SYSOPER | SYSDBA}]
The syntax of {username | /}[@connect_identifier]
When you provide The following table describes the syntax components of the
Example 1-3 This simple example connects to a local database as user connect system Example 1-4 This example connects to a local database as user connect sys as sysdba When connecting as user Example 1-6 This example connects locally with the connect / as sysdba Example 1-7 This example uses easy connect syntax to connect as user connect salesadmin@db1.mycompany.com/sales.mycompany.com Example 1-8 This example is identical to Example 1-7, except that the listener is listening on the non-default port number 1522. connect salesadmin@db1.mycompany.com:1522/sales.mycompany.com Example 1-9 This example connects remotely as user connect salesadmin@sales1 Example 1-10 This example connects remotely with external authentication to the database service designated by the net service name connect /@sales1 Example 1-11 This example connects remotely with the connect /@sales1 as sysdba See Also:
|
