怎麼樣讓我的用戶名和密碼不洩漏?
=====================
在unix下
$ ps
oracle
oracle
采用sqlplus /nolog
sql>connect sys/sys
怎樣生成建表的完整的DDL語句?
====================
用exp
或者使用某些Oracle 的小工具
truncate table和delete table有些什麼區別?
==========================
truncate: DDL
delete: dml
如何刪除重復的記錄
=============
第一個辦法
第二個辦法
DELETE FROM table_name A WHERE ROWID >
( SELECT min(rowid) FROM table_name B
WHERE A
第三個辦法
Delete from my_table where rowid not in
( SQL> select max(rowid) from my_table
group by my_column_name );
第四個辦法
delete from my_table t
where exists (select
where t
and t
and t
如何快速為已有的表加上一個主鍵?
=====================
加上一個非空的列
update table_name set seqno=rownum;
或者
CREATE SEQUENCE testseq START WITH
update table_name set seqno=testseq
SQL排序問題
=====================================
在SQL*Server 裡面
從Oracle
select * from (select col
where rownum<
這樣就能夠起到同樣的效果
在Oracle
SELECT col
(SELECT /*+ INDEX_DESC (table_name index_name) */ col
WHERE rownum <
使用提示可以讓Oracle在子查詢返回結果之前先對他進行排序
我們可以分別查看兩個SQL的執行計劃
scott@testdb> select * from sort_sample;
ID NAME
scott@testdb> create index sort_id_idx on sort_sample(id);
Index created
scott@testdb> set autotrace on explain
scott@testdb>
scott@testdb> select * from (select * from sort_sample order by id desc) where rownum<
ID NAME
Execution Plan
scott@testdb>
scott@testdb> select * from sort_sample where rownum<
ID NAME
Execution Plan
scott@testdb> ANALYZE TABLE SORT_SAMPLE COMPUTE STATISTICS;
Table analyzed
scott@testdb> ANALYZE INDEX SORT_ID_IDX COMPUTE STATISTICS;
Index analyzed
scott@testdb>
scott@testdb> select * from (select /*+index_desc(sort_sample sort_id_idx)*/ * from sort_sample)
ID NAME
//原因
用group by可以生成從小開始的排序
scott@testdb> SELECT ID
ID NAME
Execution Plan
=================================
CHAO@PING>select * from testseq;
ID NAME
CHAO@PING>select id
ID NAME
CHAO@PING>
如何刪除一個列?
===========
從Oracle
alter table tab_name drop column col
==============
CHAO@PING> create table testrename(id number
Table created
CHAO@PING> begin
PL/SQL procedure successfully completed
CHAO@PING> commit;
Commit complete
CHAO@PING> alter table testrename add name varchar
Table altered
CHAO@PING> update testrename set name=nama;
CHAO@PING> alter table testrename drop column nama;
Table altered
CHAO@PING> select * from testrename;
ID NAME
From:http://tw.wingwit.com/Article/program/Oracle/201311/17969.html