远程登录
conn hr/hr@192.168.133.117:1521/orcl <-SID

SQL->l SQL->a where id=1 不换行进行语句追加 SQL->c /whree/where 修改语句 SQL->r 执行

清空buff
clear buff

删除行号 del 行号
del 5

删除多行 del 行号1 行号2 del 2 3

增加行 SQL> i where 1=1; 在最后增加 SQL>0 select 在最前增加 SQL>1 where 1=1; 改变第1行的内容

报告SQL>@?/rdbms/admin/awrrpt #?表示$ORACLE_HOME

SAVE filename GET filename START filename @ filename EDIT filename SPOOL filename EXIT filename set AutoTRACE 执行计划

where 子句 select * from emp where employee_id=100; where='字符串' 注意格式和加单引号 如dd-MON-RR 03-AUG-08 除了=,还有> >= < <= <> != 符号 between A and B 边界值A和B会参与取值运算 in(A,B,C) like
like '%s%' 多字符匹配%
like 's' 单字符匹配 is null 和 is not null 字符串比较,只比较第1个字符的顺序,null 不参与比较

and or not 判断 where salary >=10000 and job_id like '%MAN%' where salary >=10000 or job_id like '%MAN%' where job_id not in ('IT_PROG','SA_REP') where 子句操作优先级 参考lesson_p3-20页 1.括号 2.连接. 3.......

排序 order by 默认升序 asc 降序desc order by salary ; order by salary desc; order by salary,department_id desc; 多字段排序,order by 后跟的第1字段最重要

select a,b from tab order by 1 desc , 2 desc ; 1,2表示select后的字段序号 ,不建议使用1,2,3之类的排序语法;

TOP N 取值 offset fetch first with ties 即有并列值也输出

如取前10行 order by salary desc
fetch first 10 rows only;

取前6-10行 order by salary desc offset 5 rows fetch next 5 rows only;

前2行有相同值会一并输出 order by salary desc fetch first 2 rows with ties;

替换变量(&和&&) where department_id = &department_id <-&后的名字自行命名 可在where, order by , select 表名及列名中加入变量& 如select name,&id from tab where department=&department_id; &&会自动记录第1次输入的变量

定义变量difine define column=salary; select &column from employees order by &column; 取消定义 undefine column

查看变量替换过程 set verify on 关闭查看替换过程 set verify off

解锁用户 alter user hr account unlock;

解锁用户并改密码 alter user hr identified by newhr account unlock;