视窗
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;  

                        }  

                    });

 

 

【免责声明和版权说明】
本站部分信息来源于互联网,对转载的信息我们力求标明信息的出处,我们尊重作者的版权著作权,对我们转载的信息如有异议或有侵权或违法信息请及时联系我们,本站会立即删除,对原创内容我们愿意支付适当的稿酬,联系方式:邮件:webmaster@jscj.com 电话:4008816886

相关文章

无相关信息
更新时间2022-03-13 11:18:59【至顶部↑】
联系我们 | 邮件: webmaster@jscj.com | 客服热线电话:4008816886(QQ同号) |  婵犵數濮烽弫鍛婃叏閻戣棄鏋侀柟闂寸绾惧潡鏌熺€电ǹ啸缂佲偓婵犲洦鐓冪憸婊堝礈濮樿泛桅闁告洦鍨伴崡鎶芥煕閳╁喚娈旀い蹇d邯閺屾稑鈻庤箛鏇狀啋闂佸搫鐭夌紞渚€鐛崶顒夋晪闁告侗鍠楅惁婊堟⒒娴e懙褰掝敄閸℃稑绠查柛銉墯閸嬫ɑ銇勯弴妤€浜鹃悗瑙勬礀缂嶅﹪銆佸▎鎾崇煑闁靛/鍕剁础濠电姷鏁告慨鐑藉极閸涘﹥鍙忔い鎾卞灩绾惧鏌熼崜褏甯涢柣鎾存礋閺屾洘寰勭€n亞浠撮梺鍏兼た閸ㄤ即鍩㈤幘娲绘晝闁靛繆鏅滅€靛矂姊洪棃娑氬婵☆偅鐟╄棢闁糕剝菧娴滄粓鏌¢崒姘殹闁告梻鍠栭弻鐔肩嵁閸喚浼堥梺杞扮劍閹瑰洭寮幘缁樻櫢闁跨噦鎷�

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

客服电话: