Oracle_071_lesson_p3

遠程登錄
conn hr/[email protected]: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;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章