欢迎您来到GIS动力

加入收藏 免费注册 用户登陆 帮助中心
首页 新闻动态 技术专栏 银杏树下 学习考研 软件下载 求职招聘 许愿瓶 节日祝福 用户中心 精彩推荐 资源搜索 地图
专栏导航: AO开发 | SO开发 | ArcGIS桌面 | 超图桌面 | 开发语言 | 数据库 | WebGIS | 银杏文学 | 研究生考题 | FreeMap 谈天说地
   您现在位于: 首页技术专栏数据库 → 正文
关于Oracle存储过程的若干问题备忘
08-01-22 00:00:00 作者: 出处:天极论坛整理

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;  

   }  

  });  

   cs.setString(1, foundationid);  

   cs.execute();  

   return null;  

   }  

  });  

 


(本文已被浏览 次)
发布人:admin
推荐给好友:发送给好友
上篇新闻:
下篇新闻:
相关评论
发表我的评论
  • 尊重网上道德,遵守《全国人大常委会关于维护互联网安全的决定》及中华人民共和国其他各项有关法律法;
  • 本站有权保留或删除您发表的任何评论内容;
  •   相关文章  
    Java程序员的存储过程

    关于我们 友情链接 ┋ 与我在线 ┋ 管理 ┋ TOP
    网站当前版本:GisPower CMS V3.0
    『GIS 动力』- http://www.gispower.org/
    联系我们:webmaster#gispower.org
    Copyright (c) 2003-2007 GisPOwer.Org. All Rights Reserved.

                   滇ICP备05006901号