B. 使用最高权限使用者登陆sqlplus / as sysdba ;解释: as sysdba是指定登陆用户的角色为oracle数据库sys用户,而sys用户在oracle内部的地位就等于root在linux中的地位,最大权限,不受库的限制,是管理用户
为了学习sql语句,我们使用一个scott用户
解锁scott用户
[oracle@install0 oracle]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Fri May 26 16:47:07 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> show user; USER is "SYS" SQL> conn scott/tiger; ERROR: ORA-28000: the account is locked
Warning: You are no longer connected to ORACLE. SQL> conn / as sysdba; Connected. SQL> alter user scott identified by tiger account unlock;
User altered. SQL> conn scott/tiger; Connected. SQL> select * from tab;
connection name : scoot username: scoot password: triger save password yes hostname:172.25.0.11 port:1521 sid:db01
如果scott不存在如何创建
[oracle@oratest admin]$ pwd /u01/app/oracle/product/11.2.0.4/rdbms/admin [oracle@oratest admin]$ ls scott.sql ls: cannot access scott.sql: No such file or directory [oracle@oratest admin]$ ls utlsampl.sql utlsampl.sql [oracle@oratest admin]$ echo @$ORACLE_HOME/rdbms/admin/utlsampl.sql @/u01/app/oracle/product/11.2.0.4/rdbms/admin/utlsampl.sql [oracle@oratest admin]$ echo @$ORACLE_HOME/rdbms/admin/utlsampl.sql | sqlplus / as sysdba
SQL> column username format a20 SQL> column password format a20 SQL> column account_status format a20 SQL> select username,password,account_status from dba_users;
USERNAME PASSWORD ACCOUNT_STATUS -------------------- -------------------- -------------------- SYS OPEN SYSTEM OPEN SCOTT OPEN OUTLN EXPIRED & LOCKED APPQOSSYS EXPIRED & LOCKED DBSNMP EXPIRED & LOCKED DIP EXPIRED & LOCKED ORACLE_OCM EXPIRED & LOCKED
SQLPlus login.sql
sqlplus在启动时会自动运行两个脚本:glogin.sql、login.sql这两个文件
执行顺序为:
默认在在$ORACLE_HOME/sqlplus/admin路径下查找glogin.sql文件执行
默认在在当前路径下查找login.sql文件执行,若未查找到对应文件则执行3
判断是否设置SQLPATH环境变量,如果设置了该变量则在对应路径下查找并执行,未找到则停止查找
define _editor=vi set serveroutput on size 1000000 set trimspool on set long 5000 set linesize 100 set pagesize 9999 column plan_plus_exp format a80 set sqlprompt '&_user.@&_connect_identifier.>'