新聞中心
以下的文章主要是對(duì)Oracle數(shù)據(jù)庫(kù)在存儲(chǔ)過(guò)程中出現(xiàn)的若干問(wèn)題的深入討論,如果你想對(duì)Oracle數(shù)據(jù)庫(kù)在存儲(chǔ)過(guò)程中出現(xiàn)的若干問(wèn)題有個(gè)詳細(xì)了解的話,以下就是詳細(xì)內(nèi)容的描述,希望在你今后的學(xué)習(xí)中會(huì)有所幫助。

創(chuàng)新互聯(lián)建站客戶idc服務(wù)中心,提供服務(wù)器機(jī)柜租用、成都服務(wù)器、成都主機(jī)托管、成都雙線服務(wù)器等業(yè)務(wù)的一站式服務(wù)。通過(guò)各地的服務(wù)中心,我們向成都用戶提供優(yōu)質(zhì)廉價(jià)的產(chǎn)品以及開放、透明、穩(wěn)定、高性價(jià)比的服務(wù),資深網(wǎng)絡(luò)工程師在機(jī)房提供7*24小時(shí)標(biāo)準(zhǔn)級(jí)技術(shù)保障。
1.在Oracle中,數(shù)據(jù)表別名不能加as,如:
- select a.appname from appinfo a;
正確
- select a.appname from appinfo as a;
錯(cuò)誤。也許,是怕和Oracle中的存儲(chǔ)過(guò)程中的關(guān)鍵字as沖突的問(wèn)題吧
2.在存儲(chǔ)過(guò)程中,select某一字段時(shí),后面必須緊跟into,如果select整個(gè)記錄,利用游標(biāo)的話就另當(dāng)別論了。
- select af.keynode into kn from APPFOUNDATION af where
af.appid=aid and af.foundationid=fid;
有into,正確編譯
- select af.keynode from APPFOUNDATION af where
af.appid=aid and af.foundationid=fid;
沒(méi)有into,編譯報(bào)錯(cuò),提示:Compilation
- Error: PLS-00428: an INTO clause is expected in this Select statement
3.在利用select...into...語(yǔ)法時(shí),必須先確保Oracle數(shù)據(jù)庫(kù)中有該條記錄,否則會(huì)報(bào)出"no data found"異常。
可以在該語(yǔ)法之前,先利用select count(*) from 查看數(shù)據(jù)庫(kù)中是否存在該記錄,如果存在,再利用select...into...
4.在存儲(chǔ)過(guò)程中,別名不能和字段名稱相同,否則雖然編譯可以通過(guò),但在運(yùn)行階段會(huì)報(bào)錯(cuò)
- select keynode into kn from APPFOUNDATION where appid=aid and foundationid=fid;
正確運(yùn)行
- select af.keynode into kn from APPFOUNDATION af where af.appid=appid and af.foundationid=foundationid;
運(yùn)行階段報(bào)錯(cuò),提示
- orA-01422:exact fetch returns more than requested number of rows
5.在存儲(chǔ)過(guò)程中,關(guān)于出現(xiàn)null的問(wèn)題
假設(shè)有一個(gè)表A,定義如下:
- create table A(
- id varchar2(50) primary key not null,
- vcount number(8) not null,
- bid varchar2(50) not null
外鍵
);如果在存儲(chǔ)過(guò)程中,使用如下語(yǔ)句:
select sum(vcount) into fcount from A where bid='xxxxxx';如果A表中不存在bid="xxxxxx"的記錄,則fcount=null(即使fcount定義時(shí)設(shè)置了默認(rèn)值,如:fcount number(8):=0依然無(wú)效,fcount還是會(huì)變成null),這樣以后使用fcount時(shí)就可能有問(wèn)題,所以在這里***先判斷一下:
- if fcount is null then
- fcount:=0;
end if;這樣就一切ok了。
6.Hibernate調(diào)用Oracle存儲(chǔ)過(guò)程
- this.pnumberManager.getHibernateTemplate().execute(
- new HibernateCallback() ...{
- public Object doInHibernate(Session session)
- throws HibernateException, SQLException ...{
- CallableStatement cs = session
- .connection()
- .prepareCall("{call modifyapppnumber_remain(?)}");
- cs.setString(1, foundationid);
- cs.execute();
- return null;
- }
- });
延伸閱讀:
詳細(xì)講解 DB2 9存儲(chǔ)過(guò)程的規(guī)劃和實(shí)施技
Oracle數(shù)據(jù)庫(kù)與SQL Server選型時(shí)注意的三個(gè)差異
Oracle 10g ASM 的一點(diǎn)經(jīng)驗(yàn)
Oracle 9i和10g在create index和rebuild index的統(tǒng)計(jì)信息的區(qū)別
文章出自:http://www.programbbs.com/doc/4831.htm
文章名稱:Oracle數(shù)據(jù)庫(kù)在存儲(chǔ)過(guò)程中經(jīng)常出現(xiàn)的若干問(wèn)題
當(dāng)前鏈接:http://m.fisionsoft.com.cn/article/ccscpoi.html


咨詢
建站咨詢
