利用Ant向Oracle中插入数据

11 篇文章 0 订阅

[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;!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值