1.基本結(jié)構(gòu)
CREATE OR REPLACE PROCEDURE 存儲過程名字 ( 參數(shù)1 IN NUMBER, 參數(shù)2 IN NUMBER ) IS 變量1 INTEGER :=0; 變量2 DATE; BEGIN END 存儲過程名字
關(guān)于oracle存儲過程的若干問題備忘select a.appname from appinfo a;-- 正確
select a.appname from appinfo as a;-- 錯(cuò)誤 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;-- 沒有into,編譯報(bào)錯(cuò),提示:Compilation Error: PLS-00428: an INTO clause is expected in this SELECT statement 可以在該語法之前,先利用select count(*) from 查看數(shù)據(jù)庫中是否存在該記錄,如果存在,再利用select...into...
4.在存儲過程中,別名不能和字段名稱相同,否則雖然編譯可以通過,但在運(yùn)行階段會報(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 假設(shè)有一個(gè)表A,定義如下:
6.Hibernate調(diào)用oracle存儲過程create table A(
id varchar2(50) primary key not null, vcount number(8) not null, bid varchar2(50) not null -- 外鍵 ); select sum(vcount) into fcount from A where bid='xxxxxx';
if fcount is null then
fcount:=0; end if; 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; } }); |
|