About SQL*Plus


SQL*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 Reference

Connecting to the Database with SQL*Plus


Oracle Database includes the following components:

  • The Oracle Database instance, which is a collection of processes and memory

  • A set of disk files that contain user data and system data

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 multiple Oracle instances 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

根据你的平台,您可能必须在启动SQL * Plus之前设置环境变量,或至少验证设置是否正确

例如,在大多数平台上,必须设置ORACLE_SID和ORACLE_HOME。另外,建议将PATH环境变量设置为包含ORACLE_HOME / bin目录。有些平台可能需要额外的环境变量:

  • 在UNIX和Linux平台上,您必须通过输入操作系统命令来设置环境变量。
  • 在Windows平台上,Oracle Universal Installer(OUI)会自动将值分配给Windows注册表中的ORACLE_HOME和ORACLE_SID。

对于所有平台,当在具有不同Oracle主目录的实例之间切换时,必须更改ORACLE_HOME环境变量。如果多个实例共享同一个Oracle主目录,则在切换实例时必须仅更改ORACLE_SID。

 setenv ORACLE_SID orcl
setenv ORACLE_HOME /u01/app/oracle/product/11.2./db_1
setenv LD_LIBRARY_PATH $ORACLE_HOME/lib:/usr/lib:/usr/dt/lib:/usr/openwin/lib:/usr/ccs/lib

Example 1-1 Setting Environment Variables in UNIX (C Shell)

 SET ORACLE_SID=orawin2

Example 1-2 Setting Environment Variables in Windows

Example 1-2假定在注册表中设置了ORACLE_HOME和ORACLE_SID,但你希望覆盖ORACLE_SID的注册表值以连接到其他实例。 在Windows上,您在命令提示符窗口中设置的环境变量值会覆盖注册表中的值。

Step 3: Start SQL*Plus

sqlplus /nolog

Step 4: Submit the SQL*Plus CONNECT Statement

the CONNECT statement is as follows:

CONN[ECT] [logon] [AS {SYSOPER | SYSDBA}]

The syntax of logon is as follows:

{username | /}[@connect_identifier] [edition={edition_name | DATABASE_DEFAULT}]

下表介绍了CONNECT语句的语法:

/

调用连接请求的外部认证。这种类型的认证中不使用数据库密码。

最常见的外部身份验证形式是操作系统身份验证,其中数据库用户通过使用

特定主机用户帐户登录到主机操作系统进行身份验证。外部认证也可以通过

Oracle wallet或network service来进行。

参阅:Oracle Database Security Guide

AS {SYSOPER | SYSDBA} 

表示数据库用户正在使用SYSOPER或SYSDBA系统特权进行连接。只有

某些预定义的管理用户或已添加到密码文件的用户才可以使用这些权限进行连接。

参阅:Administrative Privileges    Using Operating System Authentication

username  

一个有效的数据库用户名。数据库通过将用户名与数据字典匹配并提示输入用户密码

来验证连接请求

connect_identifier (1)  一个Oracle Net连接标识符,用于远程连接。确切的语法取决于Oracle Net配置。

如果省略,SQL * Plus将尝试连接到本地实例。 常用连接标识符是网络服务名称。
这是Oracle Net连接描述符(网络地址和数据库服务名称)的别名。别名通常在本
地计算机上的tnsnames.ora文件中解析,但可以用其他方式解析

connect_identifier (2)

作为替代,连接标识符可以使用简单连接语法。轻松连接为远程数据库提供开箱即用

的TCP / IP连接,而无需在客户端(本地)计算机上配置Oracle Net Services。 连

接标识符的简单连接语法如下(必须包含括起来的双引号):

host[:port][/service_name][:server][/instance_name]
  • server是服务处理程序的类型。可接受的值是专用,共享和合并的。如果省略,

则默认类型的服务器由侦听器选择:共享服务器(如果已配置),否则为专用

服务器

参阅:Oracle Database Net Services Administrator's Guide

edition={edition_name|DATABASE_DEFAULT}

指定新数据库会话启动的版本。如果指定一个版本,它必须存在,并且您必须具有USE

特权。如果未指定此子句,则会话将使用数据库默认版本

参阅:Oracle Database Advanced Application Developer's Guide

参考资料

https://docs.oracle.com/cd/E11882_01/server.112/e25494/dba.htm#ADMIN12472

使用SQL*Plus连接数据库的更多相关文章

  1. Oracle安装步骤及PL/SQL Developer连接数据库

    一:Oracle安装步骤及PL/SQL Developer连接数据库 win7 64位 11g 点击(操作步骤):http://www.cnblogs.com/haoke/articles/27343 ...

  2. Oracle SQL Developer 连接数据库如何对应数据库配置文件

    Oracle SQL Developer 连接数据库如何对应数据库配置文件 1.数据库配置文件 hibernate.connection.url jdbc:oracle:thin:@146.56.35 ...

  3. Oracle SQL Developer 连接数据库问题总结

    一.使用scott用户登录的问题 说明:Oracle如果是初次使用用户,scott用户是没有解锁的.所以要先解锁.注:scott是个测试用户. 具体步骤: 1.在Dos命令下输入 sqlplus 可以 ...

  4. Oracle 使用SQL*Plus连接数据库

    Oracle使用SQL*Plus连接数据库 by:授客 QQ:1033553122   使用sqlplus连接数据库 A 方式1 1.开启SQL*Plus,但不连接到数据库 $ sqlplus /NO ...

  5. 解决PL/SQL Developer连接数据库时出现 “ORA-12541:TNS:无监听程序”错误

    在用PL/SQL Developer连接数据库时出现“ORA-12541:TNS:无监听程序”错误. 1.检查listener.log日志发现下面错误:TNSLSNR for 32-bit Windo ...

  6. 本地不安装oracle-client,使用pl/sql developer连接数据库

    一.问题描述 本地未安装oracle-client端,由于机器资源有限,希望通过pl/sql developer进行远程数据库连接.单纯的安装pl/sql developer无法远程连接数据库. 二. ...

  7. [转]使用Oracle SQL Developer连接数据库并创建用户

    本文转自:http://blog.csdn.net/xw13106209/article/details/6594738 1.使用sys账户创建数据库连接 安装Oracle 11g会自带一个叫做SQL ...

  8. 不安装Oracle客户端情况下使用PL/SQL 远程连接数据库

    附送PL/SQL Developer11中文版下载地址 1.先到Oracle网站下载Instant Client : http://www.oracle.com/technetwork/databas ...

  9. PL/sql developer连接数据库的问题以及oracle数据库中文乱码的问题

    今天第二次配置PL/sql developer,表示很蛋疼,昨天因为动了一个东西然后莫名其妙的就再也连接不了数据库,总是显示各种错误,我动的东西是因为中文会显示乱码,(因为我是用32位的PL/sql ...

  10. SQL Server连接数据库失败,可能的问题!

    SQL Server Configuration Manager中启动服务 SQL Server外围应用配置器中,打开远程IP连接属性 别的应该没什么问题了!

随机推荐

  1. Git(管理修改)

    现在,假定你已经完全掌握了暂存区的概念.下面,我们要讨论的就是,为什么Git比其他版本控制系统设计得优秀,因为Git跟踪并管理的是修改,而非文件. 你会问,什么是修改?比如你新增了一行,这就是一个修改 ...

  2. Vue项目搭建

    1.环境搭建 安装node 官网下载安装包,傻瓜式安装:https://nodejs.org/zh-cn/ 安装cnpm npm install -g cnpm --registry=https:// ...

  3. java Calendar 入门【转】

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar c = Calendar. ...

  4. VMware Workstation Pro 14 虚拟机安装教程

    准备学习一下linxus,可不想双系统,那么只有虚拟机这条路了.故在此记录一下安装VMware的过程. 一.下载VMware 我用的是VMware Workstation Pro 14(其他版本也可以 ...

  5. 绕不开的hadoop

    安装 jdk 1.8 # 官网下载可能比较慢,请自行搜索国内镜像源 wget http://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a ...

  6. 转载---滋滋有味看完的一篇文章关于python与java夜话

    这是一个程序员的电脑硬盘,在一个叫做"学习"的目录下曾经生活着两个小程序,一个叫做Hello.java,即Java小子:另外一个叫做hello.c ,也就是C老头儿. C老头儿的命 ...

  7. bash 刷题leetcode

    题目一: 给定一个文本文件 file.txt,请只打印这个文件中的第十行. 示例: 假设 file.txt 有如下内容: Line 1 Line 2 Line 3 Line 4 Line 5 Line ...

  8. spingBoot整合mybatis+generator+pageHelper

    spingBoot整合mybatis+generator+pageHelper 环境/版本一览: 开发工具:Intellij IDEA 2018.1.4 springboot: 2.0.4.RELEA ...

  9. 配置tomcat限制指定IP地址访问后端应用

    1. 场景后端存在N个tomcat实例,前端通过nginx反向代理和负载均衡. tomcat1      tomcatN         |                 |        |    ...

  10. 使用phpexcel上传下载excel文件

    1. 下载 <?php /** * Created by lonm.shi. * Date: 2012-02-09 * Time: 下午4:54 * To change this templat ...