2010-10-07 36 views
1

我正在使用ant目标创建一个用户,如下所示如何将信息从ant传递给sql文件或过程

<target name="create_user"> 
    <exec executable="sqlplus" dir="${basedir}/dbsetup"> 
      <arg value="system/[email protected]"/> 
      <arg value="@create_user.sql"/> 
    </exec>  
</target> 

和sql文件如下........

create user test identified by password; 

grant resource, connect to test ; 

grant create view to test ; 

grant create materialized view to test ; 

grant create sequence to test ; 

grant create procedure to test ; 

grant create any directory to test ; 

grant create database link to test ; 

alter user test quota unlimited on users; 

quit; 

目前用户名是硬编码的create_user.sql 现在我想从ant提示用户名和密码并传递给sql文件。

请建议我如何实现这个或其他方式,我可以实现

回答

0

一种选择是使用& 1位置参数的SQL文件,如:

create user &1 identified by password; 

提示与蚂蚁输入任务的用户名,然后通过该值作为ARG在你的目标在sqlplus :

<exec executable="sqlplus" failonerror="true"> 
     <arg value="${userid}/${password}@${tnsalias}"/> 
     <arg value="yourFileNameGoesHere/> 
     <arg value="theUserNameFromPromptGoesHere"/> 
    </exec> 

这具有保持可以从其他环境中,如SQL * Plus和PL/SQL开发人员

执行表单中的SQL文件的优势
2

我已经为这个问题做什么是创建一个包含令牌的模板SQL文件一些其他的方式。
我已经使用带有标记化的ant副本复制了模板,该模板创建了一个新的文件,其中标记已被替换为所提供的标记。
然后使用ant sql任务执行新副本。
如果需要,可以重复使用各种不同的标记值。

对于提示我已经使用了将输入值分配给变量的蚂蚁输入任务,
然后在复制之前将变量设置为标记值。