2010-10-07 81 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任務執行新副本。
如果需要,可以重複使用各種不同的標記值。

對於提示我已經使用了將輸入值分配給變量的螞蟻輸入任務,
然後在複製之前將變量設置爲標記值。

相關問題