Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

In this article

Table of ContentsmaxLevel

In this article

Table of Contents
maxLevel2
excludeOlder Versions|Additional Resources|Related Links|Related Information

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.

Note

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.

Info
  • 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

Multiexcerpt include macro
nameOracle JDBC Driver Upgrade
templateDataeJyLjgUAARUAuQ==
pageOracle Snap Pack
addpanelfalse

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

Multiexcerpt include macro
nameBehavior change in Database Execute Snaps
pageAzure SQL - Execute

  • 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.

Note

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.

Info
titleExecuting 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:

Multiexcerpt include macro
nameME_DB_Execute_Snaps_Scenario1
pageAzure SQL - Execute

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.
Note
Table name and column names must not be provided as bind parameters. Only values can be provided as bind parameters.

Examples:


Multiexcerpt include macro
nameME_DB_Execute_Snaps_Scenario2
pageAzure SQL - Execute

  • 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

Note
  • 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.


Info
  • We recommend you to add a single query in the SQL Statement field.


Info

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.


Warning
titleSingle 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


Checkbox

Select this checkbox to pass the input document to the output view under the key 'original'. This field applies only to the Execute Snaps with SELECT statement.

Default Value: Selected


Ignore empty result


Checkbox

Select this checkbox to not write any document to the output view when a SELECT operation does not produce any result.
If you deselect this checkbox and select Pass through, the input document will be passed through to the output view.

Default Value: Not selected


Auto commit

Dropdown list

Choose one of the options from the list to override the state of the Auto commit on the account. The available options are:

  •  True - The Snap executes with auto-commit enabled regardless of the value set for Auto commit in the Account used by the Snap.
  •  False - The Snap executes with auto-commit disabled regardless of the value set for Auto commit in the Account used by the Snap.
  • Use account setting - The Snap executes with Auto commit property value inherited by the Account used by the Snap.

Default Value: Use account setting

Note

'Auto commit' may be enabled for certain use cases if PostgreSQL jdbc driver is used in either Redshift, PostgreSQL or generic JDBC Snap. But the JDBC driver may cause out of memory issues when Select statements are executed. In those cases, “Auto commit" in Snap property should be set to ‘False’ and the Fetch size in the “Account setting" can be increased for optimal performance.


Note
title Behavior of DML Queries in Database Execute Snap when auto-commit is false
DDL queries used in the Database Execute Snap will be committed by the Database itself, regardless of the Auto-commit setting.
When Auto commit is set to false for the DML queries, commit will be called only at the end of the pipeline lifecycle.
Instead of building multiple Snaps with inter dependent DML queries, we recommend you to use the Oracle - Stored Procedure Snap.
The Auto commit needs to be true in a scenario where the downstream Snap does depend on the data processed on an Upstream Database Execute Snap containing a DML query.
When the Auto commit is set to the Use account setting on the Snap, the account level commit needs to be enabled.


Number of retriesInteger

Specify the maximum number of

attempts to be made to receive a response. The request is terminated

retry attempts the Snap must make in case there is a network failure and is unable to read the target file. The request is terminated if the attempts do not result in a response.

  • If the Number of retries value is set to 0 (the default value), the retry option is disabled, and the Snap does not initiate a retry. The pipeline will not attempt to retry the operation in case of a failure—any failure encountered during the database operation will immediately result in the pipeline failing without any retry attempts to recover from the errors.

  • If the Number of retries value is greater than 0, the Snap initiates a download of the target file into a temporary local file. If any error occurs during the download, the Snap waits for the time specified in the Retry interval and then attempts to download the file again from the beginning. After the download is successful, the Snap streams the data from the temporary file to the downstream pipeline. All temporary local files are deleted when they are no longer needed.


Info
Ensure that the local drive has sufficient free disk space to store the temporary local file.


Default Value: 0
Example: 3

Retry interval (seconds)Integer

Specify the time interval between two successive retry requests. A retry happens only when the previous attempt resulted in an exception. 

Default Value: 1
Example:10

Column-specific timestamp precisionCheckbox

Select this checkbox to display the timestamp with millisecond/microsecond/nanosecond precision in string type.

By default, the checkbox is deselected, which maintains the backward compatibility (supports only millisecond of date time type).

Default Value: Deselected

Snap Execution

Dropdown list

Multiexcerpt include macro
nameExecution_Detail_Write
pageSOAP Execute


Examples



Expand
titleGet the student's records from a table

In this example, we have a table named STUDENT that stores students' scores. It has 3 columns: ID, NAME and SCORE. We will get the record of a student named "Brace" with this pipeline:

 

The JSON Generator Snap passes the student's name to Oracle-Execute Snap:


The Oracle-Execute Snap executes a select SQL statement to get the student's information from table STUDENT. Note that the student's name passed from previous Snap can be accessed with "$name".

Here is the running result of the pipeline:


Expand
titleError handling on the Snap

This example will show the error handling of the Snap.

We use the same pipeline as the one in example #1 and route error messages to error view:

 

The Oracle - Execute Snap tries to select AGE column that doesn't exist in table STUDENT. This should cause a SQL execution error and the error message will be routed to error view:

Here is the error message that is routed to the error view:

Downloads

Multiexcerpt include macro
namedownload_instructions
pageOpenAPI

Attachments
patterns*.slp, *.zip

Insert excerpt
Oracle Snap Pack
Oracle Snap Pack
nopaneltrue