I am trying to pass a collection of Employee objects from Java code to a DB2 Stored Procedure. In SQL server I can do that by making use of Table-Valued Parameters. In DB2 how can I achieve this?
Refer to Invoking stored procedures with ARRAY of ROW parameters in JDBC applications.
Or use Declared Global Temporary Table creating it and inserting rows into it beforehand and use this DGTT in your SP as ordinary table.
Related
I'm fairly new to stored procedure. I have to design a stored procedure for ATOMIC insert (Mass insert). I'm using COBOL program to call the stored procedure in DB2. I will store values in array and have to insert all at one shot. Below is the query we are using in COBOL program and which I have to convert to stored procedure.
INSERT INTO TABLE_NAME
(COLUMN1
,COLUMN2
,COLUMN3
,COLUMN4
,COLUMN5)
VALUES
(VALUE1
,VALUE2
,VALUE3
,VALUE4
,VALUE5)
FOR WS-SUB ROWS
ATOMIC
VALUE1,VALUE2,VALUE3,VALUE4,VALUE5 are array elements and WS-SUB is number of occurrence.
I want to know, If I can handle array in stored procedure or want to know if its possible to do ATOMIC insert in DB2 stored procedure.
Thanks in advance.
Following the documentation for DB2 on z/OS 12.0.0:
A DB2 Stored Procedure may be configured to use arrays as parameter types, see Example of using arrays in an SQL procedure.
However, if your intention is calling this from COBOL you may run into issues as the documentation for Supported SQL data types in COBOL embedded SQL applications indicates:
Arrays are not supported by the COBOL precompiler
Another approach would be to pass your data as something like a CLOB or VARCHAR delimited by a character and then parse it within your stored procedure.
By default DB2 Stored Procedures does not commit on return, so another option would be to iterate your COBOL tables and call the stored procedure repeatedly.
We are planning to create a procedure for our logic what should be in PL SQL in redshift (using workbench).
Can we use a table variable to traverse through the rows of the table ? Like we have dataframe in Python.
Sort of. Redshift implements a RECORD data type for stored procedures. Variables with this type can hold an arbitrary sets of rows.
"Overview of stored procedures in Amazon Redshift" > "Record types"
However, note that you cannot currently SELECT from a RECORD typed variable, only loop over the content.
There are several examples of using a RECORD variable in our GitHub repository: "amazon-redshift-utils/src/StoredProcedures/"
I am using SQL Server 2012 and trying to write a stored procedure that will have two components:
1. Select statement that will return several rows
2. Another component will have an aggregated value based on some conditions.
So, for the second component, I am thinking to declare a variable in the stored procedure and store the aggregated data there.
Now, my question is can I populate my output parameter with the data stored in previously declared variable and access the parameter from SSRS 2012?
I would appreciate any suggestion(s) to get me started.
Thank you
(1) When you open multiple cursors in a stored procedure, and then use a JDBC callable statement to iterate through the result sets, each in turn, are the order in which they are returned the same order in which they cursors are opened in the stored procedure? Or reverse of that? Or....?
(2) Is there a way to specify by sequence number or name which result set to process first?
For 1: The order of returned resultsets is undefined for JDBC, so it will depend on your actual database system. That said, it would be highly illogical for a stored procedure to return results in a different order than the order they are produced by the stored procedure.
For 2: Once again, this is not defined by JDBC. However I haven't heard of database systems that would allow you to control the order of returned results by any means other than their order in the stored procedure.
I have this external oracle Stored Procedure which takes INTEGER,CLOB,VARCHAR as parameters, and which inserts a record to table upon executing. This will be called using a dao layer which consists of JAVA + Spring.
I have been asked to insert multiple records (1000s ) using the same procedure. so I am thinking of writing a pl/sql block which accepts either String or Clob and substrings the values in a loop which calls the procedure. For that I have to either append a String with delemeters for each record and pass it as a parameter or I could create a CLOB from that String and pass it as a parameter.
Eg:String param ="value1,value2,value3 | value1,value2,value3 | value1,value2,value3 ..etc"
My questions are:
Is there a better solution than what I am thinking (because I think it is better to loop it inside the DB server rather than looping in DAO layer and making 1000s of DB calls)?
If I go ahead with my solution will there be limitations which prevents my effort, such as size of the data that I can pass to the pl/sql block?
I would refer you to this SO question:
Bulk insert from Java into Oracle
Basically, you should be doing a few bulk operations rather than thousands of individual ones.