访问数据库的几种方法(一)

2015-07-24 06:48:44 · 作者: · 浏览: 0
这部分很基础,但是如果搞不清楚,对以后的学习会有影响。
SQL> select * from v$version where rownum=1;


BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

1.sqlplus username/password@net_service_name (这是通过网络访问)
C:\Users\Administrator>sqlplus hr/hr@55


SQL*Plus: Release 11.2.0.1.0 Production on 星期日 5月 17 01:14:04 2015


Copyright (c) 1982, 2010, Oracle. All rights reserved.

连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
======================================================== C:\Users\Administrator>sqlplus


SQL*Plus: Release 11.2.0.1.0 Production on 星期日 5月 17 01:16:47 2015


Copyright (c) 1982, 2010, Oracle. All rights reserved.


请输入用户名: hr@55
输入口令:


连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> exit
从 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

================================================================

C:\Users\Administrator>sqlplus /nolog


SQL*Plus: Release 11.2.0.1.0 Production on 星期日 5月 17 01:17:17 2015


Copyright (c) 1982, 2010, Oracle. All rights reserved.


SQL> conn hr/hr@55
已连接。


当然也可以过EZCONNECT连接 数据库(easy connect):

CONNECT username/password@host[:port]/service_name[/instance_name]
CONNECT username/password@[//]host[:port]/service_name


\


假如你连接没有成功检查一下客户端\network\admin\sqlnet.ora下:
SQL> select * from v$version where rownum=1;


BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production


添加EZCONNECT:
NAMES.DIRECTORY_PATH= (TNSNAMES,EZCONNECT)
下面模拟不添加EZCONNECT:
n罐?+?f?*??????	3??FB8?	1?$郗忽n峨⒍??q?⑺l?e喝k?郗$>[??j堑?5喧??????v?醋?
??!低}?从帧?Oracle. All rights reserved.
连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


3.
[oracle@localhost ~]$ sqlplus sys/manager as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on 星期日 5月 17 02:12:49 2015
Copyright (c) 1982, 2009, Oracle. All rights reserved.
连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

4.
[oracle@localhost ~]$ sqlplus
SQL*Plus: Release 11.2.0.1.0 Production on 星期日 5月 17 02:13:45 2015
Copyright (c) 1982, 2009, Oracle. All rights reserved.
请输入用户名: hr
输入口令:
连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

5.
[oracle@localhost ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on 星期日 5月 17 02:15:09 2015
Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL> connect hr/hr
已连接。
SQL> exit
从 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options 断开
[oracle@localhost ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on 星期日 5月 17 02:15:40 2015
Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL> connect sys/manager as sysd