a7ed52e77c74a14312b961d1a4dc92f333ff1ffc
FAQ/Questions/Using-Stored-Procedures-In-Izenda-6.md
| ... | ... | @@ -227,4 +227,69 @@ Since Izenda primarily uses metadata to obtain information about schemas, views, |
| 227 | 227 | * INSERT EXEC - You cannot nest INSERT INTO ... EXEC statements in stored procedures used with Izenda. This is a limitation of SQL server. |
| 228 | 228 | * Return columns - The stored procedure MUST return the same columns in all cases. It is because the metadata expected when running the stored procedure must comply with the specifications given to it. |
| 229 | 229 | * Temp tables - You can build temp tables with the stored procedure and return that as long as the rules above are followed. Just ensure that the returned value is not null. This allows Izenda to obtain metadata from the empty result set of the stored procedure. |
| 230 | -* Multiple values as one parameter - It is possible to pass multiple values as a single parameter. For instance, you can construct a comma separated list of values and pass that resulting string to the SP. It would then be possible to split the string into its respective parts within your SP. |
|
| ... | ... | \ No newline at end of file |
| 0 | +* Multiple values as one parameter - It is possible to pass multiple values as a single parameter. For instance, you can construct a comma separated list of values and pass that resulting string to the SP. It would then be possible to split the string into its respective parts within your SP. |
|
| 1 | + |
|
| 2 | +##Stored Procedures in Oracle |
|
| 3 | + |
|
| 4 | +As of Izenda 6.10.0.1, certain types of stored procedures can be used in Izenda with an Oracle database deployment. The criteria for stored procedures in Oracle such as needing the same columns to be returned in all situations is the same as MSSQL but with one additional condition: the stored procedure definition must be a [[table-valued pipeline function|http://docs.oracle.com/cd/B19306_01/appdev.102/b14289/dcitblfns.htm]]. This is the only way that Izenda will be able to detect what returned columns the stored procedure will yield. |
|
| 5 | + |
|
| 6 | +Example: |
|
| 7 | + |
|
| 8 | +```sql |
|
| 9 | +create or replace FUNCTION IZ_CUSTORDERSORDERS (CUSTOMER_ID IN VARCHAR2) RETURN IZ_CUSTORDERSORDERS_TB PIPELINED IS |
|
| 10 | + RESULT_CUR SYS_REFCURSOR; |
|
| 11 | + val_1 Orders.OrderID%TYPE; |
|
| 12 | + val_2 Orders.OrderDate%TYPE; |
|
| 13 | + val_3 Orders.RequiredDate%TYPE; |
|
| 14 | + val_4 Orders.ShippedDate%TYPE; |
|
| 15 | +BEGIN |
|
| 16 | + OPEN RESULT_CUR FOR |
|
| 17 | + SELECT OrderID, OrderDate, RequiredDate, ShippedDate |
|
| 18 | + FROM Orders |
|
| 19 | + WHERE Orders.CustomerID = CUSTOMER_ID |
|
| 20 | + ORDER BY OrderID; |
|
| 21 | + |
|
| 22 | + LOOP |
|
| 23 | + FETCH RESULT_CUR INTO val_1,val_2,val_3,val_4; |
|
| 24 | + PIPE ROW(IZ_CUSTORDERSORDERS_TY(val_1,val_2,val_3,val_4)); |
|
| 25 | + EXIT WHEN RESULT_CUR%NOTFOUND; |
|
| 26 | + END LOOP; |
|
| 27 | + |
|
| 28 | + CLOSE RESULT_CUR; |
|
| 29 | + RETURN; |
|
| 30 | +END; |
|
| 31 | +``` |
|
| 32 | + |
|
| 33 | +##Stored Procedures in MySQL |
|
| 34 | + |
|
| 35 | +As of Izenda 6.10.0.1, the use of stored procedures is also available in Izenda with a MySql database deployment. The criteria for stored procedures such as needing the same columns to be returned in all situations is the same as MSSQL but there are some additional steps that must be taken for Izenda to properly interact with the stored procedure. |
|
| 36 | + |
|
| 37 | +First, the [[MySqlConnectionString|/API/CodeSamples/MySqlConnectionString]] must be updated to include the following: |
|
| 38 | + |
|
| 39 | +`MULTI_STATEMENTS=1` |
|
| 40 | + |
|
| 41 | +Example: |
|
| 42 | + |
|
| 43 | +`Driver={MySQL ODBC 5.2 ANSI Driver};DSN=MySQL;Server=YOUR_SERVER_IP;Port=YOUR_SERVER_PORT;Database=northwind;User=northwind;Password=traders;Option=3;MULTI_STATEMENTS=1` |
|
| 44 | + |
|
| 45 | +Second, the stored procedure definition must contain a pattern of statements similar to the example below. Note that any line that does not include `/* Izenda-specific code */` may be substituted for your own code. Any place the stored procedure name appears such as `[sp_name]_spResult` requires the specific string `_spResult` on the end of the identifier to function properly. |
|
| 46 | + |
|
| 47 | +Example: |
|
| 48 | + |
|
| 49 | +```sql |
|
| 50 | +DELIMITER $$ |
|
| 51 | +CREATE DEFINER=`northwind`@`%` PROCEDURE `izSales_by_Year`(in Beginning_Date Datetime,in Ending_Date Datetime) |
|
| 52 | +BEGIN |
|
| 53 | + DROP TABLE IF EXISTS `izSales_by_Year_spResult`; /* Izenda-specific code */ |
|
| 54 | + CREATE TEMPORARY TABLE `izSales_by_Year_spResult` AS /* Izenda-specific code */ |
|
| 55 | + SELECT Orders.ShippedDate, |
|
| 56 | + Orders.OrderID, |
|
| 57 | + `Order Subtotals`.Subtotal, |
|
| 58 | + ShippedDate AS Year |
|
| 59 | + FROM Orders JOIN `Order Subtotals` ON Orders.OrderID = `Order Subtotals`.OrderID |
|
| 60 | + WHERE Orders.ShippedDate Between Beginning_Date And Ending_Date; |
|
| 61 | + |
|
| 62 | + SELECT * FROM `izSales_by_Year_spResult`; /* Izenda-specific code */ |
|
| 63 | +END$$ |
|
| 64 | +DELIMITER ; |
|
| 65 | +``` |
|
| ... | ... | \ No newline at end of file |