Use this tag for DB2 SQL Procedural Language (SQL PL) questions
Questions tagged [sql-pl]
40 questions
0
votes
1 answer
How to implement width_bucket function in a single query
Oracle SQL provides
width_bucket(expression,min_value,max_value,num_buckets)
function to create a histogram. WIDTH_BUCKET Oracle SQL Reference. I want to know if the same functionality can be achieved using a nested query or something ?
Update: If…

Wajahat
- 1,593
- 3
- 20
- 47
0
votes
1 answer
"P1: begin" and "P2: begin" in a DB2 Stored Procedure
Can anyone explain to me or point me to some documentation on why the stored procedures are tagged into different parts using "P1: begin" and "P2: begin" ?
Thanks,
Mike

Sam Mike
- 11
- 2
0
votes
1 answer
In DB2 PL/SQL anonymous block declare local variables and declare continue handler results in error?
I am trying to make a simple script that handles errors from statements that are ok to fail gracefully. This is for DB2 v10.5 (Linux)
Example create a table and handle if table already exists
begin
DECLARE CONTINUE HANDLER FOR SQLSTATE '42710'…

ammianus
- 488
- 7
- 23
0
votes
1 answer
Logging frameworks for DB2
What are the logging framework options for DB2?
In other RDBM, there are several…

AngocA
- 7,655
- 6
- 39
- 55
0
votes
1 answer
Way to catch all type of rised signals in DB2 SQL-PL via a declare handler
I want to treat all types of generated signals in my code. I know how to catch a specific one with a Declare Handler, however I would like all of them.
For example, here I catch the 72822 signal.
DECLARE EXIT HANDLER FOR SQLSTATE '72822'
BEGIN
…

AngocA
- 7,655
- 6
- 39
- 55
0
votes
2 answers
Query with a "With" Clause inside a For Loop Cursor of DB2 PL SQL
I have a very complex query that includes a "With" clause. This query works fine when executed on the DB2 Client. But if the same query is used inside a For Loop Cursor of a PL SQL stored procedure it does not work. On trying to apply the stored…

Abhi
- 314
- 1
- 7
- 23
0
votes
1 answer
DB2 update trigger
I am trying to create a trigger in a DB2 database that runs on the update of a column in one table, and then fills in another table with certain values.
For example, there is a power unit table with a FLEET_ID column. Everytime the FLEET_ID is…

azoorob
- 5
- 1
- 5
0
votes
2 answers
Packages in DB2
I'm wondering if there is a package construct in DB2 like in Oracle.
For DB2 I found stored procedures and functions.
In Oracle one could group several stored procedures and functions together in a package. Is there something similar in DB2? I know…

Udo Held
- 12,314
- 11
- 67
- 93
-1
votes
1 answer
Convert Procedure from Oracle to DB2, Error when try to update table on runtime
Hello DB2 Experts I need your assistance in converting below Procedure to something more dynamic.
We have to update multiple sequences with max of id column for each table.
CREATE PROCEDURE mySchema.UPDATE_SEQUENCE ( )
DYNAMIC RESULT SETS 1
…

user1491706
- 3
- 1
- 2
-2
votes
1 answer
Building logic inside a stored procedure to check validity of employee id
I need to develop a database stored procedure with an input parameter for employee_id to the stored procedure and two output parameters. One for return code and another for return message.
CREATE OR REPLACE PROCEDURE CHECK_ID (emp_id IN INT,
…

Sidney Bookeart
- 1
- 1
- 1
- 5