国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > Oracle > 正文

關于Oracle存儲過程的若干問題探討

2024-08-29 13:28:26
字體:
來源:轉載
供稿:網友

本文探討了在Oracle數據庫時應該注意的一些問題及使用技巧。

(1)在Oracle中,數據表別名不能加as,如:

select a.appname from appinfo a;-- 正確

select a.appname from appinfo as a;-- 錯誤

也許,是怕和oracle中的存儲過程中的關鍵字as沖突的問題吧

(2)在存儲過程中,select某一字段時,后面必須緊跟into,如果select整個記錄,利用游標的話就另當別論了。

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,編譯報錯,提示:Compilation

Error: PLS-00428: an INTO clause is expected in this SELECT statement

(3)在利用select...into...語法時,必須先確保數據庫中有該條記錄,否則會報出"no data found"異常。

可以在該語法之前,先利用select count(*) from 查看數據庫中是否存在該記錄,如果存在,再利用select...into...

(4)在存儲過程中,別名不能和字段名稱相同,否則雖然編譯可以通過,但在運行階段會報錯

select keynode into kn from APPFOUNDATION where appid=aid and foundationid=fid;-- 正確運行

select af.keynode into kn from APPFOUNDATION af where af.appid=appid and af.foundationid=foundationid;-- 運行階段報錯,提示

ORA-01422:exact fetch returns more than requested number of rows

(5)在存儲過程中,關于出現null的問題

假設有一個表A,定義如下:

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';如果A表中不存在bid="xxxxxx"的記錄,則fcount=null(即使fcount定義時設置了默認值,如:fcount number(8):=0依然無效,fcount還是會變成null),這樣以后使用fcount時就可能有問題,所以在這里最好先判斷一下:

  if fcount is null then

   fcount:=0;

  end if;這樣就一切ok了。

  6.Hibernate調用oracle存儲過程

 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;

  }

 });

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 连南| 定结县| 宁晋县| 平顶山市| 都匀市| 华坪县| 阳朔县| 石棉县| 仙居县| 安西县| 阳原县| 互助| 尚志市| 闽侯县| 阜阳市| 鸡东县| 顺义区| 临汾市| 都兰县| 汕尾市| 巴彦淖尔市| 海宁市| 吴忠市| 尖扎县| 巴林左旗| 宜川县| 苏尼特右旗| 宝山区| 阳江市| 汉川市| 宾川县| 蒙自县| 九寨沟县| 平昌县| 承德县| 濮阳市| 什邡市| 庆城县| 比如县| 民勤县| 福海县|