1,"&"有時(shí)候不認(rèn),則改為"&"
?? 但在執(zhí)行insert操作或update操作時(shí)如果sql語(yǔ)句中含"&",如何處理?
?? ? ?? 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的字符轉(zhuǎn)碼是一致的。plsql中還可以set define off來(lái)關(guān)閉特殊字符,還可以用show define來(lái)查看有些特殊定義的字符
2,慎用where pid!=3等用法,這樣沒(méi)有囊括is null的情況,要實(shí)現(xiàn)同樣目的可where pid!=3 or pid is null
3,快速?gòu)牧硗庖粋€(gè)表復(fù)制數(shù)據(jù)
? 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 ? 國(guó)際語(yǔ)言支持
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;
? 如果被轉(zhuǎn)移表空間的表含有索引, 表轉(zhuǎn)移后索引變得不可用. 要?jiǎng)h除舊索引,建立新索引
? alter index user_name.index_name rebuild; 主鍵索引名與主鍵名相同
9,導(dǎo)入時(shí)表空間錯(cuò)誤
? 導(dǎo)出dmp時(shí)的用戶的默認(rèn)表空間必須是表所在的表空間,這樣導(dǎo)入時(shí)才不會(huì)出錯(cuò)。
? 如果dmp小,也可用UE打開(kāi)直接修改表空間。
10,用select into 復(fù)制數(shù)據(jù)
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');
按筆畫(huà):
select username from tab_name order by nlssort(username,'nls_sort=schinese_stroke_m');
12,插入帶單引號(hào)的字符
insert into t(a) values ('a'||chr(39)||'b' );
或insert into t(a) varlus ('a''b');
13,如果你連接到數(shù)據(jù)庫(kù)后沒(méi)有在取nextval之后再取currval,就會(huì)出現(xiàn)ORA-08002出錯(cuò). ?
? 因此對(duì)每一個(gè)session來(lái)說(shuō),應(yīng)該先用nextval,才可以取currval。
14
truncate table mapevent時(shí),如果建了外鍵引用(外鍵所在那張表不一定有數(shù)據(jù),有數(shù)據(jù)就會(huì)報(bào)另外一個(gè)錯(cuò)誤了)
則報(bào) ORA-02266:表中的唯一主鍵被啟用的外部關(guān)鍵字引用
ORA-02266: unique/primary keys in table referenced by enabled foreign keys
(外鍵所在那張表無(wú)數(shù)據(jù)時(shí)delete from table mapevent是可以執(zhí)行的)
正確的步驟:
----------------
alter table mapevent disable primary key cascade;
truncate table mapevent;
alter table mapevent enable primary key;
---------------
15
查詢某個(gè)表被哪些表引用
select *
? from user_constraints t
?where t.constraint_type = 'R'
?? and t.r_constraint_name = '該表的主鍵名';
16,按中文排序,但中文的一二三四五有問(wèn)題,可用下面的辦法:
select * from T_TIME_SETUP order by translate(ccname,'一二三四五','12345')
來(lái)源:http://www.itpub.net/226375,1.html
17,誤刪了怎么辦?用Oracle中的回閃查詢
查20分鐘前的數(shù)據(jù):
?select * from tb_wz as of timestamp(sysdate - 20 / 1440)
? http://blog.csdn.net/xuyuan77/archive/2007/06/06/1640757.aspx
18,導(dǎo)出帶有blobh或clob類型字段表時(shí)會(huì)出現(xiàn):EXP-00003: 未找到段 (8,375419) 的存儲(chǔ)定義
?原因見(jiàn)http://read.newbooks.com.cn/info/116619.html
19,導(dǎo)出命令
exp Test1/Test1passwd@服務(wù)名 owner=Test1 file=D:\files\Test1.dmp log=d:\log.log
exp還有一個(gè)參數(shù)full=y
imp aichannel/aichannel@HUST full=y? file=test.dmp ignore=y
20,查oracle的保留字 select * from v$reserved_words
21,修改序列的當(dāng)前值
alter sequence userseq increment by 500;
?select userseq.nextval from dual;
alter sequence userseq increment by 1;
22,序列跳20號(hào)
create sequence ORA_SEQ
minvalue 100000000000
maxvalue 999999999999
start with 100000000260
increment by 1
cache 20
如果設(shè)置了cache 20,數(shù)據(jù)庫(kù)關(guān)閉時(shí)這20個(gè)序列成員會(huì)丟失,造成序列不連續(xù)的現(xiàn)象。
序列設(shè)置nocache模式即可
http://topic.csdn.net/u/20090421/20/7edde8ab-dbcc-4765-b9b9-a7fae3d2af39.html
絕不能跳號(hào)的序列號(hào)設(shè)計(jì)問(wèn)題 http://www.itpub.net/viewthread.php?tid=403149
23,用9i的OEM去連10g,如果是普通用戶登錄,就會(huì)報(bào)
你必須具有select any dictionary權(quán)限才能運(yùn)行此應(yīng)用程序,請(qǐng)要求DBA為你賦予此權(quán)限
?這是是9I的OEM在連接10G的數(shù)據(jù)庫(kù)的時(shí)候的一個(gè)BUG,目前沒(méi)有解決辦法。
http://www.itpub.net/thread-888007-1-1.html
24,可用其他dba用戶修改system用戶的密碼
25,查看oracle最大連接數(shù)
show parameter processes
show parameter sessions
一個(gè)session對(duì)應(yīng)一個(gè)process,但是一個(gè)process未必對(duì)應(yīng)一個(gè)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 自從上次啟動(dòng)以來(lái)的最大值
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 錯(cuò)誤 959
ORA-00959: 表空間'TBS_BSS'不存在
這種類型的錯(cuò)誤往往是因?yàn)楸砩嫌写笞侄危笞侄嗡诘谋砜臻g不存在。普通字段是可以導(dǎo)到不同名的表空間的。
27,
alter table USERS add? primary key (userid);//不好,會(huì)自動(dòng)生成約束名,不利于移植數(shù)據(jù)
alter table USERS? add? constraint PK_USERS? primary key (userid);//ok.外鍵也是如此。
28,
INTERSECT
操作符用來(lái)返回兩個(gè)查詢中都存在的記錄,即返回兩個(gè)查詢結(jié)果的交集,前提是兩個(gè)查詢的列的數(shù)量和數(shù)據(jù)類型必須完全相同。