Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exception Handling

Status
Not open for further replies.

goodmans

MIS
Apr 23, 2008
63
GB
Hello DB2 Gurus,

I need a favour. How can I handle exceptions in DB2, I am very new to the db2. I know about exception handling. but dont know how I can do it in db2. I want to drop the primary key on a table. I dont want to fail the stored_proc if the primary key doesnt not exist.

Oracle code:
begin
alter table table_a drop primary key;
exception
when others then
----print something
end;

How can i do the same in db2. Please help.

Regards
G
 
If you explain why you want to drop the primary key, someone may have a suggestion. This is ususally (always) done in a maintenance window and is not a part of "processing".

Once the primary key is dropped, what then?

If the drop fails, seems like this would be critical. . .

Obviously, there is something i misunderstand.
 
This is for re-bulking the big volume of data, I want to drop all the constraints on the table before inserting bulk data. I got millions of data so I dont want to keep all the indexes. I can check for particular constraint name on a table if i know the constraint name, but these constraints are generated automatically so system creates the primary key with system generated name. So I dont know the name of primary key constraint. I want to run this dropping constraint on pre-sql of my Informatica Job. Afater the end of load I will create the primary key.

Regards,
G
 
Sorry for the confusion my main question is how to handle exceptions in DB2 like we have in Oracle. It doesnt have to be primary key dropping between begin and end block. let us take this example I want to create a constraint on a column but I dont know if that particular constrant already exist and the name is generated automatically so I will not know the constraint's name.

Regards,
G
 
When my people run a process that requires different action based on the result of an sql statement, this is run from within code. The code can be whatever is needed.

If you need to discover which keys exist for a table, this can be done reading the catalog tables.

I may be misunderstanding something. . .
 
Sorry I am really confused now.

I am simply asking for some code sample which handles any error, irrespective of what number it is. like we have error handling in oracle. Please let me know if this is possible in db2.

Regards
G
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top