Oracle進階之你可能會用到的命令(一)
阿新 • • 發佈:2018-12-24
不管你天天使用Oracle還是剛接觸Oracle,下面的這些命令或許在你忘記了的時候能幫忙快速找回來。
1. 檢視當前使用者
show user;
2. 去掉重複記錄的關鍵詞
distinct
3. 字串拼接連線符
||
4. 錄屏
spool 路徑
spool off
5. 檢視引數設定
select * from v$nls_parameters;
6. 排序空值放最後邊
nulls last
7. 格式化時間
to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')
8. 通用函式
nvl(a,b),當a為null時,返回b,
nvl2(a,b,c) 當a=null的時候,返回c;否則返回b
nullif(a,b) 當a=b的時候,返回null;否則返回a
coalesce(a,b,c..) 從左到右 找到第一個不為null的值
9. case表示式
case (列名) when ... then ...
when ... then ...
else ...
end;
10. group by 增強
group by rollup(a,b)
11. 層次查詢
select level,empno,ename,mgr
from emp
connect by prior empno=mgr
start with mgr is null
order by 1; (emp表中的empno員工號,mgr員工老闆號)
12. 針對操作給予反饋
set feedback off oracle(關閉)
13. 建立事物中的儲存點
savepoint a;
14. 不走回收站刪除表 (管理員沒有回收站)
drop table 表名 purge;
15. 閃回
flashback table 表名 to before drop;
16. 遮蔽檢視的DML操作
在建立檢視的時候後面加 with read only
17. 建立序列:
create sequence 序列名
*****************************************************
另附一份sql優化原則,我們都在意的是細節
1.儘量使用別名
2.sql解析是從右往左的,所以and時候假的在右,or的時候真的在右
3.能用having和where,儘量使用where
4.儘量使用多表查詢,而不是子查詢
5.union和union all都可以時候,儘量用union all(union=union all +distinct)
6.儘量不要使用集合運算
1. 檢視當前使用者
show user;
2. 去掉重複記錄的關鍵詞
distinct
3. 字串拼接連線符
||
4. 錄屏
spool 路徑
spool off
5. 檢視引數設定
select * from v$nls_parameters;
6. 排序空值放最後邊
nulls last
7. 格式化時間
to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')
8. 通用函式
nvl(a,b),當a為null時,返回b,
nvl2(a,b,c) 當a=null的時候,返回c;否則返回b
nullif(a,b) 當a=b的時候,返回null;否則返回a
coalesce(a,b,c..) 從左到右 找到第一個不為null的值
9. case表示式
case (列名) when ... then ...
when ... then ...
else ...
end;
10. group by 增強
group by rollup(a,b)
11. 層次查詢
select level,empno,ename,mgr
from emp
connect by prior empno=mgr
start with mgr is null
order by 1; (emp表中的empno員工號,mgr員工老闆號)
12. 針對操作給予反饋
set feedback off oracle(關閉)
13. 建立事物中的儲存點
savepoint a;
14. 不走回收站刪除表 (管理員沒有回收站)
drop table 表名 purge;
15. 閃回
flashback table 表名 to before drop;
16. 遮蔽檢視的DML操作
在建立檢視的時候後面加 with read only
17. 建立序列:
create sequence 序列名
*****************************************************
另附一份sql優化原則,我們都在意的是細節
1.儘量使用別名
2.sql解析是從右往左的,所以and時候假的在右,or的時候真的在右
3.能用having和where,儘量使用where
4.儘量使用多表查詢,而不是子查詢
5.union和union all都可以時候,儘量用union all(union=union all +distinct)
6.儘量不要使用集合運算