SQL Stored procedure to sync identity column in IBM i DB2 (AS400)

preview_player
Показать описание
Apply and get any of the following Credit cards:
Рекомендации по теме
Комментарии
Автор

The CASE statement could be replaced with COALESCE(MAX(IDNCOLNAM), 0)

glenngundermann
Автор

You use TRIM for LIBRARY and TABLE in the first SQLSTMT but not in the second statement. Since they are VARCHAR, the TRIM isn't needed. it's not good to do unnecessary steps and it's best to be consistent.

glenngundermann
Автор

Why did you put quotes " around the column name, library name, and table name when you built SQLSTMT?

glenngundermann
Автор

1. Are you sure you have to declare SQLCODE? Is this not automatically declared under the covers, along with a lot of other variables, like SQLSTATE, etc.?
2. Setting MAXIDNVAL = 0 and SQLSTMT = ' ' are redundant. They will be replaced by the statements following.
3. Why are you using a cursor to execute one single statement only once? Cursors are great to retrieve data, one row at a time, from a result set.

glenngundermann
Автор

Hi,

How to uniquely identify a record in AS400 database

Detailed Question:
I have AS400 database and some tables within it.
Tables don't have primary key / unique key / composite key defined and it has duplicate records.

Like oracle has concept of ROWID, in same way do we have something for AS400 database. or can we create something like ROWID?

pavang
Автор

Is there anything you can help me with ADMIN stuff in AS400??

joelburner
Автор

Have you tried using VALUES to avoid using a cursor? Much less SQL code and I believe better performance.

SET SQLSTMT = 'VALUES (SELECT .... ) INTO ?';
PREPARE STMT FROM SQLSTMT;
EXECUTE STMT USING MAXIDNVAL;


Some references:

glenngundermann
join shbcf.ru