MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Mass INSERT in a program

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
pradeepg1
Beginner


Joined: 06 Jan 2003
Posts: 20
Topics: 7
Location: Columbus, OH

PostPosted: Tue Mar 04, 2003 5:51 pm    Post subject: Mass INSERT in a program Reply with quote

Can I use Mass INSERT statement in my application program like the one given here.

INSERT INTO TABLE A
SELECT * FROM TABLE B;

If I can use above statement in my program, what happens if one of the selected record from TABLE B is already present in TABLE A. Will the execution of the program stops by giving -803 SQL CODE without inserting remaining records or it will continue with inserting remaining records then throw the -803 error. Please share your thoughts.

Thanks,
Pradeep
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
pradeepg1
Beginner


Joined: 06 Jan 2003
Posts: 20
Topics: 7
Location: Columbus, OH

PostPosted: Wed Mar 05, 2003 3:29 pm    Post subject: Reply with quote

I just tested, it failed with -803 error and remaining records are not loaded. I thought it would discard the duplicates and continue with rest of the inserts like LOAD utility. But didn't workout.
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
gotluru
Beginner


Joined: 17 Dec 2002
Posts: 29
Topics: 6

PostPosted: Wed Mar 05, 2003 8:00 pm    Post subject: Reply with quote

Try Like this:
INSERT INTO TABLE A
(SELECT * FROM TABLE B
where a.key <> b.key);
Back to top
View user's profile Send private message
satjag
Beginner


Joined: 19 Dec 2002
Posts: 19
Topics: 2

PostPosted: Wed Mar 05, 2003 9:59 pm    Post subject: Reply with quote

Is it not possible to handle the error code and continue the execution of the program, with suitable displays for the failed records ?
_________________
Regards,
satjag
Back to top
View user's profile Send private message
Glenn
Beginner


Joined: 23 Mar 2003
Posts: 56
Topics: 3

PostPosted: Sun Mar 23, 2003 7:04 am    Post subject: Reply with quote

If this is within a program, I would suggest decoupling the statement. The mass insert is possible, but not really a good idea. Basically what I'm saying is to make the select statement a cursor and after you issue a fetch, issue a insert, and then take the appropriate actions based on the SQLCODE on the insert.

This also gives the ability for you to set up commits at appropriate times so the system doesn't grind to a halt if you have very many records and the command buffers get full over not getting emptied every so often...or a rollback doesn't take forever if you do have a problem.

Actually it is my belief that statements that operate on whole tables at once should not be included within programs for reasons like described...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group