视窗
loading...
您现在的位置:首页 > IT认证 > oracle认证 >

Oracle备份恢复:oracle存储过程注意事项


1.在oracle中,数据表别名不能加as 

    [html] 

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

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

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

    [html] 

    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.在存储过程中,别名不能和字段名称相同,否则虽然编译可以通过,但在运行阶段会报错

    [html] 

    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,定义如下:

    [html] 

    create table A(  

    id varchar2(50) primary key not null,  

    vcount number(8) not null,  

    bid varchar2(50) not null -- 外键   

    );  

 

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

    [html] 

    select sum(vcount) into fcount from A where bid='xxxxxx';  

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

    [html] 

    if fcount is null then  

        fcount:=0;  

    end if;  

    这样就一切ok了。

    6.Hibernate调用oracle存储过程

    [html] 

    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;  

                        }  

                    });

閵嗏偓

閵嗏偓

閵嗘劕鍘ょ拹锝咃紣閺勫骸鎷伴悧鍫熸綀鐠囧瓨妲戦妴锟�
閺堫剛鐝柈銊ュ瀻娣団剝浼呴弶銉︾爱娴滃簼绨伴懕鏃傜秹閿涳拷鐎电娴嗘潪鐣屾畱娣団剝浼呴幋鎴滄粦閸旀稒鐪伴弽鍥ㄦ娣団剝浼呴惃鍕毉婢跺嫸绱�閹存垳婊戠亸濠囧櫢娴f粏鈧懐娈戦悧鍫熸綀閽佹ぞ缍旈弶鍐跨礉鐎佃鍨滄禒顒冩祮鏉炵晫娈戞穱鈩冧紖婵″倹婀佸鍌濐唴閹存牗婀佹笟鍨綀閹存牞绻氬▔鏇氫繆閹垵顕崣濠冩閼辨梻閮撮幋鎴滄粦閿涘本婀扮粩娆庣窗缁斿宓嗛崚鐘绘珟閿涳拷鐎电懓甯崚娑樺敶鐎硅鍨滄禒顒佸姽閹板繑鏁禒姗€鈧倸缍嬮惃鍕归柊顒婄礉閼辨梻閮撮弬鐟扮础閿涙岸鍋栨禒锟�:webmaster@jscj.com閵嗏偓閻絻鐦介敍锟�4008816886

相关文章

无相关信息
更新时间2022-03-13 11:18:59【至顶部↑】
联系我们 | 邮件: webmaster@jscj.com | 客服热线电话:4008816886(QQ同号) |  濠电儑缍€椤曆勬叏閻愮鍋撻獮鍨仾婵犫偓閸パ屽殫妞ゆ棁顔婄换锟�

付款方式留言簿投诉中心网站纠错二维码手机版

客服电话: