用户名: 密码: 验证码:           网站地图 高级搜索 RSS订阅 收藏本站
Google
您的位置:首页>>网络编程>>Oracle>>阅读资讯:关于Oracle存储过程的若干问题备忘

关于Oracle存储过程的若干问题备忘

[ 来源: | 阅读:次 | 更新日期:2007-9-21 19:04:45 | 评论 0 条 | 我要投稿 ]
 1.在oracle中,数据表别名不能加as,如:

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

字串5

  select a.appname from appinfo as a;-- 错误

字串8

  也许,是怕和oracle中的存储过程中的关键字as冲突的问题吧

字串9

  2.在存储过程中,select某一字段时,后面必须紧跟into,如果select整个记录,利用游标的话就另当别论了。

字串9

   select af.keynode into kn from APPFOUNDATION af where af.appid=aid and af.foundationid=fid;-- 有into,正确编译

yueluo.net

   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"异常。

字串7

  可以在该语法之前,先利用select count(*) from 查看数据库中是否存在该记录,如果存在,再利用select...into...

字串6

  4.在存储过程中,别名不能和字段名称相同,否则虽然编译可以通过,但在运行阶段会报错

字串7

  select keynode into kn from APPFOUNDATION where appid=aid and foundationid=fid;-- 正确运行 字串7

  select af.keynode into kn from APPFOUNDATION af where af.appid=appid and af.foundationid=foundationid;-- 运行阶段报错,提示 yueluo.net

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

  5.在存储过程中,关于出现null的问题

月落

  假设有一个表A,定义如下: 月落网

  create table A( 字串9

  id varchar2(50) primary key not null, www.yueluo.net

  vcount number(8) not null,

字串5

  bid varchar2(50) not null -- 外键 www.yueluo.net

  );如果在存储过程中,使用如下语句:

月落

  select sum(vcount) into fcount from A where bid='xxxxxx';如果A表中不存在bid="xxxxxx"的记录,则fcount=null(即使fcount定义时设置了默认值,如:fcount number(8):=0依然无效,fcount还是会变成null),这样以后使用fcount时就可能有问题,所以在这里最好先判断一下: 字串9

  if fcount is null then

www.yueluo.net

   fcount:=0; www.yueluo.net

  end if;这样就一切ok了。

月落

  6.Hibernate调用oracle存储过程 字串6

 this.pnumberManager.getHibernateTemplate().execute(

字串8

  new HibernateCallback() ...{

月落网

   public Object doInHibernate(Session session)

月落

   throws HibernateException, SQLException ...{ 字串6

   CallableStatement cs = session.connection().prepareCall("{call modifyapppnumber_remain(?)}"); 字串6

   cs.setString(1, foundationid); 字串9

   cs.execute(); 字串6

   return null;

字串6

  } 字串8

 }); 字串6


Tags:Oracle,存储过程
责任编辑:
您的评论
用户名:新注册) 密码: 匿名评论 [所有评论]

·用户发表意见仅代表其个人意见,并且承担一切因发表内容引起的纠纷和责任
·本站管理人员有权在不通知用户的情况下删除不符合规定的评论信息或留做证据
·请客观的评价您所看到的资讯,提倡就事论事,杜绝漫骂和人身攻击等不文明行为