Skip to end of metadata
Go to start of metadata

Introduction 

The SOSSQLPlusJob JITL job provides a standardized and parameterized interface for executing Oracle SQL*Plus scripts.  The JobScheduler offers out of the box capability to execute SQL scripts, passing parameters to the SQL*Plus script  or collecting and passing on the results of a script execution to next job step as a JobScheduler Order parameter.  The SOSSQLPlusJob can be used to execute existing SQL*Plus scripts  by referring them in the command parameter. 

A Simple JITL SQL*Plus Job Example

The following example shows a basic example of the SOSSQLPlusJob . It executes a simple SQL Statment  - selecting the current system date and displaying it on stdout as order_date.

Simple JobSchedulerSQLPlusJob  Expand source

Parameters

The SOSSQLPlusJob requires the following parameters:

#

Name

Title

Mandatory

Default

Example
1

command_script_file

SQL script to be executed

true

 

c:\app\bin\sqls\get_upd_count.sql

2

db_url

Database service or Instance name

true

 

DORCL01

3

db_user

User name for database access

true

 

db username
4

db_password

Password for database access

true

 

db password
5shell_commandSQL plus client nametrue sqlplus
6

variable_parser_reg_expr

Regular expression to parse output and

set order parameters for next job steps

false^SETs+(\\s)\\s*ISs(.*)$

 

 
7command_Line_optionsSQL*Plus command line optionsfalse -S -L
8ignore_ora_messagesIgnore ora error messagesfalse  
9ignore_sp2_messagesignore sp2 error messagesfalse  
10include_filesCode blocks should be executed before SQLfalse  

command_script_file

  • The SQL script  can be:
    • saved to a separate file such as get_order.sql . This file can subsequently be referred to as the value of the "command_script_file" job parameter. This is a recommended approach for achieving "separation of concern" in application architecture. 

    • SQL code can also be specified as the value of the CDATA tag as part of the Job.XML. This approach is preferred only if the SQL  code is very small and only used by a single job.

db_url

For SQLPlus job db_url is only the Oracle DB service name or instance name

db_user

DB Username which has necessary database permission to execute SQL script.

db_password

The password for the DB user defined in the db_user parameter.

shell_command

The value of this parameter specifies the name of SQL*Plus client. The SQL sctipt will be processed by the client. This parameter is useful when executing legacy SQL code i.e. Oracle 9i, 10g

variable_parser_reg_expr 

By default the SOSSQLPlusJob job defines a regular expression to parse console output from the execution of SQL Script and sets order parameters for subsequent job steps. For example, the SQL*Plus client stdout  prompt SET period_prev IS ${PN_YEAR_PREV_PERIOD}  displays the output on console; if  period_prev is 20140915, it will be parsed by regular expression ^SETs+(\\s)\\s*ISs(.*)$ and return the period_prev="20140915" order parameter.  All stdout statements matching the ^SETs+(\\s)\\s*ISs(.*)$ regular expression will be set as order_parameters.

command_Line_options

 The value of this parameter specifies all the command line parameters required by the SQL*Plus client i.e.  -V SQL*Plus version , -S silent  no banner , -M automatic HTML output etc.

ignore_ora_messages

Its not always the case when you want to ignore error messages but if need be arise, value of the parameter ignore_ora_message will specify which ORA messages Jobscheduler can ignore.

ignore_sp2_messages

If there are some expected Oracle SP2 errors which you want to ignore, use a comma separated list of all the SP2 errors as value for the ignore_sp2_messages parameter.

include_files

If you have some common code need to be executed before SQL*Plus code, you can define with include_files parameter. Multiple files can be specified, seperated by semicolons. 

Saving Database Connection Settings in a Parameter File

It strongly recommend that a db_connection parameter file such as database_connection_sqlplus.parameter.xml is used to store all the database connection settings in a common location. This approach enables the user to manage settings at central location which can then be reused by multiple jobs.

This approach also makes it easy to maintain different settings for  development, integration and production environments.

The following shows an example database connection parameter file:

database_connection_sqlplus.parameter.xml  Expand source

 

The next example shows a JITL job where the database connection parameters are stored in an external file. In this example a "common_settings/database" directory has been created inside the JobScheduler's live folder. 

SOSSQLPlusJob with database_connection_settings file  Expand source

Passing parameters to the SQL Script

JobScheduler order parameters can be passed to the SQL Script. SQL Script code can be parameterized by defining variables such as ${SCHEDULER_PARAM_VARIABLE_NAME}. Variables can be set using environment variables, JobScheduler task parameters ( as described in the following example) or from JobScheduler order parameters.

 

Passing variables to the SQL script  Expand source
Icon
Parameters can also be defined with following syntax:
  • %parameter_name%
  • ${SCHEDULER_PARAM_parameter_name}

Parameters are not case sensitive.

SQL Script as an External File 

SQL script can be defined directly inside the Job xml as a command  parameter value but is generally better stored on the file system. JITL jobs can be configured to read PL/SQL scripts from the file system by defining the script path as a value for the command  parameter i.e. 

In the following example the PL/SQL code is saved to the filesystem in C:\app\executables\sqls\get_booking_cycle.sql and subsequently referenced using the command_script_file  parameter.

 

Passing variables to the SQL Script  Expand source

Passing SQL script results to subsequent job steps as parameters

JobScheduler jobs can create and update JobScheduler Order parameters. The SOSSQLPlusJob can also pass on the result of SQL script execution i.e. calculated dates, parameters calculated from tables, etc. By default the JobSchedulerSQLPlus job defines a regular expression to parse console output from the execution of SQL Script and sets order parameters for subsequent job steps. For example, the SQL*Plus client stdout  prompt SET period_prev IS ${PN_YEAR_PREV_PERIOD}  displays the output on console; if  period_prev is 20140915, it will be parsed by regular expression ^SETs+(\\s)\\s*ISs(.*)$ and return the period_prev="20140915" order parameter All stdout statements matching the ^SETs+(\\s)\\s*ISs(.*)$ regular expression will be set as order_parameters.

Advanced Configuration

Generic job for executing multiple SQL scripts

The SOSSQLPlusJob can be configured as a generic node inside a job chain and executable SQL script can be defined as an order parameter. The following example shows such a generic job. The job chain has a job node - execute_sql - two orders - get_booking_cycle and count_trx_records . Each order is scheduled to be executed at a different time. Both orders are configured to use a different SQL script file i.e. get_booking_cycle.sql and count_trx_records.sql. 

  • JobChain

    JITL-SQLPlus.job_chain.xml  Expand source
  • Job

    JITL-SQLPlus.job.xml  Expand source
  • Order : get_booking_cycle

    JITL-SQLPlus,get_booking_cycle.order  Expand source
  • Order : get_trx_count

    JITL-SQLPlus,get_trx_count.order.xml  Expand source

Return parameters created by the SOSSQLPlusJob

The JobScheduler automatically creates the following order parameters, which will then be available to subsequent job steps. 

sql_error

  • The sql_error parameter contains all the error messages generated during the SQL script execution. This parameter will be empty if errors do not occur.

std_out_output

  • The std_out_output parameter contains all the messages spooled to stdout by SQL Script.

std_err_output

  • The std_out_output parameter contains all the messages spooled to stdout by SQL Script.

exit_code

  • The exit_code will be 0 If script ended without any error 
  • If std_error_output is not empty the exit code will be set to 99
  • If either SP2 or an ORA- error occurs the exit code will be set to 98

See also: