Executes SQL*Plus Scripts by using Oracle's sqlplus command-line query tool.
SQL*Plus statements can either be read from a source file using the start attribute or from between the enclosing <sqlplus> tags (preferably within a CDATA section)
Attribute | Description | Required |
---|---|---|
logon | Connection string. syntax: {username[/password] [@connect_identifier] | /} [AS {SYSOPER | SYSDBA}]| /NOLOG | No. Defaults to '/nolog' |
dir | The directory in which the command should be executed. | No. Defaults to projects basedir |
silent | true or false - Suppresses all SQL*Plus information and prompt messages | No. Defaults to 'false' |
start | Name of a script and arguments to execute syntax: @{url|file_name[.ext]} [arg ...] | No. |
failOnError | true or false - Indicates whether the build will continue if the command exits with an error code | No. Defaults to 'false' |
resultproperty | Name of a property in which the return code of the command should be stored. Only of interest if failonerror=false. | No. |
failOnSpoolMatch | A regular expression pattern that will be used to find matches within the SQL*Plus output stream. If a match was found, the task fails with an exception. For instance one can scan the output stream for SQL*Plus SP2 errors and issue an build exception (see example section). | No. |
The <sqlplus> task supports nested <arg> elements that will be passed as start parameters to the sql script. Optionally start parameters can be included directly within the start attribute of the sqlplus task.
Attribute | Description | Required |
---|---|---|
value | Parameter value | Yes |
<ora:sqlplus start="${sql.dir}/pass-parameters.sql" <arg value="scotch"/> <arg value="whiskey"/> </ora:sqlplus>
<ora:sqlplus start="${sql.dir}/pass-parameters.sql scotch whiskey"/>
prompt var1 = &1 prompt var2 = &2
[sqlplus] SQL*Plus: Release 10.1.0.3.0 [sqlplus] Copyright (c) 1982, 2004, Oracle. All rights reserved. [sqlplus] var1 = scotch [sqlplus] var2 = whiskey
Corresponds to Ant's nested <propertyset> element. A propertyset can be used to pass properties from Ant to SQL*Plus. So it's possible to use Ant properties directly inside SQL scripts as a defined variable.
Note: SQL*Plus has rigid variable naming conventions. E.g. dots are not allowed within variable names. Therefore the <sqlplus> task automatically replaces all dot characters by underlines.
For examples, assume a property named db.local (referenced as variable db_local inside SQL)
<ora:sqlplus> <propertyset> <propertyref prefix="db"/> </propertyset> <![CDATA[ prompt &&db_local ]]> </ora:sqlplus>
This is working within scripts inside the sqlplus tag, as well as within external script files.
Shutdown an Oracle instance. If the instance is not available, set the property 'shutdown.exitvalue' to the value of the SQL error code.
<ora:sqlplus resultproperty="shutdown.exitvalue" logon="sys/syspswd@localdb as sysdba" silent="true" failonerror="false"> <![CDATA[ WHENEVER SQLERROR EXIT SQL.SQLCODE select status from v$instance; shutdown immediate ]]> </ora:sqlplus>
<ora:sqlplus logon="sys/syspswd@localdb as sysdba" silent="true" failonerror="true"> <![CDATA[ WHENEVER SQLERROR EXIT SQL.SQLCODE declare v_logmode varchar2(30); begin select log_mode into v_logmode from v$database; if v_logmode != 'ARCHIVELOG' then raise_application_error (-20101, 'ARCHIVELOG not enabled'); end if; end; / ]]> </ora:sqlplus>
<ora:sqlplus logon="${db.userid}" silent="true" failOnSpoolMatch=".*SP2-[0-9]{4}.*"> <![CDATA[ xyz ]]> </ora:sqlplus>