[1] 去掉脚本中的包含commit、“setserverout off”、“set serverout on”、“set escape on”,和 “exec”的语句[2] 去掉“/”[3] 语句分隔符最好使用 “
分隔符” + “
换行”,如:
| ALTER TABLE xxx ADD (temp_advtoolbar CLOB)! UPDATE xxx SET temp_advtoolbar = advtoolbar! |
[4] 插入配置数据前需先判断数据是否存在当我们要在WCMConfig表中插入一条配置数据的时候,需要先判断该配置参数是否存在,注意该代码是以“end;!”结尾,如:
| declare v_count number(10); begin SELECT count(*) into v_count FROM xxx WHERE CKey = "KMS_UPLOAD_FILE_MAX_SIZE" ; if(v_count<=0 or v_count is null) then insert into xxx(configid,ctype,ckey,cvalue,cdesc) select max(configid)+1,12,"KMS_UPLOAD_FILE_MAX_SIZE","6291456","批量上传时可以上传的最大文件大小,单位为k" from xxx; update yyyset nextid=0 where tablename="xxx"; end if; end;! |
[5] 表上增加列需要先判断列是否存在当我们要在xxx表上增加LEAFFLAG列时,需要先判断xxx表是否已经存在LEAFFLAG列,注意该代码是以“end;!”结尾,具体代码如下:
| --增加是否允许创建子场景(即是否为叶子节点)的字段 2011.10.12 by liwei declare v_count number(10); begin SELECT count(*) into v_count FROM cols WHERE table_name = "xxx" and column_name="LEAFFLAG" ; if(v_count<=0 or v_count is null) then execute immediate("alter table xxx add LeafFlag number default 0 not null"); end if; end;! |
注意:当我们需要使用begin end语句块的时候,begin语句块中只能使用DML(数据操作语言,如:insert、delete、update和select),如增加配置参数的代码:
| declare v_count number(10); begin SELECT count(*) into v_count FROM xxx WHERE CKey = "KMS_UPLOAD_FILE_MAX_SIZE" ; if(v_count<=0 or v_count is null) then insert into xxx(configid,ctype,ckey,cvalue,cdesc) select max(configid)+1,12,"KMS_UPLOAD_FILE_MAX_SIZE","6291456","批量上传时可以上传的最大文件大小,单位为k" from wcmconfig; update yyy set nextid=0 where tablename="xxx"; end if;end;! |
当我们在增加列的时候,可能会使用到alter操作来给一个表添加一列,这时候我们需要使用动态sql(也就是execute immediate)来执行。因为begin end 语句块中只能执行DML语言,如果要执行DDL(alter、create等)语言,需要使用动态sql。如:
| declare v_count number(10);begin SELECT count(*) into v_count FROM cols WHERE table_name = "xxx" and column_name="LEAFFLAG" ; if(v_count<=0 or v_count is null) then execute immediate("alter table xxx add LeafFlag number default 0 not null"); end if;end;! |
Oracle入门教程:ADF 中使用Sequence的方法总结Oracle的三种高可用集群方案相关资讯 Oracle数据库 Oracle入门教程 oracle数据库教程
- Oracle数据库全球化 (03月01日)
- Oracle数据库日期过滤方法性能比较 (02/02/2015 13:20:26)
- Oracle数据库安装中端口被占用问题 (10/29/2014 07:42:24)
| - 在CentOS 6.6上搭建C++运行环境并 (10/10/2015 19:44:40)
- Oracle数据库无法使用localhost和 (11/14/2014 16:39:10)
- 使用SQLT来构建Oracle测试用例 (08/28/2014 06:17:41)
|
本文评论 查看全部评论 (0)