Oracle - Execute

In this article

Overview

You can use this Snap to execute an Oracle statement or query. This is a Write Snap type. This Snap works only with single queries.

This Snap:

  • is for simple DML (SELECT, INSERT, UPDATE, DELETE) type statements. For the comprehensive scripting functionality offered by various databases, use stored procedure functionality offered by their chosen database using the Stored Procedure Snap.
  • might drop your database, hence be cautious.

  • If you execute a SELECT query, the query's results are merged into the incoming document and the values of any existing keys will be overwritten. On the other hand, if there are no results from the query, the original document is written.
  • Any valid JSON paths that you define in the WHERE clause for queries/statements are substituted with values from an incoming document. Documents will be written to the error view if the document is missing a value to be substituted into the query/statement. 

Upcoming

JDBC Driver Upgrade

The Oracle JDBC Driver is upgraded from OJDBC6 JAR (v11.2.0.4) to OJDBC10 JAR (v19.20.0.0) in the latest distribution in October 2023 and deployed to the stable distribution in the November 2023 release (after the Snaplex upgrade). The latest JDBC driver upgrade is backward-compatible. Learn more: Oracle JDBC Driver Upgrade from v11.2.0.4 to v19.20.0.0 and JOOQ Upgrade from v3.9.1 to 3.17.x.

You can consume this driver upgrade with the 434patches23000 Snap Pack version.

Behavior Change

This JDBC driver upgrade has resulted in specific behavior changes that include errors, status codes, and success and failure messages. Learn more about the behavior changes to ensure your migration to the upgraded driver is seamless. 

Prerequisites

None.

Support for Ultra Pipelines

Works in Ultra Pipelines.

Limitations

  • Due to the limitation in Oracle JDBC driver, the SQL statement cannot have semicolons at the end except that it is a BEGIN-END block.
  • This Snap cannot invoke procedures, hence we recommend that you use Oracle Stored Procedure Snap for invoking procedures.

Known Issues

When the SQL statement property is an expression, the Pipeline parameters are shown in the Suggest, but not the input schema.

Behavior Change

  • In 4.26, when the stored procedures were called using the Database Execute Snaps, the queries were treated as write queries instead of read queries. So the output displayed message and status keys after executing the stored procedure.
    In 4.27, all the Database Execute Snaps run stored procedures correctly, that is, the queries are treated as read queries. The output now displays message key, and OUT params of the procedure (if any). The status key is not displayed.

  • If the stored procedure has no OUT parameters then only the message key is displayed with value success.

If you have any existing Pipelines that are mapped with status key or previous description then those Pipelines will fail. So, you might need to revisit your Pipeline design.

  • As part of main23721 (because of the JOOQ upgrade) previously, when you used a stored procedure in the Oracle-Execute Snap, the Snap displayed a Message:Success in the output. Now, the Snap displays $UPDATE_COUNT=-1.
  • As part of 436patches25696, when you use a stored procedure in the Oracle - Execute Snap, the Snap displays Message: Success and $UPDATE_COUNT=-1, 0, or 1 (based on the Snap Pack behavior) in the output.

Snap Input and Output

Input/OutputType of viewNumber of viewsExamples of Upstream/Downstream SnapDescription
InputDocument
  • Min:0
  • Max:1
  • JSON Generator
  • JSON Formatter
  • XML Formatter
This Snap has at most one document input view. If the input view is defined, then the where clause can substitute incoming values for a given expression.
OutputDocument
  • Min:1
  • Max:1
  • Mapper
  • Copy
  • JSON Formatter and File Writer

This Snap has at most one document output view. If an output view is available and an update/insert/merge/delete statement was executed, then the original document that was used to create the statement will be output with the status of the statement executed.

Database Write Snaps output all records of a batch (as configured in your account settings) to the error view if the write fails during batch processing.

Snap Settings

FieldField TypeDescription

Label*


String

Enter a unique name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your Pipeline.

Default Value: Oracle Execute
Example: Oracle Execute

SQL statement*


String

Specify the SQL statement to execute on the server.

Executing SQL statements in SnapLogic

You must understand the following scenarios to successfully execute your SQL statements:

Scenario 1: Executing SQL statements without expressions
If you do not enable the expression toggle of the SQL statement field:  

  • The SQL statement must not be within quotes. 
  • The $<variable_name> parts of the SQL statement are expressions. In the below example, $id and $book.

Examples:

Additionally, the JSON path is allowed only in the WHERE clause. If the SQL statement starts with SELECT (case-insensitive), the Snap regards it as a select-type query and executes once per input document. If not, it regards it as write-type query and executes in batch mode.

If your Oracle table has columns whose names contain a '$' (or any other special character) in it, enclose the column name within quotes, such as: select "USER$ID" from testtable1


Scenario 2: Executing SQL queries using expressions
If you enable the expression toggle of the SQL statement field:  

  • The SQL statement must be within quotes. 
  • The + $<variable_name> + parts of the SQL statement are expressions, and must not be within quotes. In the below example, $tablename.
  • The $<variable_name> parts of the SQL statement are bind parameter, and must be within quotes. In the below example, $id and $book.
Table name and column names must not be provided as bind parameters. Only values can be provided as bind parameters.

Examples:


  • "EMPNO=$EMPNO and ENAME=$EMPNAME"

  • "emp='" + $emp + "'"

  • "EMPNO=" + $EMPNO + " and ENAME='" + $EMPNAME+ "'"

  • Select * from "Snap10gic$#_1".emp order by ID asc
  • select firstname from test.cyclist_name
  • INSERT statement "insert into " + $tablename + " (city, temp_lo, temp_hi, date) values ('" + $city + "','" + $temp_lo + "', '" + $temp_hi + "', '" + $date + "')"
  • "select * from " + $tablename

  • The non-expression form uses bind parameters, so it is much faster than executing N arbitrary SQL expressions.
  • Using expressions that join strings together to create SQL queries or conditions has a potential SQL injection risk and hence unsafe. Ensure that you understand all implications and risks involved before using concatenation of strings with '=' Expression enabled.
  • The '$' sign and identifier characters, such as double quotes (“), single quotes ('), or back quotes (`), are reserved characters and should not be used in comments or for purposes other than their originally intended purpose.
  • We recommend you to add a single query in the SQL Statement field.

We recommend you to use the Oracle Stored Procedure Snap for invoking procedures as the Oracle Execute Snap has the following limitation while invoking procedures:

  • Procedures have to invoked as a PL/SQL block (with older jdbc JARs).  However, with this approach the output parameters cannot be sent to the output view.  Besides, the latest oracle jdbc drivers do not support PL/SQL.

Oracle JDBC documentation recommends using CallableStatement for invoking procedures, which is what the Oracle Stored Procedure Snap does.


Single quotes in values must be escaped

Any relational database (RDBMS) treats single quotes (') as special symbols. So, single quotes in the data or values passed through a DML query may cause the Snap to fail when the query is executed. Ensure that you pass two consecutive single quotes in place of one within these values to escape the single quote through these queries.

For example:

If String To pass this valueUse
Has no single quotes
Schaum Series
'Schaum Series'
Contains single quotes
O'Reilly's Publication
'O''Reilly''s Publication'

Default Value: [None]

Query type

Dropdown list/Expression

Select the type of query for your SQL statement (Read or Write).

When Auto is selected, the Snap tries to determine the query type automatically.
If the execution result of the query is not as expected, you can change the query type to Read or Write.

Default Value: Auto
Example: Read

Pass through