oralce和db2兼容开发注意事项
数据库兼容,在开发项目过程中,难免会遇到更改数据库,或者后期项目升级,也可能会遇到这种情况,这里就说明下oralce和db2兼容开发注意事项。
兼容oralce、db2开发注意事项(前提是db2版本是9.7,且是开启PLSQL编译选项之后创建的数据库):
1.在like之后若使用了表字段,应统一改成使用locate函数
如:
oralce写法:
select*fromfw_rightawhere'03'likea.rightid||'%';
兼容写法:
select*fromfw_rightawherelocate('03',a.rightid)=1;
oralce写法:
select*fromfw_rightawhere'03'like'%'||a.rightid||'%';
兼容写法:
select*fromfw_rightawherelocate('03',a.rightid)>0;
2.视图中使用的别名不应该与当前表字段同名
如以下语句,在Oracle中不会有问题,但在db2中会报"SQL0153N"错误:
e.g: CREATEORREPLACEVIEWV_WF_TODOLISTAS selectc.process_def_id,c.process_def_name,a.action_def_id, a.work_item_id,a.bae007,a.action_def_name, a.state,a.pre_wi_id,a.work_type, a.operid,a.x_oprator_ids,b.process_key_info, to_char(to_date(a.start_time,'yyyymmddhh24miss'),'yyyy-mm-ddhh24:mi:ss')asstart_time, to_char(to_date(a.complete_time,'yyyymmddhh24miss'),'yyyy-mm-ddhh24:mi:ss')ascomplete_time, a.filter_opr,a.memo,a.bae002,a.bae003,a.bae006,c.x_action_def_ids fromwf_work_itema,wf_process_instanceb,wf_action_defc wherea.action_def_id=c.action_def_id andb.process_def_id=c.process_def_id anda.bae007=b.bae007 anda.statein('0','2')
兼容写法:
CREATEORREPLACEVIEWV_WF_TODOLISTAS selectc.process_def_id,c.process_def_name,a.action_def_id, a.work_item_id,a.bae007,a.action_def_name, a.state,a.pre_wi_id,a.work_type, a.operid,a.x_oprator_ids,b.process_key_info, to_char(to_date(a.start_time,'yyyymmddhh24miss'),'yyyy-mm-ddhh24:mi:ss')asstart_time_0, to_char(to_date(a.complete_time,'yyyymmddhh24miss'),'yyyy-mm-ddhh24:mi:ss')ascomplete_time_0, a.filter_opr,a.memo,a.bae002,a.bae003,a.bae006,c.x_action_def_ids fromwf_work_itema,wf_process_instanceb,wf_action_defc wherea.action_def_id=c.action_def_id andb.process_def_id=c.process_def_id anda.bae007=b.bae007 anda.statein('0','2')
3.在下列情况下不允许ORDERBY或FETCHFIRSTnROWSONLY:
* 外层全查询视图
* "SQL表函数"的RETURN语句中的外层全查询
* 具体化查询表定义
* 未用圆括号括起来的子查询
否则会报"SQL20211N 规范ORDERBY或FETCHFIRSTnROWSONLY无效。"错误.
e.g:
oralce写法:
CREATEORREPLACEVIEWV_FW_BLANK_BULLETINas selectid,bae001,operunitid,operunittype,unitsubtype,ifergency, title,content,digest,duetime,validto,aae100, bae006,bae002,bae003,idascolid, substr(digest,1,20)asdigest2 fromfw_bulletin whereduetime<=to_char(sysdate,'yyyymmddhh24miss') and(to_char(validto)>=to_char(sysdate,'yyyymmddhh24miss')orvalidtoisnull) andaae100='1' orderbyifergencydesc,iddesc,duetimedesc
兼容写法:
CREATEORREPLACEVIEWV_FW_BLANK_BULLETINas select*from(selectid,bae001,operunitid,operunittype,unitsubtype,ifergency, title,content,digest,duetime,validto,aae100, bae006,bae002,bae003,idascolid, substr(digest,1,20)asdigest2 fromfw_bulletin whereduetime<=to_char(sysdate,'yyyymmddhh24miss') and(to_char(validto)>=to_char(sysdate,'yyyymmddhh24miss')orvalidtoisnull) andaae100='1' orderbyifergencydesc,iddesc,duetimedesc)
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!