1,"&"有時候不認,則改為"&"
?? 但在執行insert操作或update操作時如果sql語句中含"&",如何處理?
?? ? ?? 1) update userinfo set pageurl='myjsp?page=1'||'&'||'pagesize=10' where id='test' ??????? 2) update userinfo set pageurl='myjsp?page=1'||chr(38)||'pagesize=10' where id='test'其中||是連字符, chr(38)跟ASCII的字符轉碼是一致的。plsql中還可以set define off來關閉特殊字符,還可以用show define來查看有些特殊定義的字符
2,慎用where pid!=3等用法,這樣沒有囊括is null的情況,要實現同樣目的可where pid!=3 or pid is null
3,快速從另外一個表復制數據
? insert into tablea (id,name) select id,name from tableb
4,查版本
? select * from PRODUCT_COMPONENT_VERSION;或 select * from v$version;
5,nls==National ? Language ? Support ? 國際語言支持
6,PLSQL
? HKEY_CURRENT_USER\Software\Allround Automations
? HKEY_CURRENT_USER\Software\Microsoft\Security
7,查blob大小
? select dbms_lob.getlength(blobfield) from wd_blob
8,改變表空間
? alter table TB_USER move tablespace myspace;
? 如果被轉移表空間的表含有索引, 表轉移后索引變得不可用. 要刪除舊索引,建立新索引
? alter index user_name.index_name rebuild; 主鍵索引名與主鍵名相同
9,導入時表空間錯誤
? 導出dmp時的用戶的默認表空間必須是表所在的表空間,這樣導入時才不會出錯。
? 如果dmp小,也可用UE打開直接修改表空間。
10,用select into 復制數據
insert into test
? (id, name)
? select id, name from mis@dblink;
? 或
? create table test--需先刪表
as (select * from mis@dblink)
11,中文字段按拼音排序:
select username from tab_name order by nlssort(username,'nls_sort=schinese_pinyin_m');
按偏旁部首:
select username from tab_name order by nlssort(username,'nls_sort=schinese_radical_m');
按筆畫:
select username from tab_name order by nlssort(username,'nls_sort=schinese_stroke_m');
12,插入帶單引號的字符
insert into t(a) values ('a'||chr(39)||'b' );
或insert into t(a) varlus ('a''b');
13,如果你連接到數據庫后沒有在取nextval之后再取currval,就會出現ORA-08002出錯. ?
? 因此對每一個session來說,應該先用nextval,才可以取currval。
14
truncate table mapevent時,如果建了外鍵引用(外鍵所在那張表不一定有數據,有數據就會報另外一個錯誤了)
則報 ORA-02266:表中的唯一主鍵被啟用的外部關鍵字引用
ORA-02266: unique/primary keys in table referenced by enabled foreign keys
(外鍵所在那張表無數據時delete from table mapevent是可以執行的)
正確的步驟:
----------------
alter table mapevent disable primary key cascade;
truncate table mapevent;
alter table mapevent enable primary key;
---------------
15
查詢某個表被哪些表引用
select *
? from user_constraints t
?where t.constraint_type = 'R'
?? and t.r_constraint_name = '該表的主鍵名';
16,按中文排序,但中文的一二三四五有問題,可用下面的辦法:
select * from T_TIME_SETUP order by translate(ccname,'一二三四五','12345')
來源:http://www.itpub.net/226375,1.html
17,誤刪了怎么辦?用Oracle中的回閃查詢
查20分鐘前的數據:
?select * from tb_wz as of timestamp(sysdate - 20 / 1440)
? http://blog.csdn.net/xuyuan77/archive/2007/06/06/1640757.aspx
18,導出帶有blobh或clob類型字段表時會出現:EXP-00003: 未找到段 (8,375419) 的存儲定義
?原因見http://read.newbooks.com.cn/info/116619.html
19,導出命令
exp Test1/Test1passwd@服務名 owner=Test1 file=D:\files\Test1.dmp log=d:\log.log
exp還有一個參數full=y
imp aichannel/aichannel@HUST full=y? file=test.dmp ignore=y
20,查oracle的保留字 select * from v$reserved_words
21,修改序列的當前值
alter sequence userseq increment by 500;
?select userseq.nextval from dual;
alter sequence userseq increment by 1;
22,序列跳20號
create sequence ORA_SEQ
minvalue 100000000000
maxvalue 999999999999
start with 100000000260
increment by 1
cache 20
如果設置了cache 20,數據庫關閉時這20個序列成員會丟失,造成序列不連續的現象。
序列設置nocache模式即可
http://topic.csdn.net/u/20090421/20/7edde8ab-dbcc-4765-b9b9-a7fae3d2af39.html
絕不能跳號的序列號設計問題 http://www.itpub.net/viewthread.php?tid=403149
23,用9i的OEM去連10g,如果是普通用戶登錄,就會報
你必須具有select any dictionary權限才能運行此應用程序,請要求DBA為你賦予此權限
?這是是9I的OEM在連接10G的數據庫的時候的一個BUG,目前沒有解決辦法。
http://www.itpub.net/thread-888007-1-1.html
24,可用其他dba用戶修改system用戶的密碼
25,查看oracle最大連接數
show parameter processes
show parameter sessions
一個session對應一個process,但是一個process未必對應一個session
SELECT * FROM v$process p
?WHERE NOT EXISTS (SELECT 1 FROM v$session WHERE p.paddr = p.addr);
?alter system set sessions=300 scope=spfile;需重啟
v$resource_limit視圖各字段的含義
current_utilization ? - ? Number ? of ? (resources, ? locks, ? or ? processes) ? currently
being ? used
max_utization ? - ? Maximum ? consumption ? of ? the ? resource ? since ? the ? last
instance ? start ? up 自從上次啟動以來的最大值
initial_allocation ? - ? Initial ? allocation. ? This ? will ? be ? equal ? to ? the ? value
specified ? for ? the ? resource ? in ? the ? initialization ? parameter
file ? (UNLIMITED ? for ? infinite ? allocation)
limit_value ? - ? Unlimited ? for ? resources ? and ? locks. ? This ? can ? be ? greater
than ? the ? initial ? allocation ? value ? (UNLIMITED ? for ? infinite
limit).
26,
IMP-00003: 遇到 ORACLE 錯誤 959
ORA-00959: 表空間'TBS_BSS'不存在
這種類型的錯誤往往是因為表上有大字段,而大字段所在的表空間不存在。普通字段是可以導到不同名的表空間的。
27,
alter table USERS add? primary key (userid);//不好,會自動生成約束名,不利于移植數據
alter table USERS? add? constraint PK_USERS? primary key (userid);//ok.外鍵也是如此。
28,
INTERSECT
操作符用來返回兩個查詢中都存在的記錄,即返回兩個查詢結果的交集,前提是兩個查詢的列的數量和數據類型必須完全相同。