* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Calling Stored Procedures from RulePoint
Survey
Document related concepts
Entity–attribute–value model wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
Relational algebra wikipedia , lookup
Tandem Computers wikipedia , lookup
Ingres (database) wikipedia , lookup
Microsoft Access wikipedia , lookup
Clusterpoint wikipedia , lookup
Team Foundation Server wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Database model wikipedia , lookup
Oracle Database wikipedia , lookup
Relational model wikipedia , lookup
Open Database Connectivity wikipedia , lookup
Transcript
Calling Stored Procedures from RulePoint © 2014 Informatica Corporation. No part of this document may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording or otherwise) without prior consent of Informatica Corporation. All other company and product names may be trade names or trademarks of their respective owners and/or copyrighted materials of such owners. Abstract You can configure objects in RulePoint to call stored procedures. This article provides the syntax to use in objects to call stored procedures in Oracle, Microsoft SQL Server, or IBM DB2. Supported Versions • RulePoint 6.1 Table of Contents Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Calling Stored Procedures from an SQL Source in Oracle, IBM DB2, and Microsoft SQL Server. . . . . . . . . . 2 Calling Stored Procedures from an SQL Responder in Oracle, IBM DB2, and Microsoft SQL Server. . . . . . . 4 Calling Stored Procedures from a SQL Analytic in Oracle, IBM DB2, and Microsoft SQL Server. . . . . . . . . . 4 Overview You can call stored procedures from a source, analytic, and responder in RulePoint. A stored procedure is a named set of Structured Query Language (SQL) statements that are compiled and stored on the database server. Calling Stored Procedures from an SQL Source in Oracle, IBM DB2, and Microsoft SQL Server You can call stored procedures from a source in Oracle, IBM DB2, and Microsoft SQL Server: • For Oracle, use the following syntax: • For IBM DB2, use the following syntax: begin <<stored_proc>>; end; begin atomic call <<stored_proc>>; end • For Microsoft SQL Server, use the following syntax: BEGIN EXECUTE <<stored_proc>>; end Example You want to update a department table in an Oracle database based on the fetched employee information. The process involves extracting the employee records from the source. For each record that you want to fetch, execute the stored procedure to update the department tables. To execute a stored procedure, create an SQL source with the required configurations. 1. Log on to the RulePoint Console with the credentials, Administrator/Administrator1. 2. On the Sources view of the Design tab, create an SQL source, and add the configurations to connect to the Oracle database. 2 The following image shows the configurations for executing a stored procedure on the RulePoint Console: 3. 3 In the Configurations section for creating an SQL source, provide the required SQL query and the syntax for updating the records to the employee table. The following image shows the configurations to execute the stored procedure spc_update_department: Calling Stored Procedures from an SQL Responder in Oracle, IBM DB2, and Microsoft SQL Server You can call stored procedures from an SQL responder in Oracle, IBM DB2, and Microsoft SQL Server: • For Oracle, use the following syntax: • For IBM DB2, use the following syntax: begin <<stored_proc>>; end; begin atomic call <<stored_proc>>; end • For Microsoft SQL Server, use the following syntax: BEGIN EXECUTE <<stored_proc>>; end Example To push the employee records into the employee table, create an SQL responder and call the stored procedure. You can push data, such as the employee name and ID, and department name and ID into the table. To execute a stored procedure, create an SQL responder with the required configurations. 1. Log on to the RulePoint Console with the credentials, Administrator/Administrator1. 2. On the Responders view of the Design tab, create an SQL responder. 3. Provide the connection and SQL configurations required to update the employee records into the table. The following image shows you how to configure an SQL responder and execute the SQL query to push employee records into the table: The anonymous SQL block executes the stored procedure push_employee_records with inputs such as the employee and department details. Calling Stored Procedures from a SQL Analytic in Oracle, IBM DB2, and Microsoft SQL Server The rule validates the event conditions based on the values that an SQL analytic returns. You may want an SQL analytic to return values from a stored procedure. You can call a stored procedure from a SQL analytic only through a function. In an SQL analytic, you cannot pass on the cursors from the stored procedure to the anonymous block that the analytic executes. 4 To extract the values from a stored procedure, call the function in an analytic in RulePoint. In the database, use the SQL function to call the procedure. The function returns the value in the SQL query of the analytic. 1. Log in to RulePoint, and perform the following steps: a. On the Analytic view of the Design tab, create an SQL analytic. b. Configure the required values. c. To call the function in the analytic, use the following SQL analytic call: select <<function_name>> from dual 2. Use the following syntax of the function code in the database to create or replace a function: CREATE or replace FUNCTION <<function_name>> return <<ret_value_type>> is pragma autonomous_transaction; BEGIN <<stored_proc>>;--procedure call return <<ret_value>>; END; 3. Use the following syntax for the stored procedure code in the database to create or replace a procedure: CREATE OR REPLACE procedure <<stored_proc>>;-as begin --Statement 1 --Statement 2 … … --Statement N end; Example You want the number of records from an employee table in Oracle. Use an SQL analytic to call the function. The function internally calls the stored procedure. 1. In RulePoint, use the following syntax to call the function in Oracle: select fn_count_no_records_employee() from dual The following image shows how to build an SQL query in RulePoint and call a stored procedure from an SQL analytic: 2. Use the following function code to replace the function: create or replace function fn_count_no_records_employee return number is 5 result number; begin proc_count_no_records_employee(result); return result; end; The function calls the stored procedure and then returns the number of employee records returned by the procedure. 3. Use the following stored procedure code in the database to create or replace a procedure: CREATE OR REPLACE procedure proc_count_no_records_employee( out_param OUT NUMBER) is begin select count(1) into out_param from employee; end; The SQL analytic returns the count of the number of employees from the employee table by calling a function. The function calls the procedure which computes the count and returns back the value. Author Dimple Rai Senior Technical Writer Acknowledgements Thanks to Srikanth Kalyanakrishnan from the CEP development team for his help in completing this article. 6